Spaces:
Runtime error
Runtime error
Download app/main.py from AkhilJoshi/EmotionDetection: direct link, hf CLI and curl.
- Browser
- Download file 711 Bytes
-
https://huggingface.co/spaces/AkhilJoshi/EmotionDetection/resolve/main/app/main.py
- Command line
-
hf download hf://spaces/AkhilJoshi/EmotionDetection/app/main.py
-
curl -L -o main.py https://huggingface.co/spaces/AkhilJoshi/EmotionDetection/resolve/main/app/main.py
711 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from typing import List | |
| from .onnx_inference import EmotionClassifierONNX | |
| # Load the classifier on startup | |
| classifier = EmotionClassifierONNX( | |
| model_path="app/emotion_model.onnx", | |
| label_encoder_path="app/label_encoder.pkl" | |
| ) | |
| # Define request body | |
| class TextRequest(BaseModel): | |
| texts: List[str] | |
| app = FastAPI(title="Emotion Classifier API") | |
| def home(): | |
| return {"message": "Emotion classifier is up and running!"} | |
| def predict_emotions(request: TextRequest): | |
| labels = classifier.predict(request.texts) | |
| return {"predictions": labels.tolist() if hasattr(labels, 'tolist') else list(labels)} | |