-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHome.py
More file actions
120 lines (90 loc) · 4.19 KB
/
Home.py
File metadata and controls
120 lines (90 loc) · 4.19 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import tkinter as tk
from tkinter import ttk
from tkinter.ttk import Treeview
# from tkinter import PhotoImage
from Model import model
from ytAPI import youtubeAPI
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
#from sklearn.metrics import accuracy_score
from sklearn.model_selection import KFold
import matplotlib
from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
matplotlib.use('TkAgg')
class form:
def __init__ (self):
self.frame = tk.Tk()
self.frame.geometry("1200x1200")
#self.frame.config(bg = "cyan")
self.frame.title("Youtube Video Comments Sentiment Analysis")
yt_link_text = tk.StringVar()
self.lbl = tk.Label(self.frame, text = 'Enter link to a youtube video')
self.lbl.place(x=300, y=50)
self.yt_link_textfield = tk.Entry(self.frame, textvariable = yt_link_text)
self.yt_link_textfield.place(x=600, y =50)
self.submit_button = tk.Button(self.frame, text="Submit", command = self.submit_click)
self.submit_button.place(x = 500, y = 90)
self.comment_tree = Treeview(self.frame)
self.comment_tree['columns'] = ('c1')
self.comment_tree.column("#0", width=700)
self.comment_tree.column('c1', anchor = 'center')
self.comment_tree.heading('#0', text = 'Comment')
self.comment_tree.heading('c1', text = 'Sentiment')
self.comment_tree.place(x= 100, y=170)
self.frame.mainloop()
#LOGO ADD
# self.canvas = tk.Canvas(self.frame, width=200, height=200)
# self.canvas.place(x=500, y=600)
# self.image = PhotoImage(file = "/Users/rishabmehndiratta/YT setiment analysis/YT Project FINAL/popo.gif")
# self.canvas.create_image(100, 100, image=self.image)
def submit_click(self):
self.yt_link_text = self.yt_link_textfield.get()
start = self.yt_link_text.find("v=")
start += 2
end = self.yt_link_text.find("&", start)
self.video_id = self.yt_link_text[start:end]
self.objAPI = youtubeAPI()
yt_comments = self.objAPI.get_yt_comments(self.video_id)
yt_comments['sentiment'] = None
#print(yt_comments)
# getting training data for training:
self.objModel = model()
training_data = self.objModel.get_clean_training_data()
Independent_var = training_data.comment
Dependent_var = training_data.Remark
vect = TfidfVectorizer()
clf = LogisticRegression()
model_logistic = Pipeline([('vectorizer', vect), ('classifier', clf)])
model_logistic.fit(Independent_var, Dependent_var)
for index, row in yt_comments.iterrows():
prediction = model_logistic.predict([row['comment']])
yt_comments.at[index,'sentiment'] = " ".join(prediction)
print("hello before yt comments")
print(yt_comments)
x = ['+VE', '-VE']
self.sentiment_count = yt_comments['sentiment'].value_counts()
fig1 = Figure(figsize = (3,3), dpi =100)
# fig1.set_facecolor('orange')
plot1 = fig1.add_subplot(111)
explode = (0, 0.1)
colors = ['#99ff99', '#ff9999']
plot1.pie(self.sentiment_count,explode = explode, labels = x, autopct = '%0.2f%%', colors = colors)
canvas1 = FigureCanvasTkAgg(fig1, master = self.frame)
canvas1.draw()
canvas1.get_tk_widget().place(x = 100, y=450)
fig2 = Figure(figsize=(3,3), dpi = 100)
# fig2.set_facecolor('orange')
plot2 = fig2.add_subplot(111)
plot2.bar(x, self.sentiment_count, color = colors)
for index, value in enumerate(self.sentiment_count):
plot2.text(value, index, str(value))
canvas2 = FigureCanvasTkAgg(fig2, master = self.frame)
canvas2.draw()
canvas2.get_tk_widget().place(x = 700, y=450)
for index, row in yt_comments.iterrows():
# print(row[0])
self.comment_tree.insert("", 0, text = row['comment'], values = (row['sentiment']))
print(self.sentiment_count)
obj = form()