File size: 880 Bytes
27b8b43
93f6be7
27b8b43
93f6be7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import gradio as gr
from transformers import pipeline

# Load the text classification pipeline
pipeline = pipeline("text-classification", model="ProsusAI/finbert", trust_remote_code=True)

def predict(input_text):
    predictions = pipeline(input_text, threshold=0.5, return_scores=True)
    return predictions[0]

# Define the Gradio interface
gradio_app = gr.Interface(
    predict,
    inputs=gr.Textbox(label="Write a text"),
    outputs=gr.Label(label="Predicted Sentiment Probabilities"),
    components=[
        gr.Label(label="Neutral: {:.2f}".format(predictions[0]["score"][0])),
        gr.Label(label="Positive: {:.2f}".format(predictions[0]["score"][1])),
        gr.Label(label="Negative: {:.2f}".format(predictions[0]["score"][2])),
    ],
    title="Financial Sentiment Analysis",
)

# Launch the Gradio interface
if __name__ == "__main__":
    gradio_app.launch()