Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -99,14 +99,18 @@ async def predict_sentiment(input_data: TextAspectInput):
|
|
99 |
|
100 |
# Process input
|
101 |
input_ids = process_text(text, aspect)
|
|
|
102 |
|
103 |
# Make prediction
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
110 |
return {"sentiment": sentiment, "probabilities": probabilities.squeeze().tolist()}
|
111 |
except Exception as e:
|
112 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
99 |
|
100 |
# Process input
|
101 |
input_ids = process_text(text, aspect)
|
102 |
+
print("Process text: ", input_ids)
|
103 |
|
104 |
# Make prediction
|
105 |
+
try:
|
106 |
+
with torch.no_grad():
|
107 |
+
logits = model(input_ids)
|
108 |
+
probabilities = torch.softmax(logits, dim=-1)
|
109 |
+
prediction = probabilities.argmax(dim=-1).item()
|
110 |
+
sentiment = SENTIMENT_LABELS[prediction]
|
111 |
+
except Exception as e:
|
112 |
+
print(e)
|
113 |
+
|
114 |
return {"sentiment": sentiment, "probabilities": probabilities.squeeze().tolist()}
|
115 |
except Exception as e:
|
116 |
raise HTTPException(status_code=500, detail=str(e))
|