SongScope is an AI powered music recommendation system that experiments with your spotify data such as your top tracks, liked songs , artists , etc. to recommend you new songs that you might like. The system can add a personal touch to the recommendations if you provide your mood and personal emotional data. The system can be also fine-tuned based on your liked songs and spotify recommendation system to experiment with fine-tuned models too. Other features include a function to search reviews from pitchfork or similar websites to get a better understanding of the song and artist and have a critical view. The features combined with personalized fine-tuning can experiment with a newly personalized recommendation system.
Python 3.10 is used as interpreter for the project.
Needed to install the dependencies.
A Spotify account is needed to use the system. You can create one here.
This project is built using locally, so you need to provide your own Spotify Client ID and Client Secret. Please read this documentation to create your own Spotify Developer Account and get your own Client ID and Client Secret. Getting Started with Spotify Web API
set up a new account and login to the Spotify Developer Dashboard.
http://localhost:5000/callback
in the app settings.OPENAI API Key
This project uses OpenAI API to generate song lyrics. You can get your own API key by signing up here.
We will also need OPENAI ASSISTANT ID which has functions available to it. We will do this later in the project setup.
We will be using MongoDB as our database, ChromaDB for storing reviews and chat history and Nginx for our web server configurations.
The details will follow in the installation section. However, install these before starting with the project setup.
git clone https://github.com/parhamrahmani/SongScope.git
pip install -r requirements.txt
or
pip install requests python-dotenv Flask jsonify openai chromadb pymongo chainlit beautifulsoup4
sudo apt update
sudo apt install nginx
/etc/nginx/sites-available
directory.
sudo nano /etc/nginx/sites-available/songscope
Add the following configurations to the file.
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /chat/ {
proxy_pass http://127.0.0.1:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
sites-enabled
directory.
sudo ln -s /etc/nginx/sites-available/songscope /etc/nginx/sites-enabled
sudo systemctl restart nginx
sudo systemctl status nginx
sudo apt update
sudo apt install -y mongodb
sudo systemctl start mongod
sudo systemctl status mongod
/recommendations
and /generate_random_recommendations/<int:num_recommendations>
are called, and it will be saved in the database.pip install chromadb
http://localhost:5000/liked_songs
localhost:5000/home
after authorization to tweak and get new recommendations.localhost:5000/generate_random_recommendations/<int:num_recommendations>
to get random recommendations to populate the table for using it for fine-tuning.num_recommendations
parameter to get the desired number of recommendations. There are rate limits for the Spotify API.Fine-tuning is an optional step
conf/finetuning/finetuning.py
to fine-tune the model based on the prompts generated.
conf/finetuning/prompts.jsonl
to the OpenAI API and will fine-tune the model based on the prompts.OPEN_AI_ASSISTANT_ID
in the .env
file.TAVILY_KEY
in the .env
file.
.env
file.env
file in the root directory of the project..env
file.
SPOTIFY_CLIENT_ID=<YOUR_SPOTIFY_CLIENT_ID>
SPOTIFY_CLIENT_SECRET=<YOUR_SPOTIFY_CLIENT_SECRET>
REDIRECT_URI="http://localhost:5000/callback"
FLASK_SECRET_KEY=<YOUR_SECRET_KEY> # You can set a secret as anything you want
OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
CHROMADB_PATH=<PATH_TO_CHROMADB> # A path to store the chat history and reviews
MONGO_URI="mongodb://localhost:27017/spotifydb"
OPEN_AI_ASSISTANT_ID=<YOUR_OPENAI_ASSISTANT_ID>
AI_MODEL=<YOUR_OPENAI_MODEL> # The model that you want to use for the AI like gpt4o etc.
TAVILY_KEY=<YOUR_TAVILY_KEY>
sudo systemctl start nginx
sudo systemctl status nginx
sudo systemctl start mongod
sudo systemctl status mongod
python main.py
2024-07-01 02:27:48 - Loaded .env file
2024-07-01 02:27:48 - Anonymized telemetry enabled. See https://docs.trychroma.com/telemetry for more information.
* Serving Flask app 'backend'
* Debug mode: off
2024-07-01 02:27:48 - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
2024-07-01 02:27:48 - Press CTRL+C to quit
http://localhost:5000
Starting Chainlit server
2024-07-01 02:29:13 - Loaded .env file
2024-07-01 02:29:14 - Your app is available at http://localhost:8000
Chainlit thread started.
2024-07-01 02:29:15 - 127.0.0.1 - - [01/Jul/2024 02:29:15] "GET /interface HTTP/1.1" 302 -
2024-07-01 02:29:16 - Translated markdown file for en-US not found. Defaulting to chainlit.md.
2024-07-01 02:29:18 - HTTP Request: POST https://api.openai.com/v1/threads "HTTP/1.1 200 OK"
This means that the chatbot is running.
Entering chat function
Thread ID: <the thread id of openai thread>
Message: hi
2024-07-01 02:32:03 - HTTP Request: POST https://api.openai.com/v1/threads/<thread_id>/messages "HTTP/1.1 200 OK"
2024-07-01 02:32:04 - HTTP Request: POST https://api.openai.com/v1/threads/<thread_id>/runs "HTTP/1.1 200 OK"
Run status: queued
2024-07-01 02:32:05 - HTTP Request: GET https://api.openai.com/v1/threads/<thread_id>/runs/run_9a7tEs4Wo5LSUuAjugVfNYrv "HTTP/1.1 200 OK"
Run status: in_progress
2024-07-01 02:32:06 - HTTP Request: GET https://api.openai.com/v1/threads/<thread_id>/runs/run_9a7tEs4Wo5LSUuAjugVfNYrv "HTTP/1.1 200 OK"
2024-07-01 02:32:06 - HTTP Request: GET https://api.openai.com/v1/threads/<thread_id>/messages "HTTP/1.1 200 OK"
2024-07-01 02:32:07 - HTTP Request: POST https://api.openai.com/v1/threads/<thread_id>/messages "HTTP/1.1 200 OK"
2024-07-01 02:32:07 - Collection chat_history is not created.
Message in thread <thread_id> inserted successfully to chat history
Verified content: Hello! How can I assist you today?
2024-07-01 02:32:07 - 127.0.0.1 - - [01/Jul/2024 02:32:07] "POST /chat HTTP/1.1" 200 -