File size: 1,936 Bytes
eca4855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import nltk
from nltk.sentiment import SentimentIntensityAnalyzer

# Download the vader_lexicon resource
nltk.download('vader_lexicon')

text = "I absolutely loved this movie! The acting was superb, the plot was engaging, and the cinematography was stunning. I would highly recommend it to anyone looking for a great film to watch.."
analyzer = SentimentIntensityAnalyzer()
scores = analyzer.polarity_scores(text)
if scores['compound'] >= 0.05:
    print("Positive Sentiment")
elif scores['compound'] <= -0.05:
    print("Negative Sentiment")
else:
    print("Neutral Sentiment")


import gradio as gr
import nltk
from nltk.sentiment import SentimentIntensityAnalyzer

nltk.download('vader_lexicon')

analyzer = SentimentIntensityAnalyzer()

def analyze_sentiment(text):
    scores = analyzer.polarity_scores(text)
    if scores['compound'] >= 0.5:
        sentiment = "Very Positive πŸ˜ƒ"
    elif scores['compound'] > 0 and scores['compound'] < 0.5:
        sentiment = "Positive πŸ™‚"
    elif scores['compound'] == 0:
        sentiment = "Neutral 😐"
    elif scores['compound'] > -0.5 and scores['compound'] < 0:
        sentiment = "Negative πŸ™"
    elif scores['compound'] <= -0.5:
        sentiment = "Very Negative 😠"
    elif "racist" in text.lower():
        sentiment = "Racist 🀬"
    elif "annoying" in text.lower():
        sentiment = "Annoying πŸ˜’"
    elif "boring" in text.lower():
        sentiment = "Boring 😴"
    else:
        sentiment = "Unknown πŸ˜•"
    return sentiment, text

iface = gr.Interface(fn=analyze_sentiment, 
                     inputs=gr.inputs.Textbox(label="Enter Text Here"), 
                     outputs=[gr.outputs.Textbox(label="Sentiment"), 
                              gr.outputs.Textbox(label="Input Text")],
                     title="Sentiment Analysis", 
                     description="Enter a sentence and get the sentiment analysis result.")

iface.launch()