-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.py
95 lines (79 loc) · 2.76 KB
/
app.py
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
import pandas as pd
from flask import Flask, request, jsonify, render_template
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
#VADER belongs to a type of sentiment analysis that is based on lexicons of sentiment-related words
import sys
import socket
from datetime import datetime
import json
import os
#port_number = sys.argv[1]
def get_Host_name_IP():
try:
host_name = socket.gethostname()
host_ip = socket.gethostbyname(host_name)
return [host_name,host_ip]
except:
pass
def append(now,dictionary):
with os.fdopen(os.open('data.json', os.O_WRONLY | os.O_CREAT, 0o600), 'a') as file:
file.write(str('"')+now+str('":'))
file.write(json.dumps(dictionary,indent=4))
file.write(',')
file.close()
HN,IP=get_Host_name_IP()
app = Flask(__name__,template_folder='templates')
analyser = SentimentIntensityAnalyzer()
@app.route('/')
def home():
return render_template('index.html')
@app.route('/State',methods=['POST'])
def State():
'''
For rendering results on HTML GUI
'''
value = request.form
# data to store
msg = value['state']
now = str(datetime.now())[:-7]
features = [x for x in request.form.values()]
text=features[0]
result= analyser.polarity_scores(text)
pos=round(result['pos']*100)
neg=round(result['neg']*100)
neu=round(result['neu']*100)
dictionary={
"Category":"State Government",
"Feedback":msg,
"Postive":pos,
"Negative":neg,
"Neutral":neu
}
append(now,dictionary)
return render_template('index.html', prediction_text='You are {} % satisfied positively, {} % neutrally and {} % negatively satisfied with actions of State Government'.format(pos,neu,neg),data_hn=HN,data_ip=IP)
@app.route('/Central',methods=['POST'])
def Central():
'''
For rendering results on HTML GUI
'''
value = request.form
# data to store
msg = value['central']
now = str(datetime.now())[:-7]
features = [x for x in request.form.values()]
text=features[0]
result= analyser.polarity_scores(text)
pos=round(result['pos']*100)
neg=round(result['neg']*100)
neu=round(result['neu']*100)
dictionary={
"Category":"Central Government",
"Feedback":msg,
"Postive":pos,
"Negative":neg,
"Neutral":neu
}
append(now,dictionary)
return render_template('index.html', prediction_text='You are {} % satisfied positively, {} % neutrally and {} % negatively satisfied with actions of Central Government'.format(pos,neu,neg),data_hn=HN,data_ip=IP)
if __name__ == '__main__':
app.run(host='0.0.0.0',port = 5000, debug=True)