ragilbuaj commited on
Commit
a5cd817
·
1 Parent(s): b235003
Files changed (1) hide show
  1. app.py +6 -1
app.py CHANGED
@@ -31,7 +31,12 @@ def predict_sentiment(text):
31
  scores = outputs.logits[0].detach().numpy()
32
  predictions = torch.nn.functional.softmax(torch.tensor(scores), dim=0)
33
  sentiment = torch.argmax(predictions).item()
34
- return sentiment, predictions[sentiment].item()
 
 
 
 
 
35
 
36
  # Endpoint untuk analisis sentimen
37
  @app.post("/predict")
 
31
  scores = outputs.logits[0].detach().numpy()
32
  predictions = torch.nn.functional.softmax(torch.tensor(scores), dim=0)
33
  sentiment = torch.argmax(predictions).item()
34
+
35
+ # Map sentiment to label
36
+ labels = ["positive", "negative", "neutral"]
37
+ sentiment_label = labels[sentiment]
38
+
39
+ return sentiment_label, predictions[sentiment].item()
40
 
41
  # Endpoint untuk analisis sentimen
42
  @app.post("/predict")