Welcome to the MelodyMind project repository!
This repository showcases my work in building music recommendation systems, evolving from a real-time API-based recommender to a sophisticated hybrid model.
๐ Live Demo
This application is your personal guide to discovering new music, powered by the extensive Last.fm API. It offers intelligent and diverse recommendations through an intuitive Streamlit interface.
MelodyMind isn't just another music recommender; it's a hybrid system that intelligently blends various data points from Last.fm to unearth unique music tailored to your taste. Whether you provide an artist, a specific track, or both, MelodyMind digs deep to find your next favorite song. Its hybrid approach ensures you get a broad spectrum of suggestions, moving beyond simple direct similarities to explore connected artists and genres.
- Intelligent Input Handling: Smartly processes your artist and track inputs, with built-in auto-correction for common typos, ensuring you always find what you're looking for.
- Diverse Recommendation Strategies:
- Track-Focused: Discover songs similar to a given track, expanding your playlist effortlessly.
- Artist-Centric: Explore the top hits from your favorite artists or discover new tracks from artists you'll love.
- Contextual Hybridization: When direct matches are scarce, the system intelligently broadens its search to include top tracks from similar artists and songs associated with relevant genres, providing richer recommendations.
- Comprehensive Insights: Dive deeper into the music with detailed information about recommended artists and tracks, including their top tags and concise summaries.
- Sleek User Interface: Enjoy a smooth and responsive experience thanks to the interactive Streamlit web application.
- Instant Access: Direct links to Last.fm enable you to listen to recommended tracks immediately.
- Python: The robust foundation for all logic and data processing.
- Streamlit: For creating a beautiful, interactive, and easy-to-use web application.
- Requests: Handles all HTTP communications with the Last.fm API.
- Last.fm API: The rich data source powering the music recommendations.
To run this version of MelodyMind on your local machine, follow these simple steps!
- Python 3.12 (highly recommended for best compatibility)
- Git
- A Last.fm API Key โ essential for accessing music data.
- Clone the Repository:
git clone [https://github.com/indranil143/Hybrid-Music-Recommendation-System.git](https://github.com/indranil143/Hybrid-Music-Recommendation-System.git) cd Hybrid-Music-Recommendation-System
- Create a Virtual Environment (Highly Recommended):
python -m venv venv # On Windows: .\venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
- Install Dependencies:
Ensure your
requirements.txt
file is present in the current directory.pip install -r requirements.txt
- Set Your Last.fm API Key:
The application needs your Last.fm API Key to function. Set it as an environment variable:
- For Windows (Command Prompt):
set LASTFM_API_KEY="YOUR_ACTUAL_LASTFM_API_KEY"
- For Windows (PowerShell):
$env:LASTFM_API_KEY="YOUR_ACTUAL_LASTFM_API_KEY"
- For macOS/Linux (Bash/Zsh):
export LASTFM_API_KEY="YOUR_ACTUAL_LASTFM_API_KEY"
- Remember to replace
YOUR_ACTUAL_LASTFM_API_KEY
with the key you obtained from Last.fm. For persistent local development, consider using a.env
file with thepython-dotenv
package.
- For Windows (Command Prompt):
- Run the Streamlit App:
Your web browser should automatically open the MelodyMind application.
streamlit run music_app_api_only.py
Deploying MelodyMind to Streamlit Community Cloud is straightforward:
- GitHub Repository: Your project must be hosted on a public GitHub repository.
requirements.txt
: Ensure this file is located in the same directory asmusic_app_api_only.py
. It should accurately list all project dependencies and avoid platform-specific packages (likepywin32
) or problematic+cpu
PyTorch/Torchaudio versions, as these can cause deployment issues.- API Key as Secret: Securely store your
LASTFM_API_KEY
in the Streamlit Community Cloud dashboard's secrets. Go to your app settings, then "Advanced settings," and finally "Secrets," adding the following:LASTFM_API_KEY="YOUR_ACTUAL_LASTFM_API_KEY_HERE"
- Simply enter an artist name, a track name, or both in the sidebar on the left.
- Adjust the "Number of Recommendations" slider to control the quantity of suggestions.
- Then click "Get Recommendations."
- Explore the results under the "๐ต Recommendations" tab, and dive into deeper context with the "๐ Insights" tab.
This project implements a Hybrid Music Recommendation System combining Content-Based Filtering and Collaborative Filtering using the LightFM library. It provides personalized song recommendations by analyzing audio features and simulating user interactions (artist-track associations).
- Hybrid Approach: Combines Content-Based and Collaborative Filtering.
- Content-Based Filtering: Recommends songs based on audio features (danceability, tempo, energy, etc.) using cosine similarity.
- Collaborative Filtering: Utilizes the LightFM library to learn user (artist) and item (track) embeddings from interaction data.
- Simulated User Interactions: Demonstrates collaborative filtering using artist-track associations as implicit feedback.
- Streamlit Web App: Provides an interactive web interface to get recommendations.
- Modular Design: Separated data processing and deployment (
music_app.py
).
- Content-Based Filtering: Imagine recommending songs that sound similar to what you already like. This method analyzes the characteristics (features) of items (songs) and suggests others with similar characteristics.
- Collaborative Filtering: This method looks at the behavior of many users. If User A and User B like similar songs, and User A likes a song that User B hasn't heard, Collaborative Filtering might recommend that song to User B. It finds patterns in user-item interactions.
- Hybrid System: Combines both methods to recommend new, niche songs (Content-Based) while leveraging user patterns (Collaborative Filtering) for enhanced accuracy.
Uses the Spotify Dataset 1921-2020, 160k+ Tracks. Source: https://www.kaggle.com/datasets/fcpercival/160k-spotify-songs-sorted
Execute the cells in Hybrid_Music_Recommendation_System.ipynb
using Kaggle or Google Colab. This trains the model and saves music_recommender_components.pkl
.
- Ensure
music_recommender_components.pkl
is in the root directory. - Activate your virtual environment (from the previous setup steps, or create a new one).
- Run the app:
The app will open in your browser.
streamlit run music_app.py
Feel free to contribute to this project by opening issues or submitting pull requests!
This project is licensed under the MIT License - see the LICENSE file for details.