MagicMeWizard commited on
Commit
5bc2648
·
verified ·
1 Parent(s): f8c25a3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the sentiment analysis pipeline
5
+ sentiment_pipeline = pipeline("sentiment-analysis")
6
+
7
+ def analyze_sentiment(text):
8
+ result = sentiment_pipeline(text)[0]
9
+ label = result['label']
10
+ score = result['score']
11
+
12
+ if label == 'POSITIVE':
13
+ emotion = "positive"
14
+ elif label == 'NEGATIVE':
15
+ emotion = "negative"
16
+ else:
17
+ emotion = "neutral"
18
+
19
+ return f"Emotion: {emotion}\nConfidence: {score:.2f}"
20
+
21
+ # Create the Gradio interface
22
+ iface = gr.Interface(
23
+ fn=analyze_sentiment,
24
+ inputs=gr.Textbox(lines=5, placeholder="Enter your text here..."),
25
+ outputs="text",
26
+ title="Emotion Analysis",
27
+ description="Analyze the sentiment of your text using Hugging Face Transformers."
28
+ )
29
+
30
+ # Launch the app
31
+ iface.launch()