FastAPI service that detects emotions from face images using the ONNX FER+ model. Dockerized for easy deployment.
uv sync
uv run python -m detect_emotion_service- Health:
GET http://localhost:8080/health - Detect:
POST http://localhost:8080/detectwithmultipart/form-datafieldfile(image file)- Or
POST /detect-byteswithapplication/octet-streambody - Or
POST /detect-jsonwith JSON:{ "file_path": "/abs/path.jpg" }or{ "bytes_base64": "<base64>" }
- Or
Example curl:
curl -s -X POST \
-F "file=@/path/to/face.jpg" \
http://localhost:8080/detect | jqRaw bytes example:
curl -s -X POST \
-H "Content-Type: application/octet-stream" \
--data-binary @/path/to/face.jpg \
http://localhost:8080/detect-bytes | jqJSON file path example:
curl -s -X POST \
-H "Content-Type: application/json" \
-d '{"file_path":"/absolute/path/to/face.jpg"}' \
http://localhost:8080/detect-json | jqBuild and run:
docker build -t emotion-api .
docker run --rm -p 8080:8080 emotion-apiEnsure the model exists at models/emotion-ferplus-8.onnx, then:
docker compose up --buildThis will mount ./models read-only into the container at /app/models and expose port 8080.
- Place
emotion-ferplus-8.onnxin the repo root ormodels/(or setMODEL_PATH). Docker image copies it to/app/models. - If no face is detected, the whole image is classified as a fallback.