jeffrey1963 commited on
Commit
7b38ef8
·
verified ·
1 Parent(s): 9b92341

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load sentiment analysis pipeline
5
+ sentiment_classifier = pipeline("sentiment-analysis")
6
+
7
+ def analyze_sentiment(text):
8
+ result = sentiment_classifier(text)[0]
9
+ label = result['label']
10
+ score = result['score']
11
+ percent = f"{score * 100:.2f}%"
12
+ return f"{label} ({percent})"
13
+
14
+ iface = gr.Interface(
15
+ fn=analyze_sentiment,
16
+ inputs="text",
17
+ outputs="text",
18
+ title="Simple Sentiment Analyzer",
19
+ description="Enter a sentence and receive its sentiment classification (Positive, Negative, or Neutral)."
20
+ )
21
+
22
+ iface.launch()