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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -15
app.py CHANGED
@@ -5,33 +5,40 @@ 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()['label']
 
 
 
 
 
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
 
32
  # Gradio Interface
33
  iface = gr.Interface(
34
- fn=query,
35
  inputs=[gr.Textbox(lines=2, label="Financial Statement")],
36
  outputs=[
37
  gr.Textbox(label="Sentiment"),
 
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
+ # sentiment_prediction = response.json()
11
+
12
+ # pos, neg, neutr = sentiment_prediction[:, 0].item(), sentiment_prediction[:, 1].item(), sentiment_prediction[:, 2].item()
13
+ # sentiment_label = "Positive" if pos > neg and pos > neutr else "Negative" if neg > pos and neg > neutr else "Neutral"
14
+
15
+ # return sentiment_label
16
 
17
+ # output = query({
18
+ # "inputs": "I like you. I love you",
19
+ # })
20
 
21
 
22
+ def predict_sentiment(payload):
23
+ # Sentiment Analysis
24
+ response = requests.post(API_URL, headers=headers, json=payload)
25
+ sentiment_prediction = response.json()
26
 
27
+ # with torch.no_grad():
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
 
38
 
39
  # Gradio Interface
40
  iface = gr.Interface(
41
+ fn=predict_sentiment,
42
  inputs=[gr.Textbox(lines=2, label="Financial Statement")],
43
  outputs=[
44
  gr.Textbox(label="Sentiment"),