import requests | |
import gradio as gr | |
API_URL = "https://api-inference.huggingface.co/models/ProsusAI/finbert" | |
headers = {"Authorization": "Bearer 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"} | |
def query(payload): | |
response = requests.post(API_URL, headers=headers, json=payload) | |
return response.json()[0] | |
output = query({ | |
"inputs": "I like you. I love you", | |
}) | |
# def predict_sentiment(payload): | |
# # Sentiment Analysis | |
# sentiment_inputs = sentiment_tokenizer(headline, padding=True, truncation=True, return_tensors='pt') | |
# with torch.no_grad(): | |
# sentiment_outputs = sentiment_model(**sentiment_inputs) | |
# sentiment_prediction = torch.nn.functional.softmax(sentiment_outputs.logits, dim=-1) | |
# pos, neg, neutr = sentiment_prediction[:, 0].item(), sentiment_prediction[:, 1].item(), sentiment_prediction[:, 2].item() | |
# sentiment_label = "Positive" if pos > neg and pos > neutr else "Negative" if neg > pos and neg > neutr else "Neutral" | |
# return sentiment_label | |
# Gradio Interface | |
iface = gr.Interface( | |
fn=query, | |
inputs=[gr.Textbox(lines=2, label="Financial Statement")], | |
outputs=[ | |
gr.Textbox(label="Sentiment"), | |
], | |
live=True, | |
title="Financial Content Sentiment Analysis", | |
description="Enter a financial statement to analyze its sentiment." | |
) | |
iface.launch() |