cyrus-spc commited on
Commit
a96458b
Β·
verified Β·
1 Parent(s): f507699

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -1,23 +1,21 @@
1
  import gradio as gr
2
- from textblob import TextBlob
 
 
 
3
 
4
  def analyze_sentiment(text):
5
- blob = TextBlob(text)
6
- polarity = blob.sentiment.polarity
7
- if polarity > 0:
8
- sentiment = "Positive πŸ˜€"
9
- elif polarity < 0:
10
- sentiment = "Negative 😞"
11
- else:
12
- sentiment = "Neutral 😐"
13
- return f"Sentiment: {sentiment}\nPolarity Score: {polarity:.2f}"
14
 
15
  iface = gr.Interface(
16
  fn=analyze_sentiment,
17
- inputs=gr.Textbox(lines=3, placeholder="Enter text here..."),
18
  outputs="text",
19
  title="Sentiment Analysis",
20
- description="Enter text to analyze its sentiment (positive, negative, or neutral)."
21
  )
22
 
23
  if __name__ == "__main__":
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load 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
+ return f"Sentiment: {label} (confidence: {score:.2f})"
 
 
 
 
 
12
 
13
  iface = gr.Interface(
14
  fn=analyze_sentiment,
15
+ inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
16
  outputs="text",
17
  title="Sentiment Analysis",
18
+ description="Enter text to analyze its sentiment (positive/negative)."
19
  )
20
 
21
  if __name__ == "__main__":