YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
SubtletyDetector Backend
FastAPI service that classifies facial emotions from a cropped face image.
Quick start (local)
cd backend
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python app.py
# β http://localhost:7860
Endpoints
| Method | Path | Body | Returns |
|---|---|---|---|
| GET | /health |
β | Service & model status |
| GET | /emotions |
β | Canonical 8-emotion list |
| POST | /predict |
multipart/form-data field file=@face.jpg |
8 emotion probabilities |
| POST | /predict_json |
{"image": "data:image/jpeg;base64,..."} |
8 emotion probabilities |
Response shape
{
"emotions": [
{"key": "neutral", "label_en": "neutral", "label_zh": "εΉ³ι", "emoji_mild": "π", "emoji_strong": "π", "probability": 0.12},
...
{"key": "happy", ...}
],
"top_emotion": "happy",
"top_probability": 0.78,
"inference_ms": 142.5
}
Swapping the model
The default is trpakov/vit-face-expression (7-class). To use a 8-class
AffectNet model:
- Set
SUBTLETY_MODEL_ID=your-org/your-modelas an env var, or - Edit
inference.pyβDEFAULT_MODEL_ID - Update
emotions.pyβTRPAKOV_IDX_TO_EMOTIONto match the new model's output order (or replace_remap_to_8()to copy directly)
Deploy to Hugging Face Spaces
- Create a Space with Docker SDK
- Push this
backend/folder to the Space's repo - The Dockerfile will:
- Install deps
- Pre-download the model into the image
- Expose port 7860
Free CPU tier gives 2 vCPU / 16 GB RAM β enough for ~150ms inference per request on a 224Γ224 face crop.
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support