demo-stroke / app.py
Debmalya's picture
.
78d7ec0
import gradio as gr
import pycaret
from pycaret.classification import *
import pandas as pd
import category_encoders as ce
healthcare_stroke_data = pd.read_csv("healthcare-dataset-stroke-data.csv")
encoder= ce.OrdinalEncoder(cols=['gender'],return_df=True, mapping=[{'col':'gender', 'mapping':{0: 1, 1: 2,'Other': 3}}])
healthcare_stroke_data['gender'] = encoder.fit_transform(healthcare_stroke_data['gender'])
encoder= ce.OrdinalEncoder(cols=['work_type'],return_df=True, mapping=[{'col':'work_type', 'mapping':{0: 1, 1: 2, 'children': 3, '2': 4, 'Never_worked': 5}}])
healthcare_stroke_data['work_type'] = encoder.fit_transform(healthcare_stroke_data['work_type'])
s = setup(data = healthcare_stroke_data, target = 'stroke', fix_imbalance = True, session_id=123)
best = compare_models()
compare_model_results = pull()
model = gr.inputs.Dropdown(list(compare_model_results['Model']),label="Model")
gender = gr.inputs.Dropdown(choices=["Male", "Female"],label = 'gender')
age = gr.inputs.Slider(minimum=1, maximum=100, default=data['age'].mean(), label = 'age')
hypertension = gr.inputs.Dropdown(choices=["1", "0"],label = 'hypertension')
heart_disease = gr.inputs.Dropdown(choices=["1", "0"],label ='heart_disease')
ever_married = gr.inputs.Dropdown(choices=["Yes", "No"], label ='ever_married')
work_type = gr.inputs.Dropdown(choices=["children", "Govt_job","Never_worked","Private","Self-employed"],label = 'work_type')
Residence_type = gr.inputs.Dropdown(choices=["Urban", "Rural"],label = 'Residence_type')
avg_glucose_level = gr.inputs.Slider(minimum=-55, maximum=300, default=data['avg_glucose_level'].mean(), label = 'avg_glucose_level')
bmi = gr.inputs.Slider(minimum=-10, maximum=100, default=data['bmi'].mean(), label = 'bmi')
smoking_status = gr.inputs.Dropdown(choices=["Unknown", "smokes","never_smoked", "formerly_smoked"], label ='smoking_status')
gr.Interface(predict,[model, gender, age, hypertension, heart_disease, ever_married, work_type, Residence_type, avg_glucose_level, bmi, smoking_status], "label",live=True).launch()