Gabriel
app fix
cab83d4
raw
history blame
2.75 kB
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 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,
AgeEstimate,
Race+1,
Diabetic,
PhysicalActivity,
GenHealth+1,
SleepTime,
Asthma,
KidneyDisease,
SkinCancer
]
]
)
pred = rf.predict(data)[0]
return {"HeartDisease": pred}
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'], type="index", 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"),
]
output = gr.Label(num_top_classes=1)
iface = gr.Interface(
fn=predict,
inputs=inputs,
outputs=output,
description="The purpose of this model is to predict whether or not a person has any heart diseases or not.",
)
iface.launch()