File size: 1,172 Bytes
0cf6beb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53df561
0cf6beb
53df561
 
0cf6beb
 
 
53df561
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import gradio as gr
import nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer

# Download required NLTK resources
nltk.download('vader_lexicon')

# Load the pre-trained sentiment intensity analyzer
sia = SentimentIntensityAnalyzer()

def get_sentiment(tweet):
    # Preprocess the tweet
    processed_tweet = preprocess([tweet])
    
    # Get the sentiment score using VADER sentiment analyzer
    sentiment_score = sia.polarity_scores(processed_tweet[0])
    
    # Determine the sentiment label based on the compound score
    compound_score = sentiment_score['compound']
    if compound_score >= 0.05:
        sentiment = 'Positive'
    elif compound_score <= -0.05:
        sentiment = 'Negative'
    else:
        sentiment = 'Neutral'
    
    return sentiment

# Create a Gradio interface
iface = gr.Interface(
    fn=get_sentiment,
    inputs='text',
    outputs='text',
    title='Tweet Sentiment Analyzer',
    description='Enter a tweet with text or emoticon or both, and get the sentiment prediction.',
    examples=[['I love this movie!', 'This weather is terrible.']],
    theme='Soft'
    
)

# Launch the interface
iface.launch(share = True)