CoolFace
Apppublic

ht167/emotion-sensor

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

๐ŸŽญ Emotion Detection 2.0 โ€” Deployment Package

Real-time facial emotion detection web application powered by a 4-block CNN trained on FER2013.

Quick Start

Windows

Double-click start.bat

Manual Start

bash
pip install -r requirements.txt
python server.py

Then open http://localhost:8000 in your browser.

File Structure

deploy/
โ”œโ”€โ”€ server.py            # FastAPI web server (entry point)
โ”œโ”€โ”€ model_structure.py   # CNN architecture definition
โ”œโ”€โ”€ processing.py        # Face detection & preprocessing
โ”œโ”€โ”€ emotion_model.h5     # Pre-trained model weights (~12 MB)
โ”œโ”€โ”€ requirements.txt     # Python dependencies
โ”œโ”€โ”€ start.bat            # Windows startup script
โ”œโ”€โ”€ start.sh             # Linux/macOS startup script
โ”œโ”€โ”€ templates/
โ”‚   โ””โ”€โ”€ index.html       # Web UI template
โ””โ”€โ”€ static/
    โ”œโ”€โ”€ css/
    โ”‚   โ””โ”€โ”€ style.css    # Dark glassmorphism theme
    โ””โ”€โ”€ js/
        โ””โ”€โ”€ app.js       # Frontend logic (WebSocket + Canvas)

How It Works

  1. 1.Browser captures webcam frames via getUserMedia()
  2. 2.Frames are sent as base64 JPEG over WebSocket to the server
  3. 3.Haar Cascade detects face bounding boxes
  4. 4.Each face is preprocessed: crop โ†’ grayscale โ†’ 48ร—48 โ†’ normalize
  5. 5.CNN (4 conv blocks + softmax) predicts emotion probabilities
  6. 6.Results are sent back and rendered as live overlays

Emotions Detected

EmotionIndexColor
Angry0๐Ÿ”ด Red
Disgust1๐ŸŸข Green
Fear2๐ŸŸฃ Purple
Happy3๐ŸŸก Yellow
Sad4๐Ÿ”ต Blue
Surprise5๐ŸŸ  Orange
Neutral6โšช Gray

Requirements

  • โ€”Python 3.8+
  • โ€”Webcam
  • โ€”~500 MB RAM
  • โ€”No GPU required (CPU-optimized)

Privacy

All processing is performed locally. No images or data leave your machine.