Spaces:
No application file
No application file
File size: 501 Bytes
5fe8df7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
from fastapi import FastAPI
from pydantic import BaseModel
import joblib
app = FastAPI()
# Load your model once when the server starts
model = joblib.load("./models/emotion_classifier_pipe_lr.pkl")
class TextRequest(BaseModel):
text: str
class PredictionResponse(BaseModel):
emotion: str
@app.post("/predict", response_model=PredictionResponse)
def predict_emotion(req: TextRequest):
prediction = model.predict([req.text])[0]
return {"emotion": prediction}
|