AnkitPatil commited on
Commit
732315d
·
1 Parent(s): c6c30a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py CHANGED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load sentiment analysis pipeline
5
+ classifier = pipeline("sentiment-analysis")
6
+
7
+ # Gradio interface function
8
+ def analyze_sentiment(text):
9
+ result = classifier(text)
10
+ sentiment_label = result[0]['label']
11
+ confidence_score = result[0]['score']
12
+
13
+ return f"Sentiment: {sentiment_label}, Confidence: {confidence_score:.4f}"
14
+
15
+ # Create Gradio interface
16
+ iface = gr.Interface(
17
+ fn=analyze_sentiment,
18
+ inputs=gr.Textbox(),
19
+ outputs=gr.Textbox(),
20
+ live=True,
21
+ interpretation="default",
22
+ title="Sentiment Analysis App",
23
+ description="Enter a text to analyze its sentiment."
24
+ )
25
+
26
+ # Launch the Gradio app
27
+ iface.launch()