File size: 2,832 Bytes
c48b9e5
cab83d4
 
c48b9e5
cab83d4
c48b9e5
cab83d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c48b9e5
c28c5f4
 
c48b9e5
cab83d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c28c5f4
cab83d4
 
 
 
 
 
 
 
 
 
 
 
c28c5f4
 
 
 
c48b9e5
cab83d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c28c5f4
cab83d4
 
 
 
 
 
 
 
 
 
c48b9e5
cab83d4
 
c28c5f4
cab83d4
c48b9e5
 
cab83d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import gradio as gr
import numpy as np
from joblib import load

rf = load("model.pkl")

columns = [
    "BMI",
    "Smoking",
    "AlcoholDrinking",
    "Stroke",
    "PhysicalHealth",
    "MentalHealth",
    "DiffWalking",
    "Sex",
    "AgeEstimate",
    "Race",
    "Diabetic",
    "PhysicalActivity",
    "GenHealth",
    "SleepTime",
    "Asthma",
    "KidneyDisease",
    "SkinCancer"
]

def convert_to_int(s):
    return int(s[:2])

def predict(
    BMI,
    Smoking,
    AlcoholDrinking,
    Stroke,
    PhysicalHealth,
    MentalHealth,
    DiffWalking,
    Sex,
    AgeEstimate,
    Race,
    Diabetic,
    PhysicalActivity,
    GenHealth,
    SleepTime,
    Asthma,
    KidneyDisease,
    SkinCancer
):
    data = np.array(
        [
            [
                BMI,
                Smoking,
                AlcoholDrinking,
                Stroke,
                PhysicalHealth,
                MentalHealth,
                DiffWalking,
                Sex,
                convert_to_int(AgeEstimate),
                Race+1,
                Diabetic,
                PhysicalActivity,
                GenHealth+1,
                SleepTime,
                Asthma,
                KidneyDisease,
                SkinCancer
            ]
        ]
    )
    pred = rf.predict(data)[0]
    if pred == 1:
        return "Has heart disease"
    else:
        return "Does not have any heart disease"


inputs = [
    gr.Slider(minimum=0, maximum=150, label="BMI"),
    gr.Checkbox(label="Smoking"),
    gr.Checkbox(label="Alcohol Drinking"),
    gr.Checkbox(label="Stroke"),
    gr.Number(label="Physical Health"),
    gr.Number(label="MentalHealth"),
    gr.Checkbox(label="Diff Walking"),
    gr.Dropdown(["Female", "Male"], type="index", label="Sex"),
    gr.Dropdown(['18-24',
            '25-29',
            '30-34',
            '35-39',
            '40-44',
            '45-49',
            '50-54',
            '55-59',
            '60-64',
            '65-69',
            '70-74',
            '75-79',
            '80 or older'], label="Age Category"),
    gr.Dropdown(["White", "Black", "Asian", "American Indian/Alaskan Native", "Hispanic", "Other"], type="index", label="Race"),
    gr.Dropdown(["No", "Yes", "Yes(during pregnancy)", "No, borderline diabetes"], type="index", label="Diebetic"),
    gr.Checkbox(label="Physical Activity"),
    gr.Dropdown(["Poor", "Fair", "Good", "Very good", "Excellent"], type="index", label="General Health"),
    gr.Number(label="Sleep time"),
    gr.Checkbox(label="Asthma"),
    gr.Checkbox(label="Kidney Disease"),
    gr.Checkbox(label="Skin Cancer"),
]

iface = gr.Interface(
    fn=predict,
    inputs=inputs,
    outputs="text",
    description="The purpose of this model is to predict whether or not a person has any heart diseases or not.",
)

iface.launch()