CoolFace
Apppublic

ht167/emotion-sensor-2.0

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

๐ŸŽญ Emotion Detection 2.0

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

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

File Structure

โ”œโ”€โ”€ Dockerfile           # Docker build config for HF Spaces
โ”œโ”€โ”€ app.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
โ”œโ”€โ”€ templates/
โ”‚   โ””โ”€โ”€ index.html       # Web UI template
โ””โ”€โ”€ static/
    โ”œโ”€โ”€ css/
    โ”‚   โ””โ”€โ”€ style.css    # Dark glassmorphism theme
    โ””โ”€โ”€ js/
        โ””โ”€โ”€ app.js       # Frontend logic (WebSocket + Canvas)

Requirements

  • โ€”Python 3.9+
  • โ€”Webcam
  • โ€”~500 MB RAM
  • โ€”No GPU required (CPU-optimized with tensorflow-cpu)

Privacy

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