A unsupervised learning model which gives recommendations based on a given song.
We created this project to see if we can actually understand the musical patterns of a listener with their playlist as source and what factors are really useful in determining the taste and interest of the listener. And also to get some experience in basic ML and hosting a model.
-
Clone or download the repository.
-
Create a .env file in the project directory: Add the following lines, replacing the placeholders with your actual Spotify API credentials:
NEXT_PUBLIC_SPOTIFY_CLIENT_ID=YOUR_CLIENT_ID NEXT_PUBLIC_SPOTIFY_CLIENT_SECRET=YOUR_CLIENT_SECRET
-
cd to client directory
-
Run
# Install dependencies npm install # Start the development server npm run dev
Python 3.x (https://www.python.org/downloads/)
Necessary libraries:
- pandas
- numpy
- sklearn
- flask
- spotipy
- dotenv
- gunicorn
- http.server
-
Clone or download the repository.
-
Create a .env file in the project directory: Add the following lines, replacing the placeholders with your actual Spotify API credentials:
SPOTIFY_CLIENT_ID="YOUR_CLIENT_ID" SPOTIFY_CLIENT_SECRET="YOUR_CLIENT_SECRET"
-
Create a virtual environment in the project directory and activate it:
python3 -m venv .venv source .venv/bin/activate
-
Install the required libraries:
pip install -r requirements.txt
-
Start the server
gunicorn app:app
-
Prepare a list of songs: Create a JSON-formatted list containing information about the songs you want recommendations for, including their names and release years:
[ { "name": "Look What You Made Me Do", "year": 2017 } ]
-
Send the list to the '/recommend' API endpoint:
Using cURL (for command line):
curl -X POST http://<link>/recommend -H "Content-Type: application/json" -d '[{"name": "Castle on the Hill", "year": 2017}, {"name": "Look What You Made Me Do", "year": 2017}]'
Using Postman or other tools:
Set the request method to POST and the URL to http://localhost:(port)/recommend. Set the Content-Type header to application/json. Paste the JSON list of songs in the request body.
The system will respond with a JSON list of recommended songs, including their names, artists, and years.
[ { "name": "Look What You Made Me Do", "year": 2017, "artists": [ "Taylor Swift" ] }, { "name": "Believer", "year": 2017, "artists": [ "Imagine Dragons" ] }, { "name": "New Rules", "year": 2017, "artists": [ "Dua Lipa" ] }, { "name": "One Kiss (with Dua Lipa)", "year": 2018, "artists": [ "Calvin Harris", "Dua Lipa" ] }, { "name": "Don't Start Now", "year": 2019, "artists": [ "Dua Lipa" ] } ]
Note: To properly utilize the code, you'll need a Spotify developer account and a Spotify app created to obtain your API credentials. Please refer to Spotify's documentation for detailed instructions: https://developer.spotify.com/documentation/web-api/
- Implement Mood based song recommendation.
- Implement a user-specific recommendation system.
This repository is licensed under the MIT License.
If you have any questions or suggestions, feel free to contact Shantanu Wable.