Small Flask + Socket.IO application that performs real-time face emotion detection using a prebuilt Keras model and OpenCV face detection. This project demonstrates streaming webcam frames to a browser, running emotion predictions on detected faces, and emitting live emotion data via WebSockets.
src/emotion_model.h5) predicts emotion probabilities for each detected face.Emotion classification model: src/emotion_model.h5 (pretrained Keras HDF5 model). Place this file in src/ (already included in this repo).
Face detector: src/haarcascade_frontalface_default.xml (OpenCV Haar cascade). Also included in src/.
These are prebuilt assets bundled with the project; you can replace them with your own models if desired.
src/ — model and face cascade, and helper scripts.webapp/ — Flask application and frontend templates.
webapp/app.py — main Flask + Socket.IO server.webapp/templates/ — HTML templates for home, login, dashboard.webapp/static/ — CSS, JS and captures/ saved images.Python 3.8+ recommended. Key packages:
flaskflask-socketiotensorflow (or tensorflow-cpu depending on your environment)opencv-pythonnumpyI can add a requirements.txt for you — let me know.
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
# or if you don't have requirements.txt:
python -m pip install flask flask-socketio tensorflow opencv-python numpy
From the webapp directory run:
python .\app.py
Open your browser at http://localhost:5000 and go to the dashboard to see the live video and emotion updates.
Notes:
.\app.py or python app.py — python app.py is recommended.app.py where cv2.VideoCapture(0) is called./ — Home page/dashboard — Dashboard (requires a simple session login)/video_feed — MJPEG stream of the webcam frames/get_emotions — Returns latest emotion percentages as JSON/capture — POST endpoint that accepts a base64 image (image) and saves it to static/capturesapp.secret_key in webapp/app.py is a placeholder; change it before deploying.This repository stitches together OpenCV face detection and a pretrained Keras emotion model to demonstrate real-time emotion recognition in the browser.
If you want, I can also create requirements.txt, add a short README badge header, or help containerize this with Docker.