Skip to content

Co-vengers/Music-Recommendation-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎭 Facial Emotion Recognition & Music Recommendation System

An AI-powered web application that detects emotions from facial expressions in real-time and recommends personalized music playlists based on the detected mood.

Python TensorFlow Flask React Docker License


πŸ“‹ Table of Contents


✨ Features

  • 🎯 Real-time Emotion Detection - Detects 7 different emotions from facial expressions
  • 🎡 Music Recommendations - Suggests Spotify playlists based on detected emotions
  • πŸ“Έ Live Camera Feed - Capture photos directly from webcam
  • πŸ€– Deep Learning CNN - Custom-trained Convolutional Neural Network
  • 🎨 Modern React UI - Responsive, mobile-friendly interface with Tailwind CSS
  • 🐳 Docker Ready - One-command deployment with Docker Compose
  • πŸ”„ RESTful API - Clean Flask backend with JSON responses
  • πŸ“Š High Accuracy - ~70-80% accuracy on emotion detection
  • 🌐 Production Ready - Nginx reverse proxy with optimized settings

Supported Emotions

Emotion Icon Music Genre
😊 Happy 😊 Pop, Party, Summer
😒 Sad 😒 Chill, Acoustic, Rainy-day
😠 Angry 😠 Rock, Metal, Power
😐 Neutral 😐 Study, Ambient, Focus
😲 Surprise 😲 Dance, Pop, Exciting
😨 Fear 😨 Calm, Peaceful, Acoustic
🀒 Disgust 🀒 Indie, Alternative, Fresh

πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Docker Compose                          β”‚
β”‚                                                              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚  emotion-frontend      β”‚    β”‚  emotion-backend     β”‚   β”‚
β”‚  β”‚  (nginx:alpine)        │◄──►│  (python:3.10-slim)  β”‚   β”‚
β”‚  β”‚                        β”‚    β”‚                      β”‚   β”‚
β”‚  β”‚  - React App (build)   β”‚    β”‚  - Flask API         β”‚   β”‚
β”‚  β”‚  - Nginx Server        β”‚    β”‚  - TensorFlow Model  β”‚   β”‚
β”‚  β”‚  - Reverse Proxy       β”‚    β”‚  - OpenCV            β”‚   β”‚
β”‚  β”‚  Port: 80 β†’ Host       β”‚    β”‚  - Spotify API       β”‚   β”‚
β”‚  β”‚                        β”‚    β”‚  Port: 8000 (internal)β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚                                                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Request Flow

User Browser (http://localhost)
    ↓
Nginx (Port 80) - emotion-frontend container
    ↓
    β”œβ”€β†’ /api/* β†’ Proxy to backend:8000/api/*
    β”œβ”€β†’ /health β†’ Proxy to backend:8000/health
    └─→ /* β†’ Serve React static files
         ↓
Flask API (Port 8000) - emotion-backend container
    ↓
    β”œβ”€β†’ Face Detection (OpenCV)
    β”œβ”€β†’ Emotion Prediction (TensorFlow/Keras)
    └─→ Music Recommendations (Spotify API)

πŸ›  Tech Stack

Backend

  • Python 3.10 - Core programming language
  • TensorFlow/Keras - Deep learning framework
  • Flask - Web framework
  • Flask-CORS - Cross-Origin Resource Sharing
  • OpenCV - Computer vision & face detection
  • Spotipy - Spotify Web API wrapper
  • NumPy - Numerical computing
  • Pillow - Image processing

Frontend

  • React 18 - UI framework
  • Tailwind CSS - Utility-first CSS framework
  • Axios - HTTP client
  • React Webcam - Camera integration (if used)
  • Nginx - Production web server

DevOps & Infrastructure

  • Docker - Containerization
  • Docker Compose - Multi-container orchestration
  • Nginx - Reverse proxy, static file serving, gzip compression
  • Multi-stage builds - Optimized Docker images

πŸ“¦ Prerequisites

Required Software

For Docker Deployment (Recommended):

For Manual Installation:

  • Python 3.10+
  • Node.js 18+
  • npm or yarn

System Requirements

  • RAM: Minimum 8GB (16GB recommended for training)
  • Storage: ~5GB free space (dataset + model + containers)
  • OS: Windows 10/11, macOS, or Linux
  • Webcam: For live capture (optional)
  • Internet: For Spotify API and npm packages

Get Spotify API Credentials

  1. Go to Spotify Developer Dashboard
  2. Log in and create a new app
  3. Set redirect URI: http://localhost:5000/callback
  4. Copy Client ID and Client Secret

πŸš€ Quick Start with Docker

Step 1: Clone Repository

git clone https://github.com/yourusername/emotion-music-recommender.git
cd emotion-music-recommender

Step 2: Create Environment File

Create .env in the project root:

# .env
SPOTIFY_CLIENT_ID=your_spotify_client_id_here
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret_here

Step 3: Train the Model (Required First Time)

IMPORTANT: The model must be trained before Docker containers can run!

# Navigate to backend
cd backend

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Verify dataset structure
python train_model.py

# If dataset is ready, train the model (takes 1-3 hours)
python train_model.py

# Expected output:
# βœ“ Model saved to models/emotion_model.keras

Step 4: Build and Run with Docker

# Go back to project root
cd ..

# Build and start all containers
docker-compose up --build

# Or run in detached mode:
docker-compose up -d --build

Step 5: Access the Application

Open your browser and navigate to:

http://localhost

Or if you're deploying on a server:

http://your_server_ip

Step 6: Stop the Application

# Stop containers
docker-compose down

# Stop and remove volumes
docker-compose down -v

πŸ’» Manual Installation

If you prefer to run without Docker:

Backend Setup

cd backend

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Train model (if not done already)
python train_model.py

# Run Flask server
python app.py
# Server will run on http://localhost:8000

Frontend Setup

cd frontend

# Install dependencies
npm install

# Create .env file for frontend
echo "REACT_APP_BACKEND_URL=http://localhost:8000" > .env

# Run development server
npm start
# Frontend will run on http://localhost:3000

# Or build for production
npm run build
# Build files will be in frontend/build/

πŸ“Š Dataset Setup

Dataset Structure

Your dataset should be organized as follows:

backend/data/1/
β”œβ”€β”€ train/
β”‚   β”œβ”€β”€ angry/
β”‚   β”‚   β”œβ”€β”€ img001.jpg
β”‚   β”‚   β”œβ”€β”€ img002.jpg
β”‚   β”‚   └── ...
β”‚   β”œβ”€β”€ disgust/
β”‚   β”œβ”€β”€ fear/
β”‚   β”œβ”€β”€ happy/
β”‚   β”œβ”€β”€ neutral/
β”‚   β”œβ”€β”€ sad/
β”‚   └── surprise/
└── test/
    β”œβ”€β”€ angry/
    β”œβ”€β”€ disgust/
    β”œβ”€β”€ fear/
    β”œβ”€β”€ happy/
    β”œβ”€β”€ neutral/
    β”œβ”€β”€ sad/
    └── surprise/

Download Dataset

Option 1: FER2013 from Kaggle

  1. Visit Kaggle FER2013 Dataset
  2. Download and extract to backend/data/1/
  3. Ensure folder structure matches above

Option 2: Custom Dataset

Organize your own images following the structure above. Requirements:

  • Images should be faces (will be auto-cropped)
  • Minimum 1000 images per emotion recommended
  • Supported formats: .jpg, .jpeg, .png
  • Minimum resolution: 48x48 pixels

Verify Dataset

cd backend
python -c "
import os
data_path = 'data/1'
for split in ['train', 'test']:
    print(f'\n{split.upper()} SET:')
    total = 0
    for emotion in ['angry', 'disgust', 'fear', 'happy', 'neutral', 'sad', 'surprise']:
        path = os.path.join(data_path, split, emotion)
        if os.path.exists(path):
            count = len([f for f in os.listdir(path) if f.endswith(('.jpg', '.jpeg', '.png'))])
            print(f'  {emotion:10s}: {count:6d} images')
            total += count
    print(f'  {'Total':10s}: {total:6d} images')
"

Expected Output:

TRAIN SET:
  angry     :   3995 images
  disgust   :    436 images
  fear      :   4097 images
  happy     :   7215 images
  neutral   :   4965 images
  sad       :   4830 images
  surprise  :   3171 images
  Total     :  28709 images

TEST SET:
  angry     :    958 images
  disgust   :    111 images
  fear      :   1024 images
  happy     :   1774 images
  neutral   :   1233 images
  sad       :   1247 images
  surprise  :    831 images
  Total     :   7178 images

πŸŽ“ Training the Model

Training Process

cd backend

# Activate virtual environment
source venv/bin/activate  # macOS/Linux
# OR
venv\Scripts\activate     # Windows

# Start training
python train_model.py

Training Output

======================================================================
  FACIAL EMOTION RECOGNITION - CNN MODEL TRAINING
======================================================================

Training started at: 2024-12-18 10:30:00

Verifying dataset structure...
βœ“ Found 28,709 training images
βœ“ Found 7,178 validation images
βœ“ Number of classes: 7

Creating CNN model...
Model Architecture:
_________________________________________________________________
Layer (type)                 Output Shape              Param #
=================================================================
conv2d (Conv2D)              (None, 48, 48, 32)        320
batch_normalization          (None, 48, 48, 32)        128
conv2d_1 (Conv2D)            (None, 48, 48, 32)        9,248
...
=================================================================
Total params: 3,456,789
Trainable params: 3,452,693
Non-trainable params: 4,096

Training Configuration:
  Batch Size: 64
  Steps per Epoch: 448
  Validation Steps: 112
  Max Epochs: 50
  Learning Rate: 0.001

======================================================================
Starting training...
======================================================================

Epoch 1/50
448/448 [==============================] - 67s 149ms/step
  loss: 1.7234 - accuracy: 0.3456 - val_loss: 1.5432 - val_accuracy: 0.4123

Epoch 2/50
448/448 [==============================] - 64s 143ms/step
  loss: 1.5123 - accuracy: 0.4234 - val_loss: 1.4123 - val_accuracy: 0.4567

...

Epoch 50/50
448/448 [==============================] - 62s 138ms/step
  loss: 0.7234 - accuracy: 0.7856 - val_loss: 0.8234 - val_accuracy: 0.7456

======================================================================
Evaluating model on test set...
======================================================================

πŸ“Š Final Results:
  Test Loss: 0.9298
  Test Accuracy: 65.54%

======================================================================
Generating visualizations...
======================================================================

βœ“ Training history plot saved to plots/training_history.png
βœ“ Confusion matrix saved to plots/confusion_matrix.png

======================================================================
Classification Report:
======================================================================
              precision    recall  f1-score   support

       Angry       0.56      0.62      0.59       958
     Disgust       0.68      0.41      0.51       111
        Fear       0.56      0.33      0.42      1024
       Happy       0.87      0.87      0.87      1774
     Neutral       0.54      0.75      0.63      1233
         Sad       0.56      0.49      0.52      1247
    Surprise       0.75      0.78      0.76       831

    accuracy                           0.66      7178
   macro avg       0.64      0.61      0.62      7178
weighted avg       0.66      0.66      0.65      7178


βœ“ Model saved to models/emotion_model.keras

======================================================================
Training completed at: 2025-12-17 16:38:33
======================================================================

======================================================================
βœ“ TRAINING COMPLETE!
======================================================================

Next steps:
  1. Check 'models/emotion_model.h5' - your trained model
  2. Check 'plots/' folder for training visualizations
  3. Run 'python app.py' to start the Flask backend
  4. Connect your React frontend to http://localhost:5000

======================================================================

Training Configuration

Edit backend/train_model.py to customize:

# Dataset path
DATASET_PATH = 'data/1'

# Model save location
MODEL_SAVE_PATH = 'models/emotion_model.keras'

# Hyperparameters
IMG_SIZE = 48           # Image dimensions
BATCH_SIZE = 64         # Training batch size
EPOCHS = 50             # Number of epochs
LEARNING_RATE = 0.001   # Adam optimizer learning rate

Training Time Estimates

Hardware Approximate Time
CPU only (i7/i9) 3-5 hours
GPU (GTX 1660) 1.5-2 hours
GPU (RTX 3060) 1-1.5 hours
GPU (RTX 4090) 30-45 minutes

πŸ“‘ API Documentation

Base URL

# When using Docker
http://localhost/api

# When running manually
http://localhost:8000/api

Endpoints

1. Health Check

GET /health

Response:

{
  "status": "healthy",
  "model_loaded": true,
  "face_cascade_loaded": true,
  "spotify_connected": true,
  "supported_emotions": [
    "angry", "disgust", "fear", "happy", 
    "neutral", "sad", "surprise"
  ],
  "timestamp": "2024-12-18T10:30:00.000Z"
}

2. Detect Emotion

POST /api/detect-emotion
Content-Type: application/json

Request:

{
  "image": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAA..."
}

Success Response:

{
  "success": true,
  "emotion": "happy",
  "confidence": 87.34,
  "face_location": {
    "x": 120,
    "y": 80,
    "width": 200,
    "height": 200
  },
  "playlists": [
    {
      "playlist_name": "😊 Happy Vibes Collection",
      "playlist_url": "https://open.spotify.com/playlist/...",
      "tracks": [
        {
          "title": "Happy",
          "artist": "Pharrell Williams",
          "duration": "3:53",
          "genre": "Pop",
          "spotify_url": "https://open.spotify.com/track/...",
          "preview_url": "https://p.scdn.co/mp3-preview/...",
          "album_art": "https://i.scdn.co/image/..."
        }
      ]
    }
  ],
  "timestamp": "2024-12-18T10:30:00.000Z"
}

Error Response:

{
  "success": false,
  "error": "No face detected in the image. Please ensure your face is clearly visible."
}

3. Get Emotions List

GET /api/emotions

Response:

{
  "emotions": [
    "angry", "disgust", "fear", "happy", 
    "neutral", "sad", "surprise"
  ],
  "count": 7,
  "descriptions": {
    "angry": "Feeling mad or frustrated",
    "disgust": "Feeling repulsed or averse",
    "fear": "Feeling scared or anxious",
    "happy": "Feeling joyful or content",
    "neutral": "Feeling calm or indifferent",
    "sad": "Feeling down or melancholic",
    "surprise": "Feeling shocked or amazed"
  }
}

4. Test Spotify Connection

GET /api/test-spotify

Response:

{
  "connected": true,
  "message": "Spotify API working correctly",
  "test_result": true
}

πŸ“ Project Structure

emotion-music-recommender/
β”‚
β”œβ”€β”€ .env                              # Environment variables
β”œβ”€β”€ docker-compose.yml                # Docker Compose configuration
β”œβ”€β”€ README.md                         # This file
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ Dockerfile                    # Backend container definition
β”‚   β”œβ”€β”€ requirements.txt              # Python dependencies
β”‚   β”œβ”€β”€ app.py                        # Flask API server
β”‚   β”œβ”€β”€ train_model.py                # Model training script
β”‚   β”‚
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”œβ”€β”€ 1/
β”‚   β”‚   β”‚   β”œβ”€β”€ train/               # Training images
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ angry/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ disgust/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ fear/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ happy/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ neutral/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ sad/
β”‚   β”‚   β”‚   β”‚   └── surprise/
β”‚   β”‚   β”‚   └── test/                # Test images
β”‚   β”‚   β”‚       β”œβ”€β”€ angry/
β”‚   β”‚   β”‚       β”œβ”€β”€ disgust/
β”‚   β”‚   β”‚       β”œβ”€β”€ fear/
β”‚   β”‚   β”‚       β”œβ”€β”€ happy/
β”‚   β”‚   β”‚       β”œβ”€β”€ neutral/
β”‚   β”‚   β”‚       β”œβ”€β”€ sad/
β”‚   β”‚   β”‚       └── surprise/
β”‚   β”‚   └── dataset_download.py      # Dataset download helper
β”‚   β”‚
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── emotion_model.keras      # Trained model (created after training)
β”‚   β”‚
β”‚   └── plots/
β”‚       β”œβ”€β”€ training_history.png     # Training metrics visualization
β”‚       └── confusion_matrix.png     # Model performance matrix
β”‚
└── frontend/
    β”œβ”€β”€ Dockerfile                    # Frontend container definition
    β”œβ”€β”€ nginx.conf                    # Nginx configuration
    β”œβ”€β”€ package.json                  # Node.js dependencies
    β”œβ”€β”€ package-lock.json             # Locked dependencies
    β”œβ”€β”€ tailwind.config.js            # Tailwind CSS configuration
    β”œβ”€β”€ README.md                     # Frontend documentation
    β”‚
    β”œβ”€β”€ public/
    β”‚   β”œβ”€β”€ index.html                # HTML template
    β”‚   β”œβ”€β”€ favicon.ico               # App icon
    β”‚   β”œβ”€β”€ manifest.json             # PWA manifest
    β”‚   └── robots.txt                # SEO robots file
    β”‚
    └── src/
        β”œβ”€β”€ App.js                    # Main React component
        β”œβ”€β”€ App.css                   # App styles
        β”œβ”€β”€ index.js                  # Entry point
        β”œβ”€β”€ index.css                 # Global styles
        └── ...                       # Other components

βš™οΈ Configuration

Docker Compose Configuration

File: docker-compose.yml

version: "3.9"

services:
  backend:
    build:
      context: ./backend
    container_name: emotion-backend
    expose:
      - "8000"
    environment:
      SPOTIFY_CLIENT_ID: ${SPOTIFY_CLIENT_ID}
      SPOTIFY_CLIENT_SECRET: ${SPOTIFY_CLIENT_SECRET}
    restart: unless-stopped

  frontend:
    build:
      context: ./frontend
    container_name: emotion-frontend
    ports:
      - "80:80"
    environment:
      REACT_APP_BACKEND_URL: http://your_server_ip:8000
    depends_on:
      - backend
    restart: unless-stopped

Backend Configuration

File: backend/app.py

# Port configuration
# When using Docker, Flask listens on port 8000
if __name__ == '__main__':
    app.run(debug=False, host='0.0.0.0', port=8000)

# Model path
MODEL_PATH = 'models/emotion_model.keras'

# Emotion labels (MUST match training order)
EMOTION_LABELS = ['angry', 'disgust', 'fear', 'happy', 
                  'neutral', 'sad', 'surprise']

Frontend Configuration

File: frontend/nginx.conf

Key configurations:

  • Proxies /api/* requests to backend:8000
  • Serves React static files
  • Enables gzip compression
  • Caches static assets
  • Security headers

Environment Variables: Create frontend/.env for development:

REACT_APP_BACKEND_URL=http://localhost:8000

Environment Variables

File: .env (project root)

# Required: Spotify API credentials
SPOTIFY_CLIENT_ID=your_client_id_here
SPOTIFY_CLIENT_SECRET=your_client_secret_here

# Optional: Flask configuration
FLASK_ENV=production
FLASK_DEBUG=False

🌐 Deployment

Docker Deployment (Production)

1. Update Backend URL

In docker-compose.yml, update the frontend environment:

frontend:
  environment:
    REACT_APP_BACKEND_URL: http://YOUR_SERVER_IP:8000

2. Deploy to Server

# Transfer files to server
scp -r emotion-music-recommender user@your_server:/home/user/

# SSH into server
ssh user@your_server

# Navigate to project
cd /home/user/emotion-music-recommender

# Create .env file
nano .env
# Add your Spotify credentials

# Build and start
docker-compose up -d --build

# Check logs
docker-compose logs -f

# Check status
docker-compose ps

3. Configure Firewall

# Allow HTTP traffic
sudo ufw allow 80/tcp

# Allow HTTPS (if using SSL)
sudo ufw allow 443/tcp

# Enable firewall
sudo ufw enable

Production Checklist

  • Trained model exists at backend/models/emotion_model.keras
  • .env file configured with Spotify credentials
  • Backend URL updated in docker-compose.yml
  • Firewall rules configured
  • Docker and Docker Compose installed
  • Sufficient disk space (5GB+)
  • Sufficient RAM (8GB+)

HTTPS/SSL Setup (Optional but Recommended)

Use Let's Encrypt with Certbot:

# Install Certbot
sudo apt-get install certbot python3-certbot-nginx

# Update nginx.conf to include your domain
# Then get certificate
sudo certbot --nginx -d yourdomain.com

# Auto-renewal (optional)
sudo certbot renew --dry-run

Monitoring

# View logs
docker-compose logs -f backend
docker-compose logs -f frontend

# Check container stats
docker stats

# Restart containers
docker-compose restart

# Update application
git pull
docker-compose up -d --build

πŸ› Troubleshooting

Common Issues

1. Model Not Found Error

⚠ Model not found at models/emotion_model.keras

Solution:

cd backend
source venv/bin/activate
python train_model.py

2. Docker Container Won't Start

# Check logs
docker-compose logs backend
docker-compose logs frontend

# Common issue: Port already in use
# Solution: Stop conflicting service or change port in docker-compose.yml

3. No Face Detected

Solutions:

  • Ensure good lighting
  • Face camera directly
  • Remove glasses/masks if possible
  • Check camera permissions
  • Verify image is not too dark/bright

4. CORS Errors

Solution: Verify nginx.conf proxy settings and Flask-CORS configuration

# In app.py, ensure CORS is enabled
from flask_cors import CORS
app = Flask(__name__)
CORS(app)

5. Spotify API Connection Failed

# Check credentials
cat .env

# Verify in container
docker-compose exec backend printenv | grep SPOTIFY

# Test connection
curl http://localhost/health

6. Low Prediction Accuracy

Solutions:

  • Train for more epochs
  • Add more training data
  • Verify preprocessing matches training
  • Check emotion label order

7. Out of Memory During Training

# In train_model.py, reduce batch size
BATCH_SIZE = 32  # or 16

# Or enable GPU memory growth
import tensorflow as tf
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
    tf.config.experimental.set_memory_growth(gpus[0], True)

8. Frontend Build Fails

cd frontend

# Clear node modules and reinstall
rm -rf node_modules package-lock.json
npm install

# Build again
npm run build

Debug Commands

# Check Docker containers
docker-compose ps
docker-compose logs -f

# Enter backend container
docker-compose exec backend /bin/bash

# Enter frontend container  
docker-compose exec frontend /bin/sh

# Check backend health
curl http://localhost/health

# Test API directly
curl -X POST http://localhost/api/detect-emotion \
  -H "Content-Type: application/json" \
  -d '{"image": "data:image/jpeg;base64,..."}'

# Rebuild specific service
docker-compose up -d --build backend

# Remove all containers and rebuild
docker-compose down
docker-compose up --build

πŸš€ Performance Optimization

Backend Optimization

  1. Model Optimization:
# Use TensorFlow Lite for faster inference
# Add to app.py
import tensorflow as tf
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
tflite_model = converter.convert()
  1. Caching:
# Cache face detection results
from functools import lru_cache

@lru_cache(maxsize=128)
def get_cached_predictions(image_hash):
    return model.predict(image)

Frontend Optimization

  1. Code Splitting: Already implemented via React.lazy()
  2. Image Compression: Compress before sending to backend
  3. Lazy Loading: Load components on demand

Nginx Optimization

Already configured in nginx.conf:

  • Gzip compression
  • Static asset caching
  • Connection pooling

πŸ“ˆ Future Improvements

Planned Features

  • Real-time video emotion tracking
  • Multi-face detection and analysis
  • Emotion history timeline
  • User authentication and profiles
  • Save favorite songs/playlists
  • Custom playlist creation
  • Mobile app (React Native)
  • Voice emotion detection
  • Emotion analytics dashboard
  • Share emotions on social media

Technical Enhancements

  • Kubernetes deployment
  • Redis caching
  • PostgreSQL database
  • WebSocket for real-time updates
  • GraphQL API
  • Microservices architecture
  • Load balancing
  • CI/CD pipeline (GitHub Actions)
  • Automated testing
  • Performance monitoring (Prometheus/Grafana)

Model Improvements

  • Transfer learning (VGG, ResNet)
  • Ensemble models
  • Larger training dataset
  • Data augmentation techniques
  • Multi-task learning (age, gender)
  • Attention mechanisms
  • Model quantization for edge deployment

🀝 Contributing

Contributions are welcome! Please follow these guidelines:

Getting Started

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/yourusername/emotion-music-recommender.git
  3. Create a branch: git checkout -b feature/amazing-feature
  4. Make your changes
  5. Test thoroughly
  6. Commit: git commit -m 'Add amazing feature'
  7. Push: git push origin feature/amazing-feature
  8. Open a Pull Request

Code Standards

Python (Backend):

  • Follow PEP 8 style guide
  • Use type hints where applicable
  • Add docstrings to functions
  • Write unit tests for new features

JavaScript (Frontend):

  • Follow Airbnb style guide
  • Use ESLint and Prettier
  • Write component tests
  • Use meaningful variable names

Commit Message Format

type(scope): subject

body

footer

Types: feat, fix, docs, style, refactor, test, chore

Example:

feat(backend): add emotion confidence threshold

Added configurable confidence threshold for emotion detection
to filter out low-confidence predictions.

Closes #42

Pull Request Template

## Description
Brief description of changes

## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update

## Testing
- [ ] Tests pass locally
- [ ] Added new tests
- [ ] Manual testing completed

## Screenshots (if applicable)

## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review completed
- [ ] Commented complex

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors