Learto commited on
Commit
93fed63
·
1 Parent(s): 80b81e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -28,10 +28,17 @@ def predict_sentiment(payload):
28
  # sentiment_outputs = requests.post(API_URL, headers=headers, json=payload)
29
  # sentiment_prediction = torch.nn.functional.softmax(sentiment_outputs.logits, dim=-1)
30
 
31
- pos, neg, neutr = sentiment_prediction[:, 0].item(), sentiment_prediction[:, 1].item(), sentiment_prediction[:, 2].item()
 
 
 
 
 
 
 
 
32
  sentiment_label = "Positive" if pos > neg and pos > neutr else "Negative" if neg > pos and neg > neutr else "Neutral"
33
 
34
-
35
  return sentiment_label
36
 
37
 
 
28
  # sentiment_outputs = requests.post(API_URL, headers=headers, json=payload)
29
  # sentiment_prediction = torch.nn.functional.softmax(sentiment_outputs.logits, dim=-1)
30
 
31
+ for sentiment_prediction in response_json:
32
+ if sentiment_prediction['label'] == 'positive':
33
+ pos = sentiment_prediction['score']
34
+ elif sentiment_prediction['label'] == 'neutral':
35
+ neutr = sentiment_prediction.['score']
36
+ elif sentiment_prediction['label'] == 'negative':
37
+ neg = sentiment_prediction['score']
38
+
39
+ # pos, neg, neutr = sentiment_prediction[:, 0].item(), sentiment_prediction[:, 1].item(), sentiment_prediction[:, 2].item()
40
  sentiment_label = "Positive" if pos > neg and pos > neutr else "Negative" if neg > pos and neg > neutr else "Neutral"
41
 
 
42
  return sentiment_label
43
 
44