-
Notifications
You must be signed in to change notification settings - Fork 593
/
Copy pathapp.py
446 lines (412 loc) · 14.3 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# The code uses dash library in Python for rendering the web-app.
# More information can be found at https://dash.plotly.com/
# Importing required libraries
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate
import webbrowser
# Initialisation
app = dash.Dash(__name__)
server = app.server
# Defining global variables
global name, score
score = 0
# Setting layout
app.layout = html.Div(
style={'textAlign': "center", "marginLeft": "50px", "marginRight": "50px"},
children=[
html.H1(
style={'color': "#1876D2", 'fontWeight': "bolder",
"marginBottom": "50px", 'fontSize': "50px"},
children='Test your personality 😁'),
html.H3('May I know your name?'),
dcc.Input(id='name', type='text',
style={"height": "30px", "borderRadius": "20px",
"textIndent": "10px", "fontSize": "20px"}),
html.Button('Submit',
style={'backgroundColor': "#1876D2", "border": "none",
"marginLeft": "10px", "outline": "none",
'fontWeight': "bolder", "padding": "10px",
"borderRadius": "20px", 'color': "white"},
id='submit', n_clicks=0),
html.Div(id='init'),
html.Div(id='q1'),
html.Div(id='q2'),
html.Div(id='q3'),
html.Div(id='q4'),
html.Div(id='q5'),
html.Div(id='q6'),
html.Div(id='q7'),
html.Div(id='q8'),
html.Div(id='q9'),
html.Div(id='q10'),
html.Div(id='result')
]
)
# Using callbacks to handle questions and answers,
# along with keeping a track of score
@app.callback(
Output('init', 'children'),
[Input('name', 'value'), Input('submit', 'n_clicks')]
)
def update_name(name, n_clicks):
if n_clicks == 0:
raise PreventUpdate
else:
return [html.Br(),
html.H3(
style={'color': "#1876D2"}, children='''You like to spend
your free time exploring something new or do you follow
same routine'''),
dcc.RadioItems(
id='a2', options=[{'label': 'New 💯',
'value': 'new'},
{'label': 'Same as always',
'value': 'same'}],
value=None)]
@app.callback(
Output('q1', 'children'),
[Input('a1', 'value')]
)
def q1(a1):
global score
if a1 is None:
raise PreventUpdate
else:
if a1 == 'yes':
score = score + 1
elif a1 == 'maybe':
score = score + 0.5
return [html.Br(),
html.H3(
style={'color': "#1876D2"}, children='''You like to spend
your free time exploring something new or do you follow
same routine'''),
dcc.RadioItems(
id='a2', options=[{'label': 'New 💯',
'value': 'new'},
{'label': 'Same as always',
'value': 'same'}],
value=None)]
@app.callback(
Output('q2', 'children'),
[Input('a2', 'value')]
)
def q2(a2):
global score
if a2 is None:
raise PreventUpdate
else:
if a2 == 'new':
score = score + 1
return [html.Br(),
html.H3(
style={'color': "#1876D2"}, children=''''How comfortable
are you while talking to new people?'''),
dcc.Slider(
id='a3',
min=0,
max=10,
marks={
0: 'Not at all',
10: 'Absolutely comfortable'
},
step=1,
value=None
)]
@app.callback(
Output('q3', 'children'),
[Input('a3', 'value')]
)
def q3(a3):
global score
if a3 is None:
raise PreventUpdate
else:
if a3 == 1:
score = score + 0.1
elif a3 == 2:
score = score + 0.2
elif a3 == 3:
score = score + 0.3
elif a3 == 4:
score = score + 0.4
elif a3 == 5:
score = score + 0.5
elif a3 == 6:
score = score + 0.6
elif a3 == 7:
score = score + 0.7
elif a3 == 8:
score = score + 0.8
elif a3 == 9:
score = score + 0.9
elif a3 == 10:
score = score + 1
return [html.Br(),
html.H3(
style={'color': "#1876D2"}, children='''What do you prefer-
hard work or smart work?'''),
dcc.RadioItems(
id='a4',
options=[{'label': 'Hard work', 'value': 'hard'},
{'label': 'Smart work', 'value': 'smart'},
{'label': 'It depends on the situation',
'value': 'both'}],
value=None)]
@app.callback(
Output('q4', 'children'),
[Input('a4', 'value')]
)
def q4(a4):
global score
if a4 is None:
raise PreventUpdate
else:
if a4 == 'hard':
score = score + 0.5
elif a4 == 'smart':
score = score + 0.5
elif a4 == 'both':
score = score + 1
return [html.Br(),
html.H3(
style={'color': "#1876D2"}, children='''You and your peer
are working together. He/she is stuck in a task.
Will you?'''),
dcc.RadioItems(
id='a5',
options=[{'label': 'Help them instantly',
'value': 'fast'},
{'label': '''Help after completing your current
work''',
'value': 'curr'},
{'label': '''Help after
completing all your work''',
'value': 'no'}],
value=None)]
@app.callback(
Output('q5', 'children'),
[Input('a5', 'value')]
)
def q5(a5):
global score
if a5 is None:
raise PreventUpdate
else:
if a5 == 'fast':
score = score + 0.5
elif a5 == 'curr':
score = score + 1
return [html.Br(),
html.H3(
style={'color': "#1876D2"}, children='''Which category do
you fit in?'''),
dcc.RadioItems(
id='a6',
options=[{'label': 'Extrovert', 'value': 'ex'},
{'label': 'Introvert', 'value': 'in'},
{'label': 'Ambivert', 'value': 'am'}],
value=None)]
@app.callback(
Output('q6', 'children'),
[Input('a6', 'value')]
)
def q6(a6):
global score
if a6 is None:
raise PreventUpdate
else:
if a6 == 'ex':
score = score + 1
elif a6 == 'am':
score = score + 0.5
return [html.Br(),
html.H3(
style={'color': "#1876D2"}, children='''Are you willing to
work overtime if required?'''),
dcc.RadioItems(
id='a7',
options=[{'label': 'Yes I would be happy',
'value': 'happy'},
{'label': 'Yes, if I get paid accordingly',
'value': 'pay'},
{'label': 'No, I am not comfortable doing this',
'value': 'no'}],
value=None)]
@app.callback(
Output('q7', 'children'),
[Input('a7', 'value')]
)
def q7(a7):
global score
if a7 is None:
raise PreventUpdate
else:
if a7 == 'happy':
score = score + 1
elif a7 == 'no':
score = score + 0.5
return [html.Br(),
html.H3(
style={'color': "#1876D2"}, children='''How comfortable
will you be if we ask you to travel for work?'''),
dcc.RadioItems(
id='a8',
options=[{'label': 'No problem, I\'m ready',
'value': 'ready'},
{'label': 'Only if my safety is taken care of',
'value': 'safe'},
{'label': 'No, it is tiring for me',
'value': 'no'}],
value=None)]
@app.callback(
Output('q8', 'children'),
[Input('a8', 'value')]
)
def q8(a8):
global score
if a8 is None:
raise PreventUpdate
else:
if a8 == 'ready':
score = score + 1
elif a8 == 'safe':
score = score + 1
elif a8 == 'no':
score = score + 0.5
return [html.Br(),
html.H3(
style={'color': "#1876D2"}, children='''What is the salary
range you expect as a fresher?'''),
dcc.RadioItems(
id='a9',
options=[{'label': '<= 4 lpa',
'value': 'less'},
{'label': '> 4 lpa till < 90 lpa',
'value': 'more'},
{'label': 'Best according to my talent',
'value': 'mid'}],
value=None)]
@app.callback(
Output('q9', 'children'),
[Input('a9', 'value')]
)
def q9(a9):
global score
if a9 is None:
raise PreventUpdate
else:
if a9 == 'more':
score = score + 1
elif a9 == 'mid':
score = score + 1
elif a9 == 'less':
score = score + 0.5
return [html.Br(),
html.H3(
style={'color': "#1876D2"}, children='''How likely will
you reveal the company policies to an outsider, either
knowingly or unknowingly?'''),
dcc.Slider(
id='a10',
min=1,
max=5,
marks={
1: 'Very unlikely',
2: 'Somewhat unlikely',
3: 'I don\'t know',
4: 'somewhat likely',
5: 'Very likely'
},
step=1,
value=None
)]
@app.callback(
Output('q10', 'children'),
[Input('a10', 'value')]
)
def q10(a10):
global score
if a10 is None:
raise PreventUpdate
else:
if a10 == 1:
score = score + 1
elif a10 == 2:
score = score + 0.5
elif a10 == 3:
score = score + 0.5
elif a10 == 4:
score = score - 0.5
elif a10 == 5:
score = score - 1
return [html.Br(), html.H3('Any feedback you want to provide?'),
dcc.Input(id='res', type='text',
style={"height": "30px", "borderRadius": "20px",
"textIndent": "10px", "fontSize": "20px"}),
html.Button('Submit', id='feedback', n_clicks=0,
style={'backgroundColor': "#1876D2",
"border": "none",
"marginLeft": "10px",
"outline": "none",
'fontWeight': "bolder",
"padding": "10px",
"borderRadius": "20px",
'color': "white"})
]
# Displaying result according to score
@app.callback(
Output('result', 'children'),
[Input('feedback', 'n_clicks')]
)
def result(n_clicks):
if n_clicks == 0:
raise PreventUpdate
else:
if score == 0:
return [html.Br(),
html.H3("Score: " + str(score) + '''/10 --> I am sorry.
You are a poor fit.''',
style={"fontSize": "25px", "color": "#1876D2"}),
html.H3("😔"),
html.H3('Thanks for your time!')]
elif score < 5:
return [html.Br(),
html.H3("Score: " + str(score) + '''/10 --> You need to work
more upon your personality.''',
style={"fontSize": "25px", "color": "#1876D2"}),
html.H3("🙂"),
html.H3('Thanks for your time!')]
elif score == 5:
return [html.Br(),
html.H3("Score: " + str(score) + '''/10 --> You are average.
You can always improve.''',
style={"fontSize": "25px", "color": "#1876D2"}),
html.H3("😃"),
html.H3('Thanks for your time!')]
elif score > 5 and score < 8.5:
return [html.Br(),
html.H3("Score: " + str(score) + '''/10 --> You are a decent
fit for the company. Remember, practise makes a
man perfect!''',
style={"fontSize": "25px", "color": "#1876D2"}),
html.H3("💯💯"),
html.H3('Thanks for your time!')]
elif score >= 8.5 and score <= 10:
return [html.Br(),
html.H3("Score: " + str(score) + '''/10 --> Excellent🎉 We
are proud to have you in the workforce.
Congratulations!!''',
style={"fontSize": "25px", "color": "#1876D2"}),
html.H3("🔥🔥"),
html.H3('Thanks for your time!')]
def web():
webbrowser.open_new('http://127.0.0.1:8050/')
# The main function
if __name__ == '__main__':
web()
app.title = 'yourPersonality'
app.run_server()