Spaces:
Sleeping
Sleeping
Gabriel
commited on
Commit
•
cab83d4
1
Parent(s):
b498f00
app fix
Browse files
app.py
CHANGED
@@ -1,36 +1,116 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
from
|
4 |
-
from torch.nn import functional as F
|
5 |
-
import pandas as pd
|
6 |
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
# def main(inputs):
|
14 |
-
# df = pd.DataFrame(columns=inputs[1:])
|
15 |
-
# df.loc[0] = inputs[1:]
|
16 |
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
iface = gr.Interface(
|
26 |
-
fn=
|
27 |
-
inputs=
|
28 |
-
|
29 |
-
|
30 |
-
],
|
31 |
-
outputs="text",
|
32 |
-
title="Heart Disease identifier",
|
33 |
-
description="Identifies if a person has/will have a heart disease"
|
34 |
)
|
35 |
|
36 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from joblib import load
|
|
|
|
|
4 |
|
5 |
+
rf = load("model.pkl")
|
6 |
|
7 |
+
columns = [
|
8 |
+
"BMI",
|
9 |
+
"Smoking",
|
10 |
+
"AlcoholDrinking",
|
11 |
+
"Stroke",
|
12 |
+
"PhysicalHealth",
|
13 |
+
"MentalHealth",
|
14 |
+
"DiffWalking",
|
15 |
+
"Sex",
|
16 |
+
"AgeEstimate",
|
17 |
+
"Race",
|
18 |
+
"Diabetic",
|
19 |
+
"PhysicalActivity",
|
20 |
+
"GenHealth",
|
21 |
+
"SleepTime",
|
22 |
+
"Asthma",
|
23 |
+
"KidneyDisease",
|
24 |
+
"SkinCancer"
|
25 |
+
]
|
26 |
|
|
|
|
|
|
|
27 |
|
28 |
+
def predict(
|
29 |
+
BMI,
|
30 |
+
Smoking,
|
31 |
+
AlcoholDrinking,
|
32 |
+
Stroke,
|
33 |
+
PhysicalHealth,
|
34 |
+
MentalHealth,
|
35 |
+
DiffWalking,
|
36 |
+
Sex,
|
37 |
+
AgeEstimate,
|
38 |
+
Race,
|
39 |
+
Diabetic,
|
40 |
+
PhysicalActivity,
|
41 |
+
GenHealth,
|
42 |
+
SleepTime,
|
43 |
+
Asthma,
|
44 |
+
KidneyDisease,
|
45 |
+
SkinCancer
|
46 |
+
):
|
47 |
+
data = np.array(
|
48 |
+
[
|
49 |
+
[
|
50 |
+
BMI,
|
51 |
+
Smoking,
|
52 |
+
AlcoholDrinking,
|
53 |
+
Stroke,
|
54 |
+
PhysicalHealth,
|
55 |
+
MentalHealth,
|
56 |
+
DiffWalking,
|
57 |
+
Sex,
|
58 |
+
AgeEstimate,
|
59 |
+
Race+1,
|
60 |
+
Diabetic,
|
61 |
+
PhysicalActivity,
|
62 |
+
GenHealth+1,
|
63 |
+
SleepTime,
|
64 |
+
Asthma,
|
65 |
+
KidneyDisease,
|
66 |
+
SkinCancer
|
67 |
+
]
|
68 |
+
]
|
69 |
+
)
|
70 |
+
pred = rf.predict(data)[0]
|
71 |
+
return {"HeartDisease": pred}
|
72 |
|
73 |
+
|
74 |
+
inputs = [
|
75 |
+
gr.Slider(minimum=0, maximum=150, label="BMI"),
|
76 |
+
gr.Checkbox(label="Smoking"),
|
77 |
+
gr.Checkbox(label="Alcohol Drinking"),
|
78 |
+
gr.Checkbox(label="Stroke"),
|
79 |
+
gr.Number(label="Physical Health"),
|
80 |
+
gr.Number(label="MentalHealth"),
|
81 |
+
gr.Checkbox(label="Diff Walking"),
|
82 |
+
gr.Dropdown(["Female", "Male"], type="index", label="Sex"),
|
83 |
+
gr.Dropdown(['18-24',
|
84 |
+
'25-29',
|
85 |
+
'30-34',
|
86 |
+
'35-39',
|
87 |
+
'40-44',
|
88 |
+
'45-49',
|
89 |
+
'50-54',
|
90 |
+
'55-59',
|
91 |
+
'60-64',
|
92 |
+
'65-69',
|
93 |
+
'70-74',
|
94 |
+
'75-79',
|
95 |
+
'80 or older'], type="index", label="Age Category"),
|
96 |
+
gr.Dropdown(["White", "Black", "Asian", "American Indian/Alaskan Native", "Hispanic", "Other"], type="index", label="Race"),
|
97 |
+
gr.Dropdown(["No", "Yes", "Yes(during pregnancy)", "No, borderline diabetes"], type="index", label="Diebetic"),
|
98 |
+
gr.Checkbox(label="Physical Activity"),
|
99 |
+
gr.Dropdown(["Poor", "Fair", "Good", "Very good", "Excellent"], type="index", label="General Health"),
|
100 |
+
gr.Number(label="Sleep time"),
|
101 |
+
gr.Checkbox(label="Asthma"),
|
102 |
+
gr.Checkbox(label="Kidney Disease"),
|
103 |
+
gr.Checkbox(label="Skin Cancer"),
|
104 |
+
]
|
105 |
+
|
106 |
+
|
107 |
+
output = gr.Label(num_top_classes=1)
|
108 |
|
109 |
iface = gr.Interface(
|
110 |
+
fn=predict,
|
111 |
+
inputs=inputs,
|
112 |
+
outputs=output,
|
113 |
+
description="The purpose of this model is to predict whether or not a person has any heart diseases or not.",
|
|
|
|
|
|
|
|
|
114 |
)
|
115 |
|
116 |
+
iface.launch()
|