Pontonkid commited on
Commit
eca4855
β€’
1 Parent(s): a2efff7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import nltk
2
+ from nltk.sentiment import SentimentIntensityAnalyzer
3
+
4
+ # Download the vader_lexicon resource
5
+ nltk.download('vader_lexicon')
6
+
7
+ 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.."
8
+ analyzer = SentimentIntensityAnalyzer()
9
+ scores = analyzer.polarity_scores(text)
10
+ if scores['compound'] >= 0.05:
11
+ print("Positive Sentiment")
12
+ elif scores['compound'] <= -0.05:
13
+ print("Negative Sentiment")
14
+ else:
15
+ print("Neutral Sentiment")
16
+
17
+
18
+ import gradio as gr
19
+ import nltk
20
+ from nltk.sentiment import SentimentIntensityAnalyzer
21
+
22
+ nltk.download('vader_lexicon')
23
+
24
+ analyzer = SentimentIntensityAnalyzer()
25
+
26
+ def analyze_sentiment(text):
27
+ scores = analyzer.polarity_scores(text)
28
+ if scores['compound'] >= 0.5:
29
+ sentiment = "Very Positive πŸ˜ƒ"
30
+ elif scores['compound'] > 0 and scores['compound'] < 0.5:
31
+ sentiment = "Positive πŸ™‚"
32
+ elif scores['compound'] == 0:
33
+ sentiment = "Neutral 😐"
34
+ elif scores['compound'] > -0.5 and scores['compound'] < 0:
35
+ sentiment = "Negative πŸ™"
36
+ elif scores['compound'] <= -0.5:
37
+ sentiment = "Very Negative 😠"
38
+ elif "racist" in text.lower():
39
+ sentiment = "Racist 🀬"
40
+ elif "annoying" in text.lower():
41
+ sentiment = "Annoying πŸ˜’"
42
+ elif "boring" in text.lower():
43
+ sentiment = "Boring 😴"
44
+ else:
45
+ sentiment = "Unknown πŸ˜•"
46
+ return sentiment, text
47
+
48
+ iface = gr.Interface(fn=analyze_sentiment,
49
+ inputs=gr.inputs.Textbox(label="Enter Text Here"),
50
+ outputs=[gr.outputs.Textbox(label="Sentiment"),
51
+ gr.outputs.Textbox(label="Input Text")],
52
+ title="Sentiment Analysis",
53
+ description="Enter a sentence and get the sentiment analysis result.")
54
+
55
+ iface.launch()
56
+