-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
262 lines (221 loc) Β· 9.01 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
from flask import Flask, render_template, request, redirect, url_for
import pickle
import jinja2
app = Flask(__name__, template_folder='templates')
model = pickle.load(open('finalized_model.pkl', 'rb'))
output = -1
user_log = 0
def render_without_request(template_name, **template_vars):
"""
Usage is the same as flask.render_template:
render_without_request('my_template.html', var1='foo', var2='bar')
"""
env = jinja2.Environment(
loader=jinja2.PackageLoader('name.ofmy.package','templates')
)
template = env.get_template(template_name)
return template.render(**template_vars)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/home')
def home():
return render_template('home.html')
@app.route('/breathe')
def breathe():
return render_template('breathe.html')
@app.route('/clean')
def clean():
return render_template('clean.html')
@app.route('/stress')
def stress():
return render_template('stress.html')
@app.route('/book')
def book():
return render_template('book.html')
@app.route('/calendar')
def calendar():
return render_template('calendar.html')
@app.route('/music')
def music():
return render_template('music.html')
@app.route('/task')
def task():
return render_template('task.html')
@app.route('/ocd')
def ocd():
return render_template('ocd.html')
@app.route('/user')
def user():
if output == -1:
return render_template('user.html')
elif output == 1:
return render_template('user.html',
suggestio="CHRONIC STRESS",
tasksug="We recommend you to perform Task 3, although you can do any")
elif output == 2:
return render_template('user.html',
suggestio="EPISODIC ACUTE STRESS",
tasksug="We recommend you to perform Task 2, although you can do any")
elif output == 3:
return render_template('user.html',
suggestio="ACUTE STRESS",
tasksug="We recommend you to perform Task 1, although you can do any")
@app.route("/predict", methods=['POST'])
def predict():
global output
global user_log
if request.method == 'POST':
Age = request.form['Age']
if Age == 'below 30':
Age = 1
elif Age == 'Between 30 and 50':
Age = 2
else:
Age = 3
Gender = request.form['Gender']
if Gender == 'Male':
Gender = 1
else:
Gender = 2
Sector = request.form['Sector']
if Sector == 'Public':
Sector = 1
else:
Sector = 2
Work_hours = request.form['Work_hours']
if Work_hours == '5hrs':
Work_hours = 1
elif Work_hours == '10hrs':
Work_hours = 2
else:
Work_hours = 3
Work_years_span = request.form['Work_years_span']
if Work_years_span == 'Below 5 years':
Work_years_span = 1
elif Work_years_span == 'Between 5 to 10 years':
Work_years_span = 2
else:
Work_years_span = 3
Stressed_during_work = request.form['Stressed_during_work']
if Stressed_during_work == 'Sometimes':
Stressed_during_work = 1
elif Stressed_during_work == 'Very Often':
Stressed_during_work = 2
else:
Stressed_during_work = 3
Feeling_on_job = request.form['Feeling_on_job']
if Feeling_on_job == 'I am completely happy and enjoying the job':
Feeling_on_job = 1
elif Feeling_on_job == 'I sometimes feel dissatisfied but generally enjoy my job':
Feeling_on_job = 2
elif Feeling_on_job == 'Most of the time I do not enjoy my work':
Feeling_on_job = 3
else:
Feeling_on_job = 4
Source_of_stress = request.form['Source_of_stress']
if Source_of_stress == 'Over work':
Source_of_stress = 1
elif Source_of_stress == 'Family Issues':
Source_of_stress = 2
elif Source_of_stress == 'Out of Control Situation':
Source_of_stress = 3
elif Source_of_stress == 'Colleague Attitude':
Source_of_stress = 4
else:
Source_of_stress = 5
Stress_affecting_concentration = request.form['Stress_affecting_concentration']
if Stress_affecting_concentration == 'Very often':
Stress_affecting_concentration = 1
elif Stress_affecting_concentration == 'Somewhat':
Stress_affecting_concentration = 2
else:
Stress_affecting_concentration = 3
Effort_to_reduce_stress_to_improve_concentration = request.form[
'Effort_to_reduce_stress_to_improve_concentration']
if Effort_to_reduce_stress_to_improve_concentration == 'No effort':
Effort_to_reduce_stress_to_improve_concentration = 1
elif Effort_to_reduce_stress_to_improve_concentration == 'Some effort':
Effort_to_reduce_stress_to_improve_concentration = 2
else:
Effort_to_reduce_stress_to_improve_concentration = 3
Stress_due_to_too_many_duties = request.form['Stress_due_to_too_many_duties']
if Stress_due_to_too_many_duties == 'Yes':
Stress_due_to_too_many_duties = 1
else:
Stress_due_to_too_many_duties = 2
Stress_due_to_age = request.form['Stress_due_to_age']
if Stress_due_to_age == 'Yes':
Stress_due_to_age = 1
else:
Stress_due_to_age = 2
Stress_reason_family = request.form['Stress_reason_family']
if Stress_reason_family == 'Yes':
Stress_reason_family = 1
else:
Stress_reason_family = 2
Stress_due_to_competition = request.form['Stress_due_to_competition']
if Stress_due_to_competition == 'Yes':
Stress_due_to_competition = 1
else:
Stress_due_to_competition = 2
Prefer_to_stay_alone = request.form['Prefer_to_stay_alone']
if Prefer_to_stay_alone == 'Yes':
Prefer_to_stay_alone = 1
else:
Prefer_to_stay_alone = 2
Prefer_taking_responsibilities = request.form['Prefer_taking_responsibilities']
if Prefer_taking_responsibilities == 'Yes':
Prefer_taking_responsibilities = 1
else:
Prefer_taking_responsibilities = 2
Alcohol_usage = request.form['Alcohol_usage']
if Alcohol_usage == 'Yes':
Alcohol_usage = 1
else:
Alcohol_usage = 2
Stress_nervous_habits = request.form['Stress_nervous_habits']
if Stress_nervous_habits == 'Daily':
Stress_nervous_habits = 1
elif Stress_nervous_habits == 'Occasionally':
Stress_nervous_habits = 2
elif Stress_nervous_habits == 'Sometimes':
Stress_nervous_habits = 3
else:
Stress_nervous_habits = 4
Stress_makes_nervous = request.form['Stress_makes_nervous']
if Stress_makes_nervous == 'Yes':
Stress_makes_nervous = 1
else:
Stress_makes_nervous = 2
Stress_affects_emotions = request.form['Stress_affects_emotions']
if Stress_affects_emotions == 'Yes':
Stress_affects_emotions = 1
else:
Stress_affects_emotions = 2
prediction = model.predict([[Age, Gender, Sector, Work_hours,
Work_years_span, Stressed_during_work, Feeling_on_job,
Source_of_stress, Stress_affecting_concentration,
Effort_to_reduce_stress_to_improve_concentration,
Stress_due_to_too_many_duties, Stress_due_to_age,
Stress_reason_family, Stress_due_to_competition,
Prefer_to_stay_alone, Prefer_taking_responsibilities,
Alcohol_usage, Stress_nervous_habits, Stress_makes_nervous,
Stress_affects_emotions]])
output = prediction[0]
if output == 1:
return render_template('stress.html',
prediction_text="Chronic Stress... No need to worry we will work together ππ "
"Move on to Task 3")
elif output == 2:
return render_template('stress.html',
prediction_text="Episodic Acute Stress.. Lets resolve it together ππ Move on to "
"Task 2")
elif output == 3:
return render_template('stress.html',
prediction_text="Acute Stress.. We will easily come out STRESS FREE ππ Move on "
"to Task 1")
else:
return render_template('home.html')
if __name__ == "__main__":
app.run(debug=True)