guychuk commited on
Commit
94a3781
1 Parent(s): 8071298

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the models
5
+ model1 = pipeline("sentiment-analysis", model="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis")
6
+ model2 = pipeline("sentiment-analysis", model="mr8488/distilroberta-finetuned-financial-news-sentiment-analysis")
7
+
8
+ # Define the function to generate responses
9
+ def analyze_sentiment(input_text):
10
+ result1 = model1(input_text)[0]
11
+ result2 = model2(input_text)[0]
12
+ return {"Model 1": f"{result1['label']} ({result1['score']:.2f})",
13
+ "Model 2": f"{result2['label']} ({result2['score']:.2f})"}
14
+
15
+ # Create the Gradio interface
16
+ iface = gr.Interface(
17
+ fn=analyze_sentiment,
18
+ inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
19
+ outputs=[gr.outputs.Textbox(label="mrm"), gr.outputs.Textbox(label="mr")],
20
+ title="Financial News Sentiment Analysis Models Comparison",
21
+ description="Compare sentiment analysis results of two models."
22
+ )
23
+
24
+ # Launch the interface
25
+ iface.launch()