SHIROI-07 commited on
Commit
582d4d4
·
verified ·
1 Parent(s): 010ed04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -22
app.py CHANGED
@@ -1,28 +1,21 @@
1
  #Emotion Detection API using FastAPI
2
- from fastapi import FastAPI, HTTPException
3
- from pydantic import BaseModel
4
- from model import predict_emotions, calculate_distress
5
 
6
- app = FastAPI()
7
 
8
- class TextInput(BaseModel):
9
- text: str
 
 
10
 
11
- @app.post("/analyze")
12
- async def analyze(input: TextInput):
13
- try:
14
- emotions = predict_emotions(input.text)
15
- distress_score = calculate_distress(emotions)
16
 
17
- return {
18
- "text": input.text,
19
- "emotions": emotions,
20
- "distress_score": distress_score,
21
- "warning": distress_score > 1.5 # Trigger warning if score high
22
- }
23
- except Exception as e:
24
- raise HTTPException(status_code=500, detail=str(e))
25
 
26
- @app.get("/")
27
- def root():
28
- return {"message": "Emotion detector is live"}
 
1
  #Emotion Detection API using FastAPI
2
+ import gradio as gr
3
+ from model import EmotionModel
4
+ from utils import calculate_distress
5
 
6
+ emotion_model = EmotionModel()
7
 
8
+ def analyze(text):
9
+ emotions = emotion_model.predict(text)
10
+ distress = calculate_distress(emotions)
11
+ return {"emotions": emotions, "distress_score": distress}
12
 
 
 
 
 
 
13
 
14
+ app = gr.Interface(
15
+ fn=analyze,
16
+ inputs=gr.Textbox(),
17
+ outputs="json"
18
+ )
19
+ # Launch the app
20
+ app.launch()
 
21