Skip to content

Commit 502e3ca

Browse files
committed
Sentiment Detector
1 parent 6914085 commit 502e3ca

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# <b>Sentiment Detector</b>
2+
3+
[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com)
4+
5+
## Sentiment Detector Functionalities : 🚀
6+
7+
- In the input field write the sentence whose sentiment is to be checked
8+
- On clicking on ```check sentiment``` button it displays the percentage of neutral, positive and negative sentiments
9+
- It also displays the overall sentiment
10+
11+
## Sentiment Detector Instructions: 👨🏻‍💻
12+
13+
### Step 1:
14+
15+
Open Termnial 💻
16+
17+
### Step 2:
18+
19+
Locate to the directory where python file is located 📂
20+
21+
### Step 3:
22+
23+
Run the command: python script.py/python3 script.py 🧐
24+
25+
### Step 4:
26+
27+
Sit back and Relax. Let the Script do the Job. ☕
28+
29+
## Requirements
30+
31+
- vaderSentiment
32+
- tkinter
33+
34+
## DEMO
35+
![Screenshot (211)](https://user-images.githubusercontent.com/60662775/115137592-9ac8c000-a044-11eb-83fe-84eaeb549283.png)
36+
37+
## Author
38+
39+
Amit Kumar Mishra
40+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
2+
from tkinter import *
3+
4+
def detect_sentiment():
5+
6+
sentence = textArea.get("1.0", "end")
7+
sid_obj = SentimentIntensityAnalyzer()
8+
9+
sentiment_dict = sid_obj.polarity_scores(sentence)
10+
11+
string = str(sentiment_dict['neg']*100) + "% Negative"
12+
negativeField.insert(10, string)
13+
14+
string = str(sentiment_dict['neu']*100) + "% Neutral"
15+
neutralField.insert(10, string)
16+
17+
string = str(sentiment_dict['pos']*100) +"% Positive"
18+
positiveField.insert(10, string)
19+
20+
if sentiment_dict['compound'] >= 0.05 :
21+
string = "Positive"
22+
23+
elif sentiment_dict['compound'] <= - 0.05 :
24+
string = "Negative"
25+
else :
26+
string = "Neutral"
27+
28+
overallField.insert(10, string)
29+
30+
def clearAll() :
31+
32+
negativeField.delete(0, END)
33+
neutralField.delete(0, END)
34+
positiveField.delete(0, END)
35+
overallField.delete(0, END)
36+
textArea.delete(1.0, END)
37+
38+
39+
gui = Tk()
40+
gui.config(background = "light blue")
41+
gui.title("Sentiment Detector")
42+
43+
gui.geometry("500x500")
44+
enterText = Label(gui, text = "Enter Your Sentence",bg = "light blue")
45+
46+
textArea = Text(gui, height = 10, width = 53, font = "lucida 13")
47+
48+
check = Button(gui, text = "Check Sentiment", fg = "Black",bg = "light yellow", command = detect_sentiment)
49+
negative = Label(gui, text = "sentence was rated as: ",bg = "light blue")
50+
51+
neutral = Label(gui, text = "sentence was rated as: ",bg = "light blue")
52+
53+
positive = Label(gui, text = "sentence was rated as: ",bg = "light blue")
54+
55+
overall = Label(gui, text = "Sentence Overall Rated As: ",bg = "light blue")
56+
57+
negativeField = Entry(gui)
58+
59+
neutralField = Entry(gui)
60+
positiveField = Entry(gui)
61+
overallField = Entry(gui)
62+
clear = Button(gui, text = "Clear", fg = "Black",bg = "light yellow", command = clearAll)
63+
Exit = Button(gui, text = "Exit", fg = "Black",bg = "light yellow", command = exit)
64+
65+
enterText.grid(row = 0, column = 2)
66+
67+
textArea.grid(row = 1, column = 2, padx = 10, sticky = W)
68+
69+
check.grid(row = 2, column = 2)
70+
71+
neutral.grid(row = 3, column = 2)
72+
73+
neutralField.grid(row = 4, column = 2)
74+
75+
positive.grid(row = 5, column = 2)
76+
77+
positiveField.grid(row = 6, column = 2)
78+
79+
negative.grid(row = 7, column = 2)
80+
81+
negativeField.grid(row = 8, column = 2)
82+
83+
overall.grid(row = 9, column = 2)
84+
85+
overallField.grid(row = 10, column = 2)
86+
87+
clear.grid(row = 11, column = 2)
88+
89+
Exit.grid(row = 12, column = 2)
90+
91+
gui.mainloop()
92+

0 commit comments

Comments
 (0)