Learto commited on
Commit
278eba4
·
1 Parent(s): e744050

Update app.py

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