Update app.py
Browse files
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 |
-
|
9 |
-
|
10 |
-
|
11 |
|
12 |
output = query({
|
13 |
"inputs": "I like you. I love you",
|
14 |
})
|
15 |
|
16 |
|
17 |
-
def predict_sentiment(payload):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
|
27 |
|
28 |
-
|
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 |
|