Learto commited on
Commit
b173edb
·
1 Parent(s): 1cf29b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -5,27 +5,27 @@ import gradio as gr
5
  API_URL = "https://api-inference.huggingface.co/models/ProsusAI/finbert"
6
  headers = {"Authorization": "Bearer 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"}
7
 
8
- # def query(payload):
9
- # response = requests.post(API_URL, headers=headers, json=payload)
10
- # return response.json()[0]
11
 
12
  output = query({
13
  "inputs": "I like you. I love you",
14
  })
15
 
16
 
17
- def predict_sentiment(payload):
18
- # Sentiment Analysis
19
- # sentiment_inputs = sentiment_tokenizer(headline, padding=True, truncation=True, return_tensors='pt')
20
- with torch.no_grad():
21
- sentiment_outputs = requests.post(API_URL, headers=headers, json=payload)
22
- sentiment_prediction = torch.nn.functional.softmax(sentiment_outputs.logits, dim=-1)
23
 
24
- pos, neg, neutr = sentiment_prediction[:, 0].item(), sentiment_prediction[:, 1].item(), sentiment_prediction[:, 2].item()
25
- sentiment_label = "Positive" if pos > neg and pos > neutr else "Negative" if neg > pos and neg > neutr else "Neutral"
26
 
27
 
28
- return sentiment_label
29
 
30
 
31
 
 
5
  API_URL = "https://api-inference.huggingface.co/models/ProsusAI/finbert"
6
  headers = {"Authorization": "Bearer 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"}
7
 
8
+ def query(payload):
9
+ response = requests.post(API_URL, headers=headers, text=payload)
10
+ return response.text()
11
 
12
  output = query({
13
  "inputs": "I like you. I love you",
14
  })
15
 
16
 
17
+ # def predict_sentiment(payload):
18
+ # # Sentiment Analysis
19
+
20
+ # with torch.no_grad():
21
+ # sentiment_outputs = requests.post(API_URL, headers=headers, json=payload)
22
+ # sentiment_prediction = torch.nn.functional.softmax(sentiment_outputs.logits, dim=-1)
23
 
24
+ # pos, neg, neutr = sentiment_prediction[:, 0].item(), sentiment_prediction[:, 1].item(), sentiment_prediction[:, 2].item()
25
+ # sentiment_label = "Positive" if pos > neg and pos > neutr else "Negative" if neg > pos and neg > neutr else "Neutral"
26
 
27
 
28
+ # return sentiment_label
29
 
30
 
31