forked from FarmSystem/TEA-Time-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
33 lines (22 loc) · 768 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from model.emotion_model import EmotionAnalysis
import uvicorn
app = FastAPI()
class DiaryInput(BaseModel):
content: str
class EmotionResponse(BaseModel):
emotion: dict[str, int]
@app.get("/api/health")
def health():
return {"status": "ok"}
@app.post("/api/predict", response_model=EmotionResponse)
def predict(diary: DiaryInput):
try:
emotion_model = EmotionAnalysis()
emotion_result = emotion_model.analyze_emotion(diary.content)
return EmotionResponse(emotion=emotion_result)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=8000)