1+ import pandas as pd
2+ import numpy as np
3+ import matplotlib .pyplot as plt
4+ import json
5+ import faculty
6+ import drawFigure
7+
8+
9+ from flask import Flask , render_template , redirect , request
10+
11+ app = Flask (__name__ )
12+
13+
14+ with open ('Student-Feedback-Sentiment-Analysis-main/feedback1.json' ) as file :
15+ json_string = file .read ()
16+ documents1 = json .loads (json_string )
17+
18+ with open ('Student-Feedback-Sentiment-Analysis-main/feedback2.json' ) as file :
19+ json_string = file .read ()
20+ documents2 = json .loads (json_string )
21+
22+ with open ('Student-Feedback-Sentiment-Analysis-main/feedback3.json' ) as file :
23+ json_string = file .read ()
24+ documents3 = json .loads (json_string )
25+
26+ with open ('Student-Feedback-Sentiment-Analysis-main/feedback4.json' ) as file :
27+ json_string = file .read ()
28+ documents4 = json .loads (json_string )
29+
30+ with open ('Student-Feedback-Sentiment-Analysis-main/feedback5.json' ) as file :
31+ json_string = file .read ()
32+ documents5 = json .loads (json_string )
33+
34+ with open ('Student-Feedback-Sentiment-Analysis-main/feedback6.json' ) as file :
35+ json_string = file .read ()
36+ documents6 = json .loads (json_string )
37+
38+ label2category = {1 : 'positive' , 0 : 'neutral' , - 1 : 'negative' }
39+ category2label = {cat :label for label , cat in label2category .items ()}
40+
41+
42+ categories1 = [category2label [category ] for doc , category in documents1 ]
43+ categories2 = [category2label [category ] for doc , category in documents2 ]
44+ categories3 = [category2label [category ] for doc , category in documents3 ]
45+ categories4 = [category2label [category ] for doc , category in documents4 ]
46+ categories5 = [category2label [category ] for doc , category in documents5 ]
47+ categories6 = [category2label [category ] for doc , category in documents6 ]
48+
49+
50+ corpus1 = [' ' .join (document ) for document , cat in documents1 ]
51+ corpus2 = [' ' .join (document ) for document , cat in documents2 ]
52+ corpus3 = [' ' .join (document ) for document , cat in documents3 ]
53+ corpus4 = [' ' .join (document ) for document , cat in documents4 ]
54+ corpus5 = [' ' .join (document ) for document , cat in documents5 ]
55+ corpus6 = [' ' .join (document ) for document , cat in documents6 ]
56+
57+
58+
59+ @app .route ('/' )
60+ def display ():
61+ return render_template ('index.html' )
62+
63+
64+ @app .route ('/' , methods = ['POST' ])
65+ def caption ():
66+
67+ if request .method == 'POST' :
68+
69+ f = request .files ["file_name" ]
70+ path = "Student-Feedback-Sentiment-Analysis-main/static/Student-Feedback-Form.csv"
71+ f .save (path )
72+
73+ category_no = int (request .form ['Cate' ])
74+
75+ df = pd .read_csv (path )
76+
77+ cols1 = []
78+ cols2 = []
79+ cols3 = []
80+ cols4 = []
81+ cols5 = []
82+ cols6 = []
83+
84+ substring1 = ['teacher' , 'faculty' , 'feedback' , 'effectiveness' , 'teaching' , 'knowledge' , 'delivery' , 'content' , 'quality' ,
85+ 'lecture' , 'subject' , 'syllabus' , 'review' , 'assessment' ]
86+ substring2 = ['course' , 'content' , 'syllabus' , 'review' , 'evaluation' , 'curriculum' , 'syllabi' , 'contents' , 'level' ,
87+ 'difficulty' , 'lecture' , 'outline' ]
88+ substring3 = ['exam' , 'examination' , 'pattern' , 'conduct' , 'question' , 'paper' , 'level' , 'outline' ]
89+ substring4 = ['laboratory' , 'laboratories' , 'lab' , 'facility' , 'facilities' , 'review' , 'feedback' , 'rate' , 'learning' ]
90+ substring5 = ['library' , 'facilities' , 'books' , 'availability' , 'facility' , 'material' , 'rate' , 'feedback' , 'review' ]
91+ substring6 = ['extra' , 'curricular' , 'activity' , 'activities' ]
92+
93+
94+ for i in list (df .columns ):
95+ for j in substring1 :
96+ if j .casefold () in i .casefold ():
97+ cols1 .append (df .columns .get_loc (i ))
98+ if cols1 != []:
99+ break
100+
101+ for i in list (df .columns ):
102+ for j in substring2 :
103+ if j .casefold () in i .casefold ():
104+ cols2 .append (df .columns .get_loc (i ))
105+ if cols2 != []:
106+ break
107+
108+ for i in list (df .columns ):
109+ for j in substring3 :
110+ if j .casefold () in i .casefold ():
111+ cols3 .append (df .columns .get_loc (i ))
112+ if cols3 != []:
113+ break
114+
115+ for i in list (df .columns ):
116+ for j in substring4 :
117+ if j .casefold () in i .casefold ():
118+ cols4 .append (df .columns .get_loc (i ))
119+ if cols4 != []:
120+ break
121+
122+
123+ for i in list (df .columns ):
124+ for j in substring5 :
125+ if j .casefold () in i .casefold ():
126+ cols5 .append (df .columns .get_loc (i ))
127+ if cols5 != []:
128+ break
129+
130+ for i in list (df .columns ):
131+ for j in substring6 :
132+ if j .casefold () in i .casefold ():
133+ cols6 .append (df .columns .get_loc (i ))
134+ if cols6 != []:
135+ break
136+
137+ cols = cols1 + cols2 + cols3 + cols4 + cols5 + cols6
138+ cols = list (set (cols ))
139+
140+ df_form = pd .read_csv (path , usecols = cols )
141+ reviews = np .array (df_form )
142+
143+ pos1 , n1 , neg1 = faculty .predict (corpus1 , categories1 , reviews [: , 0 ])
144+ pos2 , n2 , neg2 = faculty .predict (corpus1 , categories1 , reviews [: , 1 ])
145+ pos3 , n3 , neg3 = faculty .predict (corpus1 , categories1 , reviews [: , 2 ])
146+ pos4 , n4 , neg4 = faculty .predict (corpus1 , categories1 , reviews [: , 3 ])
147+ pos5 , n5 , neg5 = faculty .predict (corpus1 , categories1 , reviews [: , 4 ])
148+ pos6 , n6 , neg6 = faculty .predict (corpus1 , categories1 , reviews [: , 5 ])
149+
150+ results = {
151+ 'f1' : 'Teacher Feedback' ,
152+ 'pos1' : pos1 ,
153+ 'n1' : n1 ,
154+ 'neg1' : neg1 ,
155+ 'f2' : 'Course Content' ,
156+ 'pos2' : pos2 ,
157+ 'n2' : n2 ,
158+ 'neg1' : neg2 ,
159+ 'f3' : 'Examination pattern' ,
160+ 'pos3' : pos3 ,
161+ 'n3' : n3 ,
162+ 'neg3' : neg3 ,
163+ 'f4' : 'Laboratory' ,
164+ 'pos4' : pos4 ,
165+ 'n4' : n4 ,
166+ 'neg4' : neg4 ,
167+ 'f5' : 'Library Facilities' ,
168+ 'pos5' : pos5 ,
169+ 'n5' : n5 ,
170+ 'neg5' : neg5 ,
171+ 'f6' : 'Extra Co-Curricular Activities' ,
172+ 'pos6' : pos6 ,
173+ 'n6' : n6 ,
174+ 'neg6' : neg6 ,
175+ }
176+
177+ values = list ([[pos1 , n1 , neg1 ], [pos2 , n2 , neg2 ], [pos3 , n3 , neg3 ], [pos4 , n4 , neg4 ], [pos5 , n5 , neg5 ], [pos6 , n6 , neg6 ]])
178+ labels = list (['Teacher Feedback' , 'Course Content' , 'Examination pattern' ,'Laboratory' ,'Library Facilities' , 'Extra Co-Curricular Activities' ])
179+
180+ print (values [category_no - 1 ] , labels [category_no - 1 ] , category_no , category_no - 1 )
181+
182+ if category_no == 1 :
183+ results_1 = {
184+ 'f1' : 'Teacher Feedback' ,
185+ 'pos1' : pos1 ,
186+ 'n1' : n1 ,
187+ 'neg1' : neg1
188+ }
189+
190+ drawFigure .make (values [category_no - 1 ] , labels [category_no - 1 ] , category_no )
191+
192+ return render_template ('index1.html' , result1 = results_1 , cat = category_no )
193+
194+
195+ elif category_no == 2 :
196+ results_2 = {
197+ 'f2' : 'Course Content' ,
198+ 'pos2' : pos2 ,
199+ 'n2' : n2 ,
200+ 'neg2' : neg2
201+ }
202+
203+ drawFigure .make (values [category_no - 1 ] , labels [category_no - 1 ] , category_no )
204+
205+ return render_template ('index1.html' , result2 = results_2 , cat = category_no )
206+
207+
208+ elif category_no == 3 :
209+ results_3 = {
210+ 'f3' : 'Examination pattern' ,
211+ 'pos3' : pos3 ,
212+ 'n3' : n3 ,
213+ 'neg3' : neg3
214+ }
215+
216+ drawFigure .make (values [category_no - 1 ] , labels [category_no - 1 ] , category_no )
217+
218+ return render_template ('index1.html' , result3 = results_3 , cat = category_no )
219+
220+
221+ elif category_no == 4 :
222+ results_4 = {
223+ 'f4' : 'Laboratory' ,
224+ 'pos4' : pos4 ,
225+ 'n4' : n4 ,
226+ 'neg4' : neg4
227+ }
228+
229+ drawFigure .make (values [category_no - 1 ] , labels [category_no - 1 ] , category_no )
230+
231+ return render_template ('index1.html' , result4 = results_4 , cat = category_no )
232+
233+
234+ elif category_no == 5 :
235+ results_5 = {
236+ 'f5' : 'Library Facilities' ,
237+ 'pos5' : pos5 ,
238+ 'n5' : n5 ,
239+ 'neg5' : neg5
240+ }
241+
242+ drawFigure .make (values [category_no - 1 ] , labels [category_no - 1 ] , category_no )
243+
244+ return render_template ('index1.html' , result5 = results_5 , cat = category_no )
245+
246+
247+ elif category_no == 6 :
248+ results_6 = {
249+ 'f6' : 'Extra Co-Curricular Activities' ,
250+ 'pos6' : pos6 ,
251+ 'n6' : n6 ,
252+ 'neg6' : neg6
253+ }
254+
255+ drawFigure .make (values [category_no - 1 ] , labels [category_no - 1 ] , category_no )
256+
257+ return render_template ('index1.html' , result6 = results_6 , cat = category_no )
258+
259+
260+ else :
261+ for i in range (0 , 6 ):
262+ fig = plt .figure (figsize = (8 ,8 ) , edgecolor = 'red' , linewidth = 10 )
263+ plt .bar (x = ['Positive' , 'Neutral' , 'Negative' ] , height = values [i ] , color = ['blue' ,'gold' ,'red' ])
264+ plt .title (labels [i ], fontsize = 24 , weight = 'demibold' , pad = 15 , fontstyle = 'italic' , family = 'cursive' )
265+ plt .xticks (rotation = 0 , fontsize = 16 )
266+ plt .yticks ([])
267+ plt .xlabel ('Feedback Type' ,fontsize = 18 , labelpad = 17 , weight = 550 , family = 'cursive' )
268+ plt .ylabel ('' )
269+ fig .subplots_adjust (bottom = 0.14 )
270+ ax = plt .gca ()
271+ ax .spines ['right' ].set_visible (False )
272+ ax .spines ['top' ].set_visible (False )
273+ ax .spines ['left' ].set_visible (False )
274+ for p in ax .patches :
275+ ax .annotate ("%.1f%%" % (100 * float (p .get_height ()/ sum (values [i ]))), (p .get_x () + p .get_width () / 2. , abs (p .get_height ())),
276+ ha = 'center' , va = 'bottom' , color = 'black' , xytext = (0 , 5 ),rotation = 'horizontal' ,
277+ textcoords = 'offset points' , fontsize = 16 , fontweight = 'medium' )
278+ plt .savefig (f'Student-Feedback-Sentiment-Analysis-main/static/plot{ i + 10 } .jpg' )
279+
280+ return render_template ('index1.html' , result = results )
281+
282+ else :
283+ return render_template ('error.html' )
284+
285+
286+ if __name__ == '__main__' :
287+ app .run (debug = True )
0 commit comments