Spaces:
Build error
Build error
dellazhangyd
commited on
Commit
·
e5c67fa
1
Parent(s):
4a9cbbf
Update app.py
Browse files
app.py
CHANGED
@@ -13,10 +13,10 @@ loaded_model = pickle.load(open("h22_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 |
|
@@ -46,12 +46,18 @@ with gr.Blocks(title=title) as demo:
|
|
46 |
gr.Markdown("""---""")
|
47 |
gr.Markdown(description2)
|
48 |
gr.Markdown("""---""")
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
submit_btn = gr.Button("Analyze")
|
56 |
|
57 |
with gr.Column(visible=True) as output_col:
|
@@ -60,11 +66,11 @@ with gr.Blocks(title=title) as demo:
|
|
60 |
|
61 |
submit_btn.click(
|
62 |
main_func,
|
63 |
-
[
|
64 |
-
[label,local_plot], api_name="
|
65 |
)
|
66 |
|
67 |
gr.Markdown("### Click on any of the examples below to see how it works:")
|
68 |
-
gr.Examples([[4,4,4,4,5,5], [5,4,5,4,4,4]], [
|
69 |
|
70 |
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 |
|
|
|
46 |
gr.Markdown("""---""")
|
47 |
gr.Markdown(description2)
|
48 |
gr.Markdown("""---""")
|
49 |
+
age = gr.Slider(label="age Score", minimum=15, maximum=90, value=40, step=5)
|
50 |
+
sex = gr.Slider(label="sex Score", minimum=0, maximum=1, value=1, step=1)
|
51 |
+
cp = gr.Slider(label="cp Score", minimum=1, maximum=5, value=4, step=1)
|
52 |
+
chol = gr.Slider(label="chol Score", minimum=1, maximum=5, value=4, step=1)
|
53 |
+
fbs = gr.Slider(label="fbs Score", minimum=1, maximum=5, value=4, step=1)
|
54 |
+
restecg = gr.Slider(label="restecg Score", minimum=1, maximum=5, value=4, step=1)
|
55 |
+
thalachh = gr.Slider(label="thalachh Score", minimum=1, maximum=5, value=4, step=1)
|
56 |
+
exng = gr.Slider(label="exng Score", minimum=1, maximum=5, value=4, step=1)
|
57 |
+
oldpeak = gr.Slider(label="oldpeak Score", minimum=1, maximum=5, value=4, step=1)
|
58 |
+
slp = gr.Slider(label="slp Score", minimum=1, maximum=5, value=4, step=1)
|
59 |
+
caa = gr.Slider(label="caa Score", minimum=1, maximum=5, value=4, step=1)
|
60 |
+
thall = gr.Slider(label="thall Score", minimum=1, maximum=5, value=4, step=1)
|
61 |
submit_btn = gr.Button("Analyze")
|
62 |
|
63 |
with gr.Column(visible=True) as output_col:
|
|
|
66 |
|
67 |
submit_btn.click(
|
68 |
main_func,
|
69 |
+
[age, sex, cp, trtbps, chol, fbs, restecg, thalachh, exng, oldpeak, slp, caa, thall],
|
70 |
+
[label,local_plot], api_name="Heart_Predictor"
|
71 |
)
|
72 |
|
73 |
gr.Markdown("### Click on any of the examples below to see how it works:")
|
74 |
+
gr.Examples([[24,0,3,5,6,8,4,4,4,4,5,5,6], [5,2,3,4,2,3,3,4,2,4,5,4,4,4]], [age, sex, cp, trtbps, chol, fbs, restecg, thalachh, exng, oldpeak, slp, caa, thall], [label,local_plot], main_func, cache_examples=True)
|
75 |
|
76 |
demo.launch()
|