How sarmadusmani89/emotion-prediction works
Project type and purpose
• From the file tree and README, this is a small full-stack web application (likely built with Flask) that performs real-time emotion detection on video streams (webcam or sample videos) using a pre-trained PyTorch model. It serves a web front-end, processes video frames server-side, runs inference, and sends processed frames/alerts back to the browser.
File structure
• Top-level files:
• main.py – entry point, defines web server routes
• emotion_recognizer.py – encapsulates video capture and model-inference logic
• attention_autoencoder_emotion_model.pth – pre-trained PyTorch model
• templates/index.html – front-end HTML view
• static/alert.mp3 – audio alert asset
• videos/… – sample video files
• Pattern: a single backend service (MVC style)
• “templates” = Views
• “main.py” routes = Controllers
• “emotion_recognizer.py” + .pth = Model
• No external microservices or databases; uses in-memory video capture and model loading.
README for additional insights
• Confirms “real-time” processing of children’s emotions
• Alerts on negative emotions via an audio file
Components
a. Main components:
1) Client (Browser UI)
2) Web Server (Flask app in main.py)
3) Video Capture & Inference Module (emotion_recognizer.py using OpenCV + PyTorch)
4) Model Artifacts (attention_autoencoder_emotion_model.pth)
5) Static Assets (alert.mp3)
6) Templates (index.html)
7) Sample Videos (videos/*.mp4) – optional input source
b. Relationships & interactions:
• Browser → HTTP GET “/” → Server serves index.html
• Browser → HTTP GET “/video_feed” → Server streams JPEG frames (yielded by OpenCV capture + inference overlay)
• Server loads .pth model into memory at startup
• For each frame: capture → predict emotion → if negative, flag alert → encode frame → send to browser
• Browser displays MJPEG stream in a <img> or <video> tag; on receiving “alert” flag, plays alert.mp3 from /static
c. Architectural patterns:
• MVC: templates (V), routes in main.py (C), emotion_recognizer + .pth (M)
• Streaming API pattern for video frames
d. Key technologies:
• Python + Flask
• OpenCV for frame capture/processing
• PyTorch for inference
• HTML5 for UI, static MP3 for alert sound
• “Browser UI” (green),
• “Flask Server” (blue),
• “VideoCapture+Inference” (orange),
• “Model File (.pth)” (gray),
• “Static Assets” (audio) & “Templates” (HTML) (purple)
• GET / → index.html
• GET /video_feed → MJPEG stream
• Frame → predict_emotion() → frame+metadata
Next steps
• Lay out the Browser on the left.
• .pth file and sample videos as data sources feeding into Inference Module.
• Static/alert.mp3 and templates/index.html as assets served by the Flask App.