Skip to content

Latest commit

Β 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 MoodGuard · AI Mental Health Monitor

Real-time emotion detection powered by deep learning and computer vision β€” analyze facial expressions through photos or live webcam using AI.

Python Flask TensorFlow OpenCV Keras License


πŸ“Œ Overview

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

✨ Features

πŸ“Έ Photo Analysis

Upload facial images and instantly detect emotional state with AI-powered prediction.

πŸŽ₯ Live Webcam Detection

Real-time emotion detection through webcam feed.

πŸ“Š Emotion Prediction Dashboard

Clean and interactive dashboard UI built with HTML, CSS, and JavaScript.

πŸ•’ Detection History

Can track and display previous analysis sessions.

πŸ”’ Privacy First

All processing happens locally. No cloud upload. No external APIs.

⚑ Fast AI Inference

TensorFlow model loaded directly in Flask for fast prediction.

🧠 Deep Learning Model

CNN trained on FER2013 facial expression dataset.


πŸ› οΈ Technology Stack

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

πŸš€ Getting Started

Prerequisites

  • Python 3.10+
  • Webcam (for video detection)
  • moodguard_model.h5

Installation

1. Clone Repository

git clone https://github.com/yourusername/MoodGuard.git
cd MoodGuard

2. Create Virtual Environment

python -m venv venv

Windows

venv\Scripts\activate

Mac/Linux

source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Add Model File

Place:

moodguard_model.h5

inside project root directory.


β–Ά Run Project

python app.py

Open browser:

http://127.0.0.1:5000

πŸ“¦ Requirements

Flask==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.0

Install:

pip install -r requirements.txt

πŸ”¬ Detection Pipeline

Input 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 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ˜„ Supported Emotions

MoodGuard detects 7 emotions:

  • Happy 😊
  • Sad 😒
  • Angry 😠
  • Fear 😨
  • Surprise 😲
  • Neutral 😐
  • Disgust πŸ˜–

🧠 Model Details

Property Value
Model CNN
Framework TensorFlow / Keras
Dataset FER2013
Classes 7 Emotions
Training Images 35K+
Format .h5
Input Facial Expressions

πŸ“ Project Structure

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

πŸ–₯️ App Sections

Section Description
πŸ“Έ Photo Analysis Upload image β†’ detect emotion
πŸŽ₯ Video Detection Real-time webcam prediction
πŸ“œ History Previous detections
ℹ️ About System overview

⚠️ Troubleshooting

Model file not found

Place moodguard_model.h5 in root directory.

Camera not opening

Check OS/browser camera permissions.

No face detected

Use a clear front-facing image.

Slow prediction

Close other heavy applications.

TensorFlow install issue

Use Python 3.10 (recommended).


πŸ—ΊοΈ Roadmap

  • Mood trend analysis
  • PDF reports
  • Session analytics
  • Database support
  • Dark mode
  • Login system
  • Voice emotion detection
  • AI chatbot integration
  • Docker deployment

πŸ‘©β€πŸ’» About Creator

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.


πŸ“„ License

Licensed under MIT License.


πŸ™ Acknowledgements

  • FER2013 Dataset
  • TensorFlow
  • OpenCV
  • Flask
  • Keras
  • Open-source AI/ML community

MoodGuard Β· v1.0
Built with ❀️ by Hamna Munir · Python · Flask · OpenCV · TensorFlow · CNN

About

MoodGuard is an AI-powered mood detection and mental health monitoring web app that analyzes facial expressions and images in real time using Flask, Deep Learning, TensorFlow, and OpenCV with a privacy-first approach.

Topics

Resources

Stars

24 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages