import numpy as np import gradio as gr import pickle from sklearn.preprocessing import normalize model = pickle.load(open("model.pkl", 'rb')) def predict(Age, CigsPerDay, Cholestrol, SysBP, DIaBP, BMI, HeartRate, GlucoseLevel, Gender, BpMedication, PrevalentStroke, Smoker): ''' For making predictions ''' list_to_be_normalised = np.array([Age, CigsPerDay, Cholestrol, SysBP, DIaBP, BMI, HeartRate, GlucoseLevel]).reshape(1, -1) normalized = normalize(list_to_be_normalised) boolean = [Gender, BpMedication, PrevalentStroke, Smoker] final_features = np.append(normalized, boolean).reshape(1, -1) prediction = model.predict(final_features) if prediction == 1: return "problem" else: return "healthy" iface = gr.Interface( fn=predict, inputs=[ gr.inputs.Number(label="Age (Enter Age)", default=40), gr.inputs.Number(label="CigsPerDay (Enter Cigarettes Per Day)", default=10), gr.inputs.Number(label="Cholesterol (Enter Cholesterol Level)", default=200), gr.inputs.Number(label="SysBP (Enter Systolic Blood Pressure)", default=120), gr.inputs.Number(label="DIaBP (Enter Diastolic Blood Pressure)", default=80), gr.inputs.Number(label="BMI (Enter Body Mass Index)", default=25), gr.inputs.Number(label="HeartRate (Enter Heart Rate)", default=70), gr.inputs.Number(label="GlucoseLevel (Enter Glucose Level)", default=100), gr.inputs.Checkbox(label="Gender (Select Gender)"), gr.inputs.Checkbox(label="BpMedication (Select Blood Pressure Medication)"), gr.inputs.Checkbox(label="PrevalentStroke (Select Prevalent Stroke)"), gr.inputs.Checkbox(label="Smoker (Select Smoker)"), ], outputs=gr.outputs.Textbox(label="Prediction"), ) iface.launch()