Moodify is a real-time emotion-based music recommendation system that uses facial expression analysis to recommend songs that match the user's current emotional state. By leveraging a Convolutional Neural Network (CNN) trained on the FER2013 dataset and integrating with the Spotify API, Moodify personalizes music experiences dynamically as your emotions change.
- 🎥 Real-time facial emotion detection using webcam feed
- 🧠 Deep Learning model (CNN) trained on the FER2013 dataset
- 🎵 Spotify API integration for emotion-aligned music recommendations
- 🌐 Flask web app with live video stream and dynamic song suggestions
- 📊 Detailed evaluation with accuracy, confusion matrix, ROC curve, and more
Live detection and instant playlist recommendations.
| Technology | Purpose |
|---|---|
| Python | Core programming language |
| TensorFlow/Keras | Deep learning model for emotion classification |
| OpenCV | Real-time face detection and image preprocessing |
| Spotipy | Python client for Spotify Web API |
| Flask | Web application framework |
| Pandas, NumPy | Data processing and handling |
| Matplotlib | Data visualization and evaluation metrics |
Moodify/
├── app.py # Main Flask app
├── camera.py # Handles video capture and emotion detection
├── train.py # Model training script
├── Spotipy.py # Spotify playlist fetch script
├── emotion_detection_model.keras # Trained model file
├── songs/ # Emotion-wise CSV playlists
├── templates/ # HTML files (index.html)
├── static/ # CSS and JS assets
├── haarcascade_frontalface_default.xml # Face detection XML
├── utils.py # Supporting utility functions
- FER2013: Facial Expression Recognition 2013
- Images: 35,887 grayscale images (48x48)
- Classes: Angry, Disgust, Fear, Happy, Neutral, Sad, Surprise
- Split: 28,709 for training, 7,178 for testing
git clone https://github.com/TheDevilPython/Moodify.git
cd Moodifypython -m venv moodify-env
source moodify-env/bin/activate # or moodify-env\Scripts\activate on Windowspip install -r requirements.txtAdd your Spotify credentials:
set SPOTIPY_CLIENT_ID=your_client_id
set SPOTIPY_CLIENT_SECRET=your_client_secretpython app.pyTo retrain the model:
python train.pyIt includes:
- Data augmentation
- Accuracy/loss visualization
- Early stopping
- Evaluation metrics like confusion matrix, ROC curve
- Real-time facial expression capture
- CNN-based emotion classification
- Spotify API integration using Spotipy
- Dynamic web UI to show current mood and playlist
- Downloadable CSVs of songs for each mood
- Fully modular and extensible
| Live Emotion Detection | Song Recommendations |
|---|---|
![]() |
![]() |
- Add support for multi-modal emotion detection (voice + text)
- Improve playlist personalization based on past emotion history
- Add speech-based interaction
- Deploy via Docker or on cloud (Heroku, AWS)
This project is licensed under the MIT License. Feel free to use and modify.
Made with ❤️ by [Your Name]
GitHub: TheDevilPython

