File size: 862 Bytes
b127cc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import gradio as gr
from transformers import pipeline

# Load the models
model1 = pipeline("sentiment-analysis", model="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis")
model2 = pipeline("sentiment-analysis", model="mr8488/distilroberta-finetuned-financial-news-sentiment-analysis")

# Define the function to generate responses
def analyze_sentiment(input_text):
    result1 = model1(input_text)[0]
    result2 = model2(input_text)[0]
    return {"mrm8488": f"{result1['label']} ({result1['score']:.2f})",
            "mr8488": f"{result2['label']} ({result2['score']:.2f})"}

# Create the Gradio interface
iface = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="text", title="Financial Sentiment Analysis", description="Enter a sentence to analyze its sentiment using two different models.")

# Launch the interface
iface.launch()