Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,21 @@
|
|
1 |
#Emotion Detection API using FastAPI
|
2 |
-
|
3 |
-
from
|
4 |
-
from
|
5 |
|
6 |
-
|
7 |
|
8 |
-
|
9 |
-
text
|
|
|
|
|
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 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
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 |
|
|
|
|
|
|