File size: 1,433 Bytes
13c1b9f
 
 
37b924f
 
 
 
 
13c1b9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)