Real-time emotion detection powered by deep learning and computer vision β analyze facial expressions through photos or live webcam using AI.
MoodGuard is an AI-powered emotion recognition and mental health monitoring web application that uses Convolutional Neural Networks (CNN) and computer vision to detect facial emotions in real time.
The system can analyze uploaded images, captured photos, and live webcam feeds to predict emotional states such as happiness, sadness, anger, fear, surprise, disgust, and neutrality.
It is designed with a privacy-first local AI approach, meaning no facial data is sent to any external server.
| Metric | Value |
|---|---|
| π― Model Accuracy | 66.6% |
| πΌοΈ Training Images | 35,000+ |
| π Emotion Classes | 7 |
| π§ Model Type | CNN |
| π¦ Dataset | FER2013 |
| π Privacy | 100% Local Processing |
Upload facial images and instantly detect emotional state with AI-powered prediction.
Real-time emotion detection through webcam feed.
Clean and interactive dashboard UI built with HTML, CSS, and JavaScript.
Can track and display previous analysis sessions.
All processing happens locally. No cloud upload. No external APIs.
TensorFlow model loaded directly in Flask for fast prediction.
CNN trained on FER2013 facial expression dataset.
| Technology | Role |
|---|---|
| π Python 3.10 | Core language |
| π Flask | Backend web framework |
| π€ TensorFlow / Keras | CNN model loading & prediction |
| π· OpenCV | Face detection & image preprocessing |
| π’ NumPy | Numerical computation |
| πΌοΈ Pillow | Image handling |
| π¨ HTML / CSS / JS | Frontend dashboard |
| π¦ H5Py | Loading .h5 trained model |
- Python 3.10+
- Webcam (for video detection)
moodguard_model.h5
git clone https://github.com/yourusername/MoodGuard.git
cd MoodGuardpython -m venv venvvenv\Scripts\activatesource venv/bin/activatepip install -r requirements.txtPlace:
moodguard_model.h5inside project root directory.
python app.pyOpen browser:
http://127.0.0.1:5000Flask==3.0.3
tensorflow==2.10.0
opencv-python==4.10.0.84
numpy==1.23.5
Pillow==10.4.0
h5py==3.11.0
gunicorn==22.0.0Install:
pip install -r requirements.txtInput Image / Webcam
β
βΌ
ββββββββββββββββββββββββββ
β 1. Image Capture β
β Photo Upload / Webcam β
ββββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β 2. Face Detection β
β OpenCV Haar Cascade β
ββββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β 3. Preprocessing β
β Resize + Normalize β
ββββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β 4. CNN Prediction β
β TensorFlow / Keras β
ββββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β 5. Emotion Output β
β UI + Prediction Result β
ββββββββββββββββββββββββββ
MoodGuard detects 7 emotions:
- Happy π
- Sad π’
- Angry π
- Fear π¨
- Surprise π²
- Neutral π
- Disgust π
| Property | Value |
|---|---|
| Model | CNN |
| Framework | TensorFlow / Keras |
| Dataset | FER2013 |
| Classes | 7 Emotions |
| Training Images | 35K+ |
| Format | .h5 |
| Input | Facial Expressions |
MoodGuard/
β
βββ app.py
βββ detect_emotion.py
βββ prepare_dataset.py
βββ train_model.py
βββ moodguard_model.h5
βββ requirements.txt
βββ README.md
βββ .gitignore
β
βββ templates/
β βββ index.html
β
βββ static/
βββ style.css
βββ script.js| Section | Description |
|---|---|
| πΈ Photo Analysis | Upload image β detect emotion |
| π₯ Video Detection | Real-time webcam prediction |
| π History | Previous detections |
| βΉοΈ About | System overview |
Place moodguard_model.h5 in root directory.
Check OS/browser camera permissions.
Use a clear front-facing image.
Close other heavy applications.
Use Python 3.10 (recommended).
- Mood trend analysis
- PDF reports
- Session analytics
- Database support
- Dark mode
- Login system
- Voice emotion detection
- AI chatbot integration
- Docker deployment
Hamna Munir
AI/ML Engineer β’ Software Engineering Student
Built MoodGuard as an end-to-end AI project combining:
- Deep Learning
- CNN Architecture
- Computer Vision
- Flask Deployment
- Frontend + Backend Integration
- Real-time AI Prediction
This project demonstrates a complete machine learning workflow from preprocessing β model training β deployment.
Licensed under MIT License.
- FER2013 Dataset
- TensorFlow
- OpenCV
- Flask
- Keras
- Open-source AI/ML community
Built with β€οΈ by Hamna Munir Β· Python Β· Flask Β· OpenCV Β· TensorFlow Β· CNN