A Flask-based REST API for detecting faces in images and predicting their emotions using machine learning models.
- Face detection using MTCNN (Multi-task Cascaded Convolutional Networks)
- Emotion recognition with EmotiEffLib models
- RESTful API with JSON responses
- Base64-encoded face images in responses
- CORS support for web applications
- Automatic cleanup of uploaded files
- Python 3.9 or higher
- UV package manager (recommended)
-
Clone or navigate to the project directory:
cd server -
Install dependencies using pip:
pip install -r requirements.txt
Start the Flask development server:
python app.pyThe server will run on http://localhost:5000.
Analyzes an uploaded image for faces and predicts emotions.
Request:
- Method:
POST - Content-Type:
multipart/form-data - Body:
image(file) - Image file (JPEG, PNG)
Response (200 OK):
{
"results": [
{
"emotion": "happy",
"face_image": "base64encodedstring..."
}
]
}Error Response (400 Bad Request):
{
"error": "No image file provided"
}server/
├── app.py # Flask application
├── model.py # Face detection and emotion recognition logic
├── pyproject.toml # Project configuration and dependencies
├── README.md # This file
└── uploads/ # Temporary upload directory (auto-created)- Flask: Web framework
- EmotiEffLib: Emotion recognition library
- Facenet-Pytorch: Face detection
- OpenCV: Image processing
- Pillow: Image handling
- Flask-CORS: Cross-origin resource sharing