JohnJoelMota commited on
Commit
e4e3102
·
verified ·
1 Parent(s): 8370cfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -1,8 +1,6 @@
1
  import gradio as gr
2
- import pandas as pd
3
- import numpy as np
4
- from nltk.sentiment import SentimentIntensityAnalyzer
5
  import nltk
 
6
 
7
  # Download VADER lexicon
8
  nltk.download('vader_lexicon', quiet=True)
@@ -12,9 +10,10 @@ def perform_sentiment_analysis(text):
12
  return sia.polarity_scores(text)
13
 
14
  def categorize_sentiment(compound_score):
15
- if compound_score >= 0.05:
 
16
  return 'Positive'
17
- elif compound_score <= -0.05:
18
  return 'Negative'
19
  else:
20
  return 'Neutral'
@@ -24,12 +23,25 @@ def analyze_sentiment(input_text):
24
  sentiment = categorize_sentiment(scores['compound'])
25
  return {"Sentiment": sentiment, "Scores": scores}
26
 
 
 
 
 
 
 
 
 
 
 
27
  demo = gr.Interface(
28
  fn=analyze_sentiment,
29
- inputs=gr.Textbox(label="Enter text for sentiment analysis"),
30
  outputs="json",
31
  title="Sentiment Analysis Tool using Reddit Data",
32
- description="Analyze sentiment of text using Reddit data."
 
 
 
33
  )
34
 
35
  demo.launch()
 
1
  import gradio as gr
 
 
 
2
  import nltk
3
+ from nltk.sentiment import SentimentIntensityAnalyzer
4
 
5
  # Download VADER lexicon
6
  nltk.download('vader_lexicon', quiet=True)
 
10
  return sia.polarity_scores(text)
11
 
12
  def categorize_sentiment(compound_score):
13
+ # Adjusting thresholds for a more balanced classification
14
+ if compound_score > 0.1: # Increased positive threshold
15
  return 'Positive'
16
+ elif compound_score < -0.1: # Increased negative threshold
17
  return 'Negative'
18
  else:
19
  return 'Neutral'
 
23
  sentiment = categorize_sentiment(scores['compound'])
24
  return {"Sentiment": sentiment, "Scores": scores}
25
 
26
+ # Example Reddit posts for sentiment analysis
27
+ examples = [
28
+ "Just got a new job and I'm so excited! The team seems great and the work looks interesting.", # Positive
29
+ "I really enjoyed the last movie I watched; it was captivating and well-made.", # Positive
30
+ "I'm really frustrated with how the job market is right now. It's so unfair.", # Negative
31
+ "I hate Data structures.", # Negative
32
+ "The meeting was informative, but it felt a bit long.", # Neutral
33
+ "Hey John, did you finish your intro to Machine Learning textbook?", # Neutral
34
+ ]
35
+
36
  demo = gr.Interface(
37
  fn=analyze_sentiment,
38
+ inputs=gr.Textbox(label="Enter text for sentiment analysis", placeholder="Type your text here..."),
39
  outputs="json",
40
  title="Sentiment Analysis Tool using Reddit Data",
41
+ description=(
42
+ "Enter text to see the sentiment analysis result. You can also use the examples below to test different sentiments."
43
+ ),
44
+ examples=examples # Add the Reddit examples here
45
  )
46
 
47
  demo.launch()