Quickstart Guide
Get EmoChat emotion recognition AI running in just a few steps. This guide will take you from installation to your first real-time emotion detection session.Prerequisites
Before starting, ensure you have:- Python 3.8 or higher installed
- A webcam or camera device
- Basic familiarity with command line
- Windows, macOS, or Linux operating system
Quick Start Steps
Install Dependencies
Clone the repository and install required Python packages:The key dependencies include:
- Flask 3.1.3 - Web server
- opencv-contrib-python 4.13.0.92 - Computer vision
- scikit-learn 1.8.0 - Machine learning
- numpy 2.4.2 - Numerical computing
Prepare Training Data
Create a data directory with emotion folders:Add training images to each folder:This creates
- Place happy facial expression images in
../data/happy/ - Place sad facial expression images in
../data/sad/
data.txt with normalized facial landmarks for each image.Train the Model
Train the Random Forest classifier:You’ll see output like:The model is saved as the
model file in your project directory.Training typically takes 10-30 seconds depending on your dataset size. Aim for accuracy above 80% for reliable predictions.
Launch Flask Server
Start the web application server:You should see:
The server is now running and ready to process webcam frames!
Access Web Interface
Open your web browser and navigate to:You’ll see the EmoChat web interface with:
- Activate Camera button to enable your webcam
- Real-time emotion detection display
- Session recording controls
- Context input for AI analysis
Use Real-Time Emotion Recognition
In the web interface:
- Click Activate Camera to start your webcam
- Grant camera permissions when prompted
- Your emotion will be detected and displayed in real-time
- See “HAPPY” or “SAD” based on your facial expression
- Enter a context in the text field (e.g., “Talking about my day”)
- Click Start Recording (30s)
- Express yourself for 30 seconds
- Get empathetic AI feedback from Google Gemini
Optional: Configure Gemini AI
To enable AI-powered emotional analysis:Or use an environment variable:
- Get a Google Gemini API key from Google AI Studio
-
Set the API key in
app.py:
app.py
What’s Next?
Installation Details
Learn about system requirements, troubleshooting, and advanced setup
API Reference
Explore the Flask API endpoints and integrate with your own applications
Model Training
Deep dive into the machine learning pipeline and improve accuracy
Web Application
Learn about the Flask server and frontend integration
Troubleshooting
Camera Access Denied
Camera Access Denied
If the browser denies camera access:
- Click the camera icon in the address bar
- Allow camera permissions for localhost
- Refresh the page and try again
- Make sure no other application is using the camera
'No module named cv2.face' Error
'No module named cv2.face' Error
This means
opencv-contrib-python is not installed:Model File Not Found
Model File Not Found
If you see “No se encontró el modelo entrenado”:
- Make sure you ran
train_model.pysuccessfully - Check that the
modelfile exists in your project directory - Verify the training completed without errors
Low Accuracy Predictions
Low Accuracy Predictions
If emotions are detected incorrectly:
- Ensure good lighting on your face
- Face the camera directly
- Use more diverse training images
- Retrain with a larger dataset (100+ images per emotion)
- Check that training accuracy was above 80%
Understanding the Detection Flow
Here’s what happens when you use EmoChat:- Webcam Capture: JavaScript captures frames from your webcam every second
- Base64 Encoding: Images are encoded and sent to the Flask server via
/predict - Face Detection: OpenCV Haar Cascade detects faces in the image
- Landmark Extraction: 68 facial landmark points are identified using LBF model
- Normalization: Coordinates are normalized relative to face boundaries
- ML Prediction: Random Forest classifier predicts emotion (0=Happy, 1=Sad)
- Real-time Display: Emotion is shown in the web interface
Advanced Usage
Testing Without Web Interface
Test the model directly with your webcam:q to quit the OpenCV window.
Session Analysis
The session recording feature:- Captures emotions every second for 30 seconds
- Sends the emotion sequence to Google Gemini AI
- Receives empathetic feedback based on patterns
- Helps understand emotional fluctuations over time
All facial data is processed locally and never stored. Session analysis only sends emotion labels (not images) to Gemini AI.
Next Steps
Now that you have EmoChat running, explore:- Core Concepts - Learn how emotion recognition works
- Training Guide - Improve your model with better data
- API Reference - Integrate EmoChat into your applications
- Web Application - Customize the web interface

