thewarriorprincess commited on
Commit
c481785
1 Parent(s): 1c431b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -13,10 +13,10 @@ loaded_model = pickle.load(open("heart_xgb.pkl", 'rb'))
13
  explainer = shap.Explainer(loaded_model) # PLEASE DO NOT CHANGE THIS.
14
 
15
  # Create the main function for server
16
- def main_func(ValueDiversity,AdequateResources,Voice,GrowthAdvancement,Workload,WorkLifeBalance):
17
- new_row = pd.DataFrame.from_dict({'ValueDiversity':ValueDiversity,'AdequateResources':AdequateResources,
18
- 'Voice':Voice,'GrowthAdvancement':GrowthAdvancement,'Workload':Workload,
19
- 'WorkLifeBalance':WorkLifeBalance}, orient = 'index').transpose()
20
 
21
  prob = loaded_model.predict_proba(new_row)
22
 
@@ -29,7 +29,7 @@ def main_func(ValueDiversity,AdequateResources,Voice,GrowthAdvancement,Workload,
29
  local_plot = plt.gcf()
30
  plt.close()
31
 
32
- return {"Leave": float(prob[0][0]), "Stay": 1-float(prob[0][0])}, local_plot
33
 
34
  # Create the UI
35
  title = "**Heart Attack Predictor & Interpreter** 🪐"
@@ -48,12 +48,20 @@ with gr.Blocks(title=title) as demo:
48
  gr.Markdown("""---""")
49
  gr.Markdown(description2)
50
  gr.Markdown("""---""")
51
- ValueDiversity = gr.Slider(label="ValueDiversity Score", minimum=1, maximum=5, value=4, step=1)
52
- AdequateResources = gr.Slider(label="AdequateResources Score", minimum=1, maximum=5, value=4, step=1)
53
- Voice = gr.Slider(label="Voice Score", minimum=1, maximum=5, value=4, step=1)
54
- GrowthAdvancement = gr.Slider(label="GrowthAdvancement Score", minimum=1, maximum=5, value=4, step=1)
55
- Workload = gr.Slider(label="Workload Score", minimum=1, maximum=5, value=4, step=1)
56
- WorkLifeBalance = gr.Slider(label="WorkLifeBalance Score", minimum=1, maximum=5, value=4, step=1)
 
 
 
 
 
 
 
 
57
  submit_btn = gr.Button("Analyze")
58
 
59
  with gr.Column(visible=True) as output_col:
@@ -62,11 +70,11 @@ with gr.Blocks(title=title) as demo:
62
 
63
  submit_btn.click(
64
  main_func,
65
- [ValueDiversity,AdequateResources,Voice,GrowthAdvancement,Workload,WorkLifeBalance],
66
- [label,local_plot], api_name="Employee_Turnover"
67
  )
68
 
69
  gr.Markdown("### Click on any of the examples below to see how it works:")
70
- gr.Examples([[4,4,4,4,5,5], [5,4,5,4,4,4]], [ValueDiversity,AdequateResources,Voice,GrowthAdvancement,Workload,WorkLifeBalance], [label,local_plot], main_func, cache_examples=True)
71
 
72
  demo.launch()
 
13
  explainer = shap.Explainer(loaded_model) # PLEASE DO NOT CHANGE THIS.
14
 
15
  # Create the main function for server
16
+ def main_func(age,sex,cp,trtbps,chol,fbs,restecg,thalachh,exng,oldpeak,slp,caa,thall):
17
+ new_row = pd.DataFrame.from_dict({'age':age,'sex':sex,
18
+ 'cp':cp,'trtbps':trtbps,'chol':chol,
19
+ 'fbs':fbs, 'restecg':restecg, 'thalachh':thalachh, 'exng':exng, 'oldpeak':oldpeak, 'slp':slp, 'caa':caa, 'thall':thall}, orient = 'index').transpose()
20
 
21
  prob = loaded_model.predict_proba(new_row)
22
 
 
29
  local_plot = plt.gcf()
30
  plt.close()
31
 
32
+ return {"Low Change": float(prob[0][0]), "High Chance": 1-float(prob[0][0])}, local_plot
33
 
34
  # Create the UI
35
  title = "**Heart Attack Predictor & Interpreter** 🪐"
 
48
  gr.Markdown("""---""")
49
  gr.Markdown(description2)
50
  gr.Markdown("""---""")
51
+ age = gr.Slider(label="age Score", minimum=15, maximum=90, value=4, step=1)
52
+ sex = gr.Slider(label="sex Score", minimum=1, maximum=5, value=4, step=1)
53
+ cp = gr.Slider(label="cp Score", minimum=1, maximum=5, value=4, step=1)
54
+ trtbps = gr.Slider(label="GrowthAdvancement Score", minimum=1, maximum=5, value=4, step=1)
55
+ chol = gr.Slider(label="chol Score", minimum=1, maximum=5, value=4, step=1)
56
+ fbs = gr.Slider(label="fbs Score", minimum=1, maximum=5, value=4, step=1)
57
+ restecg = gr.Slider(label="restecg Score", minimum=1, maximum=5, value=4, step=1)
58
+ thalacch = gr.Slider(label="thalacch Score", minimum=1, maximum=5, value=4, step=1)
59
+ exng = gr.Slider(label="exng Score", minimum=1, maximum=5, value=4, step=1)
60
+ oldpeak = gr.Slider(label="oldpeak Score", minimum=1, maximum=5, value=4, step=1)
61
+ slp = gr.Slider(label="slp Score", minimum=1, maximum=5, value=4, step=1)
62
+ caa = gr.Slider(label="caa Score", minimum=1, maximum=5, value=4, step=1)
63
+ thall = gr.Slider(label="thall Score", minimum=1, maximum=5, value=4, step=1)
64
+
65
  submit_btn = gr.Button("Analyze")
66
 
67
  with gr.Column(visible=True) as output_col:
 
70
 
71
  submit_btn.click(
72
  main_func,
73
+ [age,sex,cp,trtbps,chol,fbs,restecg,thalachh,exng,oldpeak,slp,caa,thall],
74
+ [label,local_plot], api_name="Heart_Predictor"
75
  )
76
 
77
  gr.Markdown("### Click on any of the examples below to see how it works:")
78
+ gr.Examples([[24,0,4,4,4,4,5,5,1,2,3], [24,0,4,4,3,2,5,5,1,2,3]], [age,sex,cp,trtbps,chol,fbs,restecg,thalachh,exng,oldpeak,slp,caa,thall], [label,local_plot], main_func, cache_examples=True)
79
 
80
  demo.launch()