vidhiparikh's picture
Update app.py
216a819
raw
history blame contribute delete
No virus
5.74 kB
import pickle
import gradio as gr
#from sklearn.metrics import classification_report
#from sklearn.model_selection import train_test_split
#from sklearn.linear_model import LogisticRegression
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):
#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)
print(age1+gender1+occupation1+line_of_work1+certaindays_hw1)
if age1=="18":
age1=int(1)
elif age1=="19-25":
age1=int(0)
elif age1=="33-40":
age1=int(2)
elif age1=="60+":
age1=int(3)
elif age1=="26-32":
age1=int(4)
elif age1=="40-50":
age1=int(5)
else: age1=int(6)
print(str(age1))
if gender1=="Male":
gender1=int(0)
elif gender1=="Female":
gender1=int(1)
else: gender1=int(2)
print(str(gender1))
if occupation1=="Student in College":
occupation1=int(0)
elif occupation1=="Student in School":
occupation1=int(1)
elif occupation1=="Working Professional":
occupation1=int(2)
elif occupation1=="Entrepreneur":
occupation1=int(3)
elif occupation1=="Retired/Senior Citizen":
occupation1=int(4)
elif occupation1=="Homemaker":
occupation1=int(5)
else: occupation1=int(6)
print(str(occupation1))
if line_of_work1=="Teaching":
line_of_work1=int(0)
elif line_of_work1=="Engineering":
line_of_work1=int(1)
elif line_of_work1=="Management":
line_of_work1=int(2)
elif line_of_work1=="APSPDCL":
line_of_work1=int(3)
elif line_of_work1=="Architecture":
line_of_work1=int(4)
elif line_of_work1=="Other":
line_of_work1=int(5)
else: line_of_work1=int(6)
print(str(line_of_work1))
if certaindays_hw1=="Yes":
certaindays_hw1=int(0)
elif certaindays_hw1=="No":
certaindays_hw1=int(1)
else: certaindays_hw1=int(2)
print(str(certaindays_hw1))
with open("covid_psyc_model.pkcls", "rb") as f:
#Then feeds our data into the model, then sets the "preds" variable to the prediction output for our class variable, which is price.
clf = pickle.load(f)
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]])
if preds == 0:
return "Complete Physical Attendance"
elif preds== 1:
return "Work/study from home"
else:
return "Please check and re-enter your inputs"
#Finally, we send the prediction to the website.
return preds
HasAge=gr.Dropdown(["18","19-25","26-32","33-40","40-50","50-60","60+"],label="Please select your age range")
HasGender=gr.Dropdown(["Male","Female","Prefer not to say"],label="Please select your gender")
HasOccupation=gr.Dropdown(["Student in College", "Student in School", "Working Professional",
"Entrepreneur", "Retired/Senior Citizen", "Homemaker",
"Currently Out of Work",
"Medical Professional aiding efforts against COVID-19"],label="Please select your occupation")
HasLineOfWork=gr.Dropdown(["Teaching","Engineering","Management","APSPDCL","Architecture","Other","Government Employee"],label="Please select your line of work")
HasTimeBP=gr.Slider(minimum=4,maximum=12,step=1,label="How many hours before pandemic did the employee work?")
HasTimeDP=gr.Slider(minimum=4,maximum=12,step=1,label="How many hours after pandemic did the employee work?")
HasTravelTime=gr.Slider(minimum=0.5,maximum=3,step=0.5,label="How many hours does the employee travel for work?")
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?")
HasHomeEnv=gr.Slider(minimum=1,maximum=5,step=1,label="On a scale of 1-5, how comfortable is the employee in home environment?")
HasProdInc=gr.Slider(minimum=-1,maximum=1,step=0.5,label="On a scale of -1 to 1, how productive is the employee?")
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?")
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?")
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?")
HasRelaxed=gr.Slider(minimum=-1,maximum=1,step=0.5,label="On a scale of -1 to 1, how relaxed does the employee feel?")
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?")
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?")
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?")
HasCertainDaysHW=gr.Dropdown(["Yes","No","Maybe"],label="Is the employee okay to work in a hybrid setting?")
output = gr.Textbox(label="Employee Preference Prediction:")
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)
app.launch()