Skip to content

alzyras/emotion_detection_api

Repository files navigation

Emotion Detection API

FastAPI service that detects emotions from face images using the ONNX FER+ model. Dockerized for easy deployment.

Run locally

uv sync
uv run python -m detect_emotion_service
  • Health: GET http://localhost:8080/health
  • Detect: POST http://localhost:8080/detect with multipart/form-data field file (image file)
    • Or POST /detect-bytes with application/octet-stream body
    • Or POST /detect-json with JSON: { "file_path": "/abs/path.jpg" } or { "bytes_base64": "<base64>" }

Example curl:

curl -s -X POST \
  -F "file=@/path/to/face.jpg" \
  http://localhost:8080/detect | jq

Raw bytes example:

curl -s -X POST \
  -H "Content-Type: application/octet-stream" \
  --data-binary @/path/to/face.jpg \
  http://localhost:8080/detect-bytes | jq

JSON 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 | jq

Docker

Build and run:

docker build -t emotion-api .
docker run --rm -p 8080:8080 emotion-api

Docker Compose

Ensure the model exists at models/emotion-ferplus-8.onnx, then:

docker compose up --build

This will mount ./models read-only into the container at /app/models and expose port 8080.

Notes

  • Place emotion-ferplus-8.onnx in the repo root or models/ (or set MODEL_PATH). Docker image copies it to /app/models.
  • If no face is detected, the whole image is classified as a fallback.

https://huggingface.co/webml/models-moved/blob/0e73dc31942fbdbbd135d85be5e5321eee88a826/emotion-ferplus-8.onnx

About

API for detecting human emotion from face photographs.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published