Real-time facial expression analysis powered by DeepFace CNNs.
Upload a portrait or stream your webcam โ get instant emotion scores, face-bounding boxes, and contextual insights.
| Feature | Details |
|---|---|
| ๐ค Image Upload | Analyze any JPG/PNG/WebP portrait. Bounding box + emotion scores returned instantly. |
| ๐ท Live Webcam | Frame-by-frame real-time analysis every ~800 ms via your browser camera. |
| ๐ 4-Class Emotion Detection | Joy ยท Sadness ยท Anger ยท Neutral with percentage confidence scores. |
| ๐ฏ Face Bounding Box | Detected face is highlighted with a dynamic overlay that scales proportionally. |
| ๐ Confidence Ring | Animated radial progress ring for dominant emotion confidence. |
| ๐ก Contextual Insights | Personality-driven tips per detected emotion state. |
| โก Hot Reload Dev | Vite HMR frontend + Uvicorn backend, both run concurrently during development. |
The interface is a 3-column dark dashboard:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐ EmotionAI โ DeepFace ยท Live โ โ Top Bar
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโค
โ INPUT MODE โ โ NEURAL OUTPUTโ
โ โ Canvas / Viewport โ โ
โ ๐ค Upload โ (drop zone or โ Emotion โ
โ ๐ท Webcam โ webcam feed) โ Analysis โ
โ โ โ โ
โ EMOTION โ โ Confidence โ
โ PALETTE โ โ Ring + Bars โ
โ โข Joy โ โ + Insight โ
โ โข Sadness โ โ โ
โ โข Anger โ โ โ
โ โข Neutral โ โ โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโ
Design System:
- Fonts: Syne (headings) + Space Grotesk (body)
- Palette: Warm orange accent (
#FF6B35), emotion-coded colors (Joy = amber, Sadness = blue, Anger = red, Neutral = slate) - Animations: Framer Motion transitions, floating emoji idle states, springy bar reveals
EmotionAI/
โ
โโโ emotion.py โ Python FastAPI backend (port 8000)
โโโ requirements.txt โ Python dependencies
โ
โโโ frontend/ โ React + Vite frontend (port 5173)
โโโ index.html
โโโ vite.config.js
โโโ package.json
โโโ src/
โโโ main.jsx โ React entry point
โโโ index.css โ Global reset + Google Fonts import
โโโ App.jsx โ Main app component (all UI + logic)
โโโ App.css โ Full design system & layout styles
Browser (React)
โ
โ POST /analyze (image upload โ multipart/form-data)
โ POST /analyze-frame (webcam frame โ base64 JSON)
โผ
FastAPI Backend (emotion.py)
โ
โ cv2.imdecode() โ numpy array
โ DeepFace.analyze() โ raw emotion dict + face region
โ safe_float/safe_int() โ serialization guard
โผ
JSON Response
{
"emotions": [
{ "label": "Joy", "score": 87.4 },
{ "label": "Neutral", "score": 8.1 },
{ "label": "Sadness", "score": 3.1 },
{ "label": "Anger", "score": 1.4 }
],
"region": { "x": 110, "y": 45, "w": 220, "h": 280 },
"image_width": 640,
"image_height": 480
}
| Package | Purpose |
|---|---|
| FastAPI | REST API framework |
| Uvicorn | ASGI server |
| DeepFace | CNN-based facial emotion analysis |
OpenCV (cv2) |
Image decoding from bytes/base64 |
| NumPy | Array handling for image data |
| TensorFlow / Keras | DeepFace model runtime |
| Package | Purpose |
|---|---|
| React 19 | UI component framework |
| Vite 8 | Dev server + bundler with HMR |
| Framer Motion | Smooth animations & transitions |
| react-webcam | Webcam access & frame capture |
| lucide-react | Icon set |
- Python 3.10+ with pip
- Node.js 18+ with npm
- A webcam (optional, for live mode)
git clone https://github.com/your-username/EmotionAI.git
cd EmotionAI# Install all Python dependencies
pip install -r requirements.txt
โ ๏ธ Note: This installs TensorFlow + DeepFace which are large (~2 GB). First run will also auto-download the DeepFace model weights.
# Start the backend server
python emotion.pyBackend will be live at โ http://localhost:8000
cd frontend
# Install Node dependencies
npm install --legacy-peer-deps
# Start the dev server
npm run devFrontend will be live at โ http://localhost:5173
Navigate to http://localhost:5173 in your browser.
Base URL: http://localhost:8000
Analyze an uploaded image file.
Request: multipart/form-data
| Field | Type | Description |
|---|---|---|
file |
UploadFile |
Image file (JPG, PNG, WebP) |
Response:
{
"emotions": [
{ "label": "Joy", "score": 87.4 },
{ "label": "Neutral", "score": 8.1 },
{ "label": "Sadness", "score": 3.1 },
{ "label": "Anger", "score": 1.4 }
],
"region": { "x": 110, "y": 45, "w": 220, "h": 280 },
"image_width": 640,
"image_height": 480
}Analyze a base64-encoded webcam frame (used for live mode).
Request: application/json
{
"image": "data:image/jpeg;base64,/9j/4AAQSkZJRgAB..."
}Response: Same structure as /analyze.
Error response (non-500):
{ "error": "Awaiting clear webcam frame..." }The backend always returns HTTP 200 with an
errorkey rather than throwing 500s โ this keeps the React frontend resilient during webcam startup.
Inside emotion.py, the process_frame() function:
- Guards against empty frames โ returns a soft error if the image is null or zero-size (common during webcam init).
- Calls
DeepFace.analyze()with:actions=["emotion"]โ only emotion analysis, skipping age/gender/race for speed.enforce_detection=Falseโ allows analysis even if no face is confidently detected.silent=Trueโ suppresses verbose TF logs.
- Extracts & remaps raw emotion keys (
happy,sad,angry,neutral) into labeled objects. - Casts all NumPy types to plain Python
float/intviasafe_float()/safe_int()to avoid JSON serialization errors. - Sorts emotions by score descending so the dominant emotion is always
emotions[0]. - Returns face region in absolute pixel coordinates โ the frontend converts these to percentages for responsive overlay rendering.
- Click "Upload Image" in the sidebar (or it's selected by default).
- Click "Choose File" or click anywhere in the drop zone.
- Select a portrait photo โ DeepFace processes it and the results appear within 1โ3 seconds.
- A golden bounding box appears around the detected face with the dominant emotion label.
- The right panel shows the dominant emotion card with a confidence ring + full spectrum bars.
- Click โ to clear and try another image.
- Click "Live Webcam" in the sidebar.
- Allow browser camera permissions if prompted.
- Click "โถ Start Scan" โ the app begins analyzing your face every 800 ms.
- Watch the emotion bars animate in real-time as your expression changes.
- Click "โน Stop Scan" to pause analysis.
App.jsx
โ
โโโ <ConfidenceRing /> โ SVG radial ring showing % confidence
โ
โโโ Shell Layout
โ โโโ <header.topbar> โ Brand logo + DeepFace live badge
โ โ
โ โโโ <aside.sidebar> โ Mode selector + emotion palette legend
โ โ
โ โโโ <div.main>
โ โ
โ โโโ <div.canvas-area> โ Left: viewport + header + status chip
โ โ โโโ <div.dropzone> โ Upload idle state
โ โ โโโ <img.preview> โ Uploaded image + bounding box
โ โ โโโ <Webcam> โ Live webcam feed + scan button
โ โ
โ โโโ <div.analysis-panel> โ Right: results panel
โ โโโ <div.dominant-card> โ Top emotion + ring
โ โโโ <div.spectrum-section> โ Animated bar rows
โ โโโ <div.tip-card> โ Contextual insight message
| Issue | Fix Applied |
|---|---|
deepface not installed |
Run pip install -r requirements.txt |
lucide-react missing in frontend |
Install with npm install lucide-react --legacy-peer-deps |
Vite PostCSS crash (<<<<<<< HEAD) |
Resolved git merge conflict markers in root package.json and package-lock.json |
| NumPy serialization โ HTTP 500 | safe_float() / safe_int() helpers wrap all DeepFace output values |
| Empty webcam frames on startup | process_frame() returns {"error": "..."} instead of crashing |
cd frontend
npm run build
# Output in frontend/dist/pip install gunicorn
gunicorn emotion:app -w 2 -k uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000MIT License โ see LICENSE for details.
Built with โค๏ธ using DeepFace, FastAPI & React