A Django-based music recommendation web application that finds similar songs using advanced audio feature analysis and machine learning.
- Smart Song Search: Search for tracks by song name, artist, or album
- Similar Song Discovery: Find songs with similar audio characteristics using hybrid similarity (cosine + euclidean)
- Mood-based Recommendations: Discover songs with similar emotional qualities
- Artist Deep Dive: Explore more tracks from the same artist
- Audio Feature Analysis: Leverages 10 audio features including danceability, energy, valence, tempo, and more
- Machine Learning Models: KNN + K-Means clustering for intelligent recommendations
- Danceability: How suitable the track is for dancing
- Energy: Intensity and activity measure
- Valence: Musical positiveness (happy/sad)
- Tempo: Speed in BPM
- Acousticness: Confidence of acoustic sound
- Instrumentalness: Predicts vocal content
- Speechiness: Presence of spoken words
- Liveness: Audience presence probability
- Loudness: Overall volume in dB
- Duration: Track length
- Feature Weighting: Prioritizes danceability, energy, and valence (1.4x weight)
- Scaling: StandardScaler for audio features, MinMaxScaler for tempo/duration
- Hybrid Similarity: 75% cosine similarity + 25% euclidean distance
- Artist Boost: 5% bonus for same-artist tracks
- Popularity Bias: 10% influence from track popularity
- Match Score: 0-100% similarity percentage
- Subjective Match Quality: 60-75% (typical for feature-based recommenders)
- Same-mood Clustering: ~6 mood clusters (Happy/High Energy, Warm/Relaxed, etc.)
- No deep learning required - fast and efficient
- Python 3.10 or higher
- pip (Python package manager)
- Git
-
Clone the repository
git clone https://github.com/dhruvindave007/MusicApp.git cd MusicApp -
Create a virtual environment
# Windows python -m venv venv venv\Scripts\activate # macOS/Linux python3 -m venv venv source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Set up the database
python manage.py migrate
-
Train the recommendation models
python manage.py train_recommender
This will:
- Load
music/data/spotify_tracks.csv(114,000+ tracks) - Extract and scale audio features
- Train KNN model (15 neighbors)
- Train K-Means clustering (6 mood clusters)
- Save models to
music/artifacts/
- Load
-
Run the development server
python manage.py runserver
-
Open your browser Navigate to
http://127.0.0.1:8000/
MusicApp/
β
βββ manage.py # Django management script
βββ requirements.txt # Python dependencies
βββ db.sqlite3 # SQLite database
β
βββ MusicAI/ # Django project settings
β βββ settings.py
β βββ urls.py
β βββ wsgi.py
β
βββ music/ # Main application
β βββ views.py # Request handlers
β βββ urls.py # URL routing
β βββ models.py # Database models
β βββ utils.py # Similarity calculations
β βββ recommender.py # ML recommendation engine
β β
β βββ data/
β β βββ spotify_tracks.csv # Dataset (114k+ tracks)
β β
β βββ artifacts/ # Trained models
β β βββ knn.joblib # KNN model
β β βββ kmeans.joblib # K-Means clustering
β β βββ scalers.joblib # Feature scalers
β β βββ cluster_names.joblib # Mood cluster labels
β β βββ tracks.parquet # Processed data
β β
β βββ management/commands/
β β βββ train_recommender.py # Model training command
β β
β βββ templates/music/ # HTML templates
β βββ search.html
β βββ song_detail.html
β βββ results.html
β
βββ static/ # CSS, JS, images
βββ style.css
- Go to the home page
- Enter a song name, artist, or album
- Click search or press Enter
- Click on any song from search results
- See the top 10 most similar songs with match percentages
- Explore "More from this Artist" section
- 90-100%: Extremely similar (same mood, tempo, energy)
- 75-89%: Very similar (comparable vibe)
- 60-74%: Moderately similar (some shared characteristics)
- Below 60%: Loosely related
# Train with custom settings
python manage.py train_recommender \
--csv music/data/spotify_tracks.csv \
--out music/artifacts \
--neighbors 20 \
--clusters 8-
Prepare a CSV with these columns:
- Required:
track_name,artist_name,id(Spotify track ID) - Audio features:
danceability,energy,loudness,speechiness,acousticness,instrumentalness,liveness,valence,tempo,duration_ms - Optional:
album_name,popularity,year
- Required:
-
Place it in
music/data/ -
Train the model:
python manage.py train_recommender --csv music/data/your_dataset.csv
Run accuracy evaluation tests:
python manage.py test musicThis validates:
- CSV loading and cleaning
- Feature extraction and scaling
- Model training and prediction
- Similarity calculation accuracy
- Recommendation diversity
Edit MusicAI/settings.py to customize:
- Database settings
- Static files location
- Allowed hosts
- Debug mode
Core packages:
- Django 5.2.4: Web framework
- pandas 2.3.1: Data manipulation
- scikit-learn 1.7.1: Machine learning models
- numpy 2.3.2: Numerical computing
- joblib 1.5.1: Model persistence
See requirements.txt for complete list.
- Ensure virtual environment is activated
- Run
pip install -r requirements.txt
- Verify
music/data/spotify_tracks.csvexists - Check file path in training command
- Run
python manage.py train_recommenderfirst - Models must be trained before running the server
- Dataset might not contain the artist/song
- Try partial names or alternative spellings
- Check if CSV loaded correctly
For production deployment:
- Set
DEBUG = Falsein settings.py - Configure
ALLOWED_HOSTS - Use proper database (PostgreSQL/MySQL)
- Set up static file serving
- Use production WSGI server (Gunicorn/uWSGI)
- Configure SECRET_KEY via environment variable
This project is for educational purposes.
Dhruvin Dave
- GitHub: @dhruvindave007
- Spotify for audio feature data
- scikit-learn community
- Django framework
- Add user accounts and favorite tracking
- Playlist generation
- Real-time Spotify API integration
- Deep learning models (neural collaborative filtering)
- Genre-based filtering
- Export recommendations to Spotify
- Audio preview integration
- A/B testing framework for algorithm improvements
Note: This system uses audio feature similarity, not collaborative filtering. It finds songs that sound similar, not songs that similar users liked.