yk07577 commited on
Commit
989ca35
·
verified ·
1 Parent(s): e76addd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the sentiment analysis model from Hugging Face
5
+ sentiment_analyzer = pipeline("sentiment-analysis")
6
+
7
+ # Define a function that will analyze sentiment
8
+ def analyze_sentiment(text):
9
+ result = sentiment_analyzer(text)
10
+ return result[0]['label'], result[0]['score']
11
+
12
+ # Create a Gradio interface for the sentiment analysis function
13
+ iface = gr.Interface(
14
+ fn=analyze_sentiment,
15
+ inputs=gr.Textbox(label="Enter text for sentiment analysis"),
16
+ outputs=[gr.Textbox(label="Sentiment Label"), gr.Textbox(label="Confidence Score")],
17
+ live=True
18
+ )
19
+
20
+ # Launch the interface
21
+ iface.launch()