saira-projects commited on
Commit
ef18eae
·
verified ·
1 Parent(s): 606b728

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load sentiment analysis model
5
+ sentiment = pipeline("sentiment-analysis")
6
+
7
+ # Function to analyze text
8
+ def analyze_sentiment(text):
9
+ if not text.strip():
10
+ return "Please enter some text!"
11
+ result = sentiment(text)[0]
12
+ return f"Label: {result['label']}, Score: {round(result['score'], 2)}"
13
+
14
+ # Gradio interface
15
+ iface = gr.Interface(
16
+ fn=analyze_sentiment,
17
+ inputs=gr.Textbox(lines=5, placeholder="Type your text here..."),
18
+ outputs="text",
19
+ title="😊 Sentiment Analyzer",
20
+ description="Type any text and see if it is Positive, Negative, or Neutral!"
21
+ )
22
+
23
+ iface.launch()