Spaces:
Build error
Build error
thewarriorprincess
commited on
Commit
•
c481785
1
Parent(s):
1c431b0
Update app.py
Browse files
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(
|
17 |
-
new_row = pd.DataFrame.from_dict({'
|
18 |
-
'
|
19 |
-
'
|
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 {"
|
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 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
[
|
66 |
-
[label,local_plot], api_name="
|
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], [
|
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()
|