vibha-mah commited on
Commit
0cf6beb
·
1 Parent(s): 172e877

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import nltk
3
+ from nltk.sentiment.vader import SentimentIntensityAnalyzer
4
+
5
+ # Download required NLTK resources
6
+ nltk.download('vader_lexicon')
7
+
8
+ # Load the pre-trained sentiment intensity analyzer
9
+ sia = SentimentIntensityAnalyzer()
10
+
11
+ def get_sentiment(tweet):
12
+ # Preprocess the tweet
13
+ processed_tweet = preprocess([tweet])
14
+
15
+ # Get the sentiment score using VADER sentiment analyzer
16
+ sentiment_score = sia.polarity_scores(processed_tweet[0])
17
+
18
+ # Determine the sentiment label based on the compound score
19
+ compound_score = sentiment_score['compound']
20
+ if compound_score >= 0.05:
21
+ sentiment = 'Positive'
22
+ elif compound_score <= -0.05:
23
+ sentiment = 'Negative'
24
+ else:
25
+ sentiment = 'Neutral'
26
+
27
+ return sentiment
28
+
29
+ # Create a Gradio interface
30
+ iface = gr.Interface(
31
+ fn=get_sentiment,
32
+ inputs='text',
33
+ outputs='text',
34
+ title='Tweet Sentiment Analyzer',
35
+ description='Enter a tweet and get the sentiment prediction.',
36
+ examples=[['I love this movie!', 'This weather is terrible.']],
37
+ theme='default'
38
+ )
39
+
40
+ # Launch the interface
41
+ iface.launch()