A comprehensive real-time emotion detection system powered by deep learning models and modern web technologies. This application combines 9 pre-trained PyTorch models with an intuitive React frontend and FastAPI backend for accurate emotion recognition.
- Due to the free tier hosting the frontend and backend might be slow to load 1 to 2 minute as the render service shut down and redeploy them only when they are tried to accessed.
- 9 Pre-trained Models: Choose from MobileNetV2, ResNet50, and VGG19 architectures trained on FER2013, RAF-DB, and CK+48 datasets
- Real-time Detection: Live emotion recognition through webcam with instant results
- Image Upload: Upload images for emotion analysis with detailed confidence scores
- Interactive Web Interface: Clean, responsive UI with dark/light mode support
- High Accuracy: Up to 98.99% accuracy on controlled datasets, 80.28% on real-world scenarios
- FastAPI Backend: High-performance API with automatic model loading and GPU acceleration
- Deployment Ready: Complete deployment guides for multiple platforms
| Model | FER2013 | RAF-DB | CK+48 |
|---|---|---|---|
| MobileNetV2 | 55.68% | 73.57% | 97.98% |
| ResNet50 | 56.60% | 76.27% | 98.99% |
| VGG19 | 58.75% | 80.28% | 98.99% |
- React 18.3.1 - Modern UI library
- Vite - Fast build tool and dev server
- Tailwind CSS - Utility-first CSS framework
- Lucide React - Beautiful icon library
- React Router - Client-side routing
- FastAPI - High-performance Python web framework
- PyTorch 2.1.0 - Deep learning framework
- Torchvision - Computer vision utilities
- Uvicorn - ASGI server implementation
- Pillow - Image processing library
- Node.js 18+ and npm
- Python 3.8+ and pip
- CUDA (optional, for GPU acceleration)
- Trained model files (place in
backend/results/)
git clone <repository-url>
cd emotion-detection-app# Install dependencies
npm install
# Start development server
npm run dev# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r backend/requirements.txt
# Start FastAPI server
cd backend && python main.pyPlace your trained model files in the backend/results/ directory:
backend/results/
βββ MobileNetV2_FER2013_best.pt
βββ MobileNetV2_RAF-DB_best.pt
βββ MobileNetV2_CK+48_best.pt
βββ ResNet50_FER2013_best.pt
βββ ResNet50_RAF-DB_best.pt
βββ ResNet50_CK+48_best.pt
βββ VGG19_FER2013_best.pt
βββ VGG19_RAF-DB_best.pt
βββ VGG19_CK+48_best.pt
- Frontend: http://localhost:5173
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
The frontend is already deployed at: https://lively-cannoli-82572a.netlify.app
# 1. Create account at railway.app
# 2. Connect your GitHub repository
# 3. Deploy from the backend folder
# 4. Railway will use the Dockerfile automatically# 1. Create account at render.com
# 2. Create new Web Service
# 3. Set build command: pip install -r requirements.txt
# 4. Set start command: uvicorn main:app --host 0.0.0.0 --port $PORT# 1. Install Vercel CLI: npm i -g vercel
# 2. Run vercel in the backend directory
# 3. Uses serverless configuration with mock predictionscd backend
docker build -t emotion-api .
docker run -p 8000:8000 emotion-apiAfter deploying your backend, update the frontend environment:
- Create
.envfile in the root directory:
VITE_API_URL=https://your-backend-domain.railway.app- Redeploy the frontend to Netlify with the new environment variable.
- Select Model: Choose from 9 available models based on your accuracy/speed requirements
- Live Detection: Enable camera permissions and click "Start Detection"
- Image Upload: Upload an image and click "Analyze Emotion"
- View Results: See real-time emotion predictions with confidence scores
emotion-detection-app/
βββ src/ # React frontend source
β βββ components/ # Reusable UI components
β βββ pages/ # Application pages
β βββ contexts/ # React contexts (theme)
β βββ config/ # API configuration
β βββ main.tsx # Application entry point
βββ backend/ # FastAPI backend
β βββ main.py # FastAPI application
β βββ main-serverless.py # Serverless version
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Docker configuration
β βββ railway.json # Railway deployment config
β βββ render.yaml # Render deployment config
β βββ vercel.json # Vercel deployment config
β βββ results/ # Model files directory
β βββ DEPLOYMENT.md # Deployment guide
β βββ README.md # Backend documentation
βββ public/ # Static assets
βββ .env.example # Environment variables template
βββ README.md # This file
Get information about available models and their configurations.
Predict emotion from uploaded image.
- Parameters:
file(image),model(string) - Response: Emotion predictions with confidence scores
Health check endpoint for monitoring API status.
- FER2013: 35,887 grayscale images, 7 emotions
- RAF-DB: 15,339 real-world images, 7 emotions
- CK+48: 981 lab-controlled images, 7 emotions
- MobileNetV2: 3.5M parameters, optimized for mobile
- ResNet50: 25.6M parameters, balanced performance
- VGG19: 143.7M parameters, highest accuracy
- Add model configuration to
MODEL_CONFIGSinbackend/main.py - Place model file in
backend/results/ - Update documentation and frontend model list
# Frontend
VITE_API_URL=http://localhost:8000
# Backend
PORT=8000
HOST=0.0.0.0-
API Connection Failed
- Check if backend server is running
- Verify API URL in environment variables
- Check CORS configuration
-
Model files not found
- Verify files are in
backend/results/directory - Check file names match configuration exactly
- Verify files are in
-
Camera access denied
- Enable camera permissions in browser settings
- Ensure HTTPS in production (required for camera access)
-
Slow inference
- Check GPU availability and CUDA installation
- Consider using MobileNetV2 for faster inference
- RAM: 8GB minimum (16GB recommended for GPU inference)
- Storage: 2GB for models and dependencies
- GPU: NVIDIA GPU with CUDA support (optional)
- Chrome: 90+
- Firefox: 88+
- Safari: 14+
- Edge: 90+
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit changes:
git commit -am 'Add feature' - Push to branch:
git push origin feature-name - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- FER2013, RAF-DB, CK+48 datasets for training data
- PyTorch team for the deep learning framework
- FastAPI for the high-performance web framework
- React and Vite teams for modern web development tools
For questions, issues, or contributions:
- Check the backend deployment guide at
backend/DEPLOYMENT.md - Review the API docs at
/docs(when backend is running) - Create an issue on GitHub
Built with β€οΈ using React, FastAPI, and PyTorch
- Frontend: https://lively-cannoli-82572a.netlify.app
- Backend: Deploy using the guide in
backend/DEPLOYMENT.md