Spaces:
Runtime error
Runtime error
Commit
·
3587e2b
1
Parent(s):
5594854
Upload 2 files
Browse filesThere are two files - one runs the python webapp through gradio and the other one is the pickled file for the machine learning model
- covid_psyc_model.pkcls +0 -0
- webapp.py +98 -0
covid_psyc_model.pkcls
ADDED
Binary file (1.16 kB). View file
|
|
webapp.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import gradio as gr
|
3 |
+
def make_prediction(age1,gender1,occupation1,line_of_work1,time_bp1,time_dp1,travel_time1,easeof_online1,home_env1,prod_inc1,sleep_bal1,new_skill1,fam_connect1,relaxed1,self_time1,like_hw1,dislike_hw1,certaindays_hw1):
|
4 |
+
#print(age1+gender1+occupation1+line_of_work1+time_bp1+time_dp1+travel_time1+easeof_online1+home_env1+prod_inc1+sleep_bal1+new_skill1+fam_connect1+relaxed1+self_time1+like_hw1+dislike_hw1+certaindays_hw1)
|
5 |
+
print(age1+gender1+occupation1+line_of_work1+certaindays_hw1)
|
6 |
+
if age1=="18":
|
7 |
+
age1=int(1)
|
8 |
+
elif age1=="19-25":
|
9 |
+
age1=int(0)
|
10 |
+
elif age1=="33-40":
|
11 |
+
age1=int(2)
|
12 |
+
elif age1=="60+":
|
13 |
+
age1=int(3)
|
14 |
+
elif age1=="26-32":
|
15 |
+
age1=int(4)
|
16 |
+
elif age1=="40-50":
|
17 |
+
age1=int(5)
|
18 |
+
else: age1=int(6)
|
19 |
+
print(str(age1))
|
20 |
+
if gender1=="Male":
|
21 |
+
gender1=int(0)
|
22 |
+
elif gender1=="Female":
|
23 |
+
gender1=int(1)
|
24 |
+
else: gender1=int(2)
|
25 |
+
print(str(gender1))
|
26 |
+
if occupation1=="Student in College":
|
27 |
+
occupation1=int(0)
|
28 |
+
elif occupation1=="Student in School":
|
29 |
+
occupation1=int(1)
|
30 |
+
elif occupation1=="Working Professional":
|
31 |
+
occupation1=int(2)
|
32 |
+
elif occupation1=="Entrepreneur":
|
33 |
+
occupation1=int(3)
|
34 |
+
elif occupation1=="Retired/Senior Citizen":
|
35 |
+
occupation1=int(4)
|
36 |
+
elif occupation1=="Homemaker":
|
37 |
+
occupation1=int(5)
|
38 |
+
else: occupation1=int(6)
|
39 |
+
print(str(occupation1))
|
40 |
+
if line_of_work1=="Teaching":
|
41 |
+
line_of_work1=int(0)
|
42 |
+
elif line_of_work1=="Engineering":
|
43 |
+
line_of_work1=int(1)
|
44 |
+
elif line_of_work1=="Management":
|
45 |
+
line_of_work1=int(2)
|
46 |
+
elif line_of_work1=="APSPDCL":
|
47 |
+
line_of_work1=int(3)
|
48 |
+
elif line_of_work1=="Architecture":
|
49 |
+
line_of_work1=int(4)
|
50 |
+
elif line_of_work1=="Other":
|
51 |
+
line_of_work1=int(5)
|
52 |
+
else: line_of_work1=int(6)
|
53 |
+
print(str(line_of_work1))
|
54 |
+
if certaindays_hw1=="Yes":
|
55 |
+
certaindays_hw1=int(0)
|
56 |
+
elif certaindays_hw1=="No":
|
57 |
+
certaindays_hw1=int(1)
|
58 |
+
else: certaindays_hw1=int(2)
|
59 |
+
print(str(certaindays_hw1))
|
60 |
+
with open("covid_psyc_model.pkcls", "rb") as f:
|
61 |
+
#Then feeds our data into the model, then sets the "preds" variable to the prediction output for our class variable, which is price.
|
62 |
+
clf = pickle.load(f)
|
63 |
+
preds=clf.predict([[age1,gender1,occupation1,line_of_work1,time_bp1,time_dp1,travel_time1,easeof_online1,home_env1,prod_inc1,sleep_bal1,new_skill1,fam_connect1,relaxed1,self_time1,like_hw1,dislike_hw1,certaindays_hw1]])
|
64 |
+
if preds == 0:
|
65 |
+
return "Complete Physical Attendance"
|
66 |
+
elif preds== 1:
|
67 |
+
return "Work/study from home"
|
68 |
+
else:
|
69 |
+
return "Please check and re-enter your inputs"
|
70 |
+
#Finally, we send the prediction to the website.
|
71 |
+
return preds
|
72 |
+
|
73 |
+
HasAge=gr.Dropdown(["18","19-25","26-32","33-40","40-50","50-60","60+"],label="Please select your age range")
|
74 |
+
HasGender=gr.Dropdown(["Male","Female","Prefer not to say"],label="Please select your gender")
|
75 |
+
HasOccupation=gr.Dropdown(["Student in College", "Student in School", "Working Professional",
|
76 |
+
"Entrepreneur", "Retired/Senior Citizen", "Homemaker",
|
77 |
+
"Currently Out of Work",
|
78 |
+
"Medical Professional aiding efforts against COVID-19"],label="Please select your occupation")
|
79 |
+
HasLineOfWork=gr.Dropdown(["Teaching","Engineering","Management","APSPDCL","Architecture","Other","Government Employee"],label="Please select your line of work")
|
80 |
+
HasTimeBP=gr.Slider(minimum=4,maximum=12,step=1,label="How many hours before pandemic did the employee work?")
|
81 |
+
HasTimeDP=gr.Slider(minimum=4,maximum=12,step=1,label="How many hours after pandemic did the employee work?")
|
82 |
+
HasTravelTime=gr.Slider(minimum=0.5,maximum=3,step=0.5,label="How many hours does the employee travel for work?")
|
83 |
+
HasEaseOfOnline=gr.Slider(minimum=1,maximum=5,step=1,label="On a scale of 1-5, how easy does the employee find to work online?")
|
84 |
+
HasHomeEnv=gr.Slider(minimum=1,maximum=5,step=1,label="On a scale of 1-5, how comfortable is the employee in home environment?")
|
85 |
+
HasProdInc=gr.Slider(minimum=-1,maximum=1,step=0.5,label="On a scale of -1 to 1, how productive is the employee?")
|
86 |
+
HasSleepBal=gr.Slider(minimum=-1,maximum=1,step=0.5,label="On a scale of -1 to 1, how is the employee's sleep cycle?")
|
87 |
+
HasNewSkill=gr.Slider(minimum=-1,maximum=1,step=0.5,label="On a scale of -1 to 1, how likely is it that the employee learnt a new skill?")
|
88 |
+
HasFamConnect=gr.Slider(minimum=-1,maximum=1,step=0.5,label="On a scale of -1 to 1, how is the employee's family connection impacted?")
|
89 |
+
HasRelaxed=gr.Slider(minimum=-1,maximum=1,step=0.5,label="On a scale of -1 to 1, how relaxed does the employee feel?")
|
90 |
+
HasSelfTime=gr.Slider(minimum=-1,maximum=1,step=0.5,label="On a scale of -1 to 1, how likely does the employee feel the presence of self-time?")
|
91 |
+
HasLikeHW=gr.Slider(minimum=0,maximum=1,step=0.1,label="On a scale of 0 to 1, how much does the employee like working from home?")
|
92 |
+
HasDislikeHW=gr.Slider(minimum=0,maximum=1,step=0.1,label="On a scale of 0 to 1, how much does the employee dislike working from home?")
|
93 |
+
HasCertainDaysHW=gr.Dropdown(["Yes","No","Maybe"],label="Is the employee okay to work in a hybrid setting?")
|
94 |
+
|
95 |
+
output = gr.Textbox(label="Employee Preference Prediction:")
|
96 |
+
|
97 |
+
app = gr.Interface(fn = make_prediction, inputs=[HasAge,HasGender,HasOccupation,HasLineOfWork,HasTimeBP,HasTimeDP,HasTravelTime,HasEaseOfOnline,HasHomeEnv,HasProdInc,HasSleepBal,HasNewSkill,HasFamConnect,HasRelaxed,HasSelfTime,HasLikeHW,HasDislikeHW,HasCertainDaysHW], outputs=output)
|
98 |
+
app.launch()
|