|
import requests |
|
import urllib.parse |
|
import gradio as gr |
|
|
|
API_URL = "https://api-inference.huggingface.co/models/ProsusAI/finbert" |
|
headers = {"Authorization": "Bearer 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"} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def predict_sentiment(payload): |
|
|
|
response = requests.post(API_URL, headers=headers, json=payload) |
|
sentiment_prediction = response.json() |
|
|
|
|
|
|
|
|
|
|
|
for sentiment_prediction in response_json: |
|
if sentiment_prediction['label'] == 'positive': |
|
pos = sentiment_prediction['score'] |
|
elif sentiment_prediction['label'] == 'neutral': |
|
neutr = sentiment_prediction['score'] |
|
elif sentiment_prediction['label'] == 'negative': |
|
neg = sentiment_prediction['score'] |
|
|
|
|
|
sentiment_label = "Positive" if pos > neg and pos > neutr else "Negative" if neg > pos and neg > neutr else "Neutral" |
|
|
|
return sentiment_label |
|
|
|
|
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_sentiment, |
|
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() |