Healthy_heart / app.py
alibidaran's picture
Update app.py
37b924f
raw
history blame
1.43 kB
import pickle
import gradio as gr
import numpy as np
import pandas as pd
df=pd.read_csv("heart.csv")
encode_sex={name:i for i,name in enumerate(df["Sex"].unique())}
encode_chest={name:i for i,name in enumerate(df["ChestPainType"].unique())}
encode_slope={name:i for i, name in enumerate(df['ST_Slope'].unique())}
file_name='heart_disease_model.sav'
model=pickle.load(open('heart_disease_model.sav','rb'))
def show_output(age,sex,chestpain,maxhr,st_slope,cholestrol):
values=dict()
values['Age']=age
values['Sex']=encode_sex[sex]
values['ChestPainType']=encode_chest[chestpain]
values["MaxHR"]=maxhr
values["ST_Slope"]=encode_slope[st_slope]
values['Cholestrol']=cholestrol
encoded=pd.DataFrame.from_dict([values])
x=encoded.to_numpy()
x=x.reshape(1,-1)
x=(x-x.min())/(x.max()-x.min())
preds=model.predict_proba(x)
return {'healthy':preds[0][0],'Diseased':preds[0][1]}
inputs = [gr.Slider(1,120,2,label='age'),
gr.Dropdown(df["Sex"].unique().tolist(),label='sex'),
gr.Dropdown(df["ChestPainType"].unique().tolist(),label='chestpain'),
gr.Slider(1,200,1,label='maxhr'),
gr.Dropdown(df['ST_Slope'].unique().tolist(),label='st_slope'),
gr.Slider(1,400,1,label='cholestrol'),
]
demo=gr.Interface(show_output,inputs=inputs,outputs='label',theme=gr.themes.Default(neutral_hue='red',secondary_hue=gr.themes.colors.cyan,primary_hue='red'))
demo.launch(debug=True)