Spaces:
Sleeping
Sleeping
import gradio as gr | |
import numpy as np | |
import pickle | |
# Load the trained model | |
with open('heart_disease_model.pkl', 'rb') as file: | |
model = pickle.load(file) | |
# Define the prediction function | |
def predict_heart_disease(male, age, currentSmoker, cigsPerDay, BPMeds, prevalentStroke, prevalentHyp, diabetes, BMI): | |
male = 1 if male == "Male" else 0 | |
currentSmoker = 1 if currentSmoker else 0 | |
BPMeds = 1 if BPMeds else 0 | |
prevalentStroke = 1 if prevalentStroke else 0 | |
prevalentHyp = 1 if prevalentHyp else 0 | |
diabetes = 1 if diabetes else 0 | |
input_data = np.array([[male, age, currentSmoker, cigsPerDay, BPMeds, prevalentStroke, prevalentHyp, diabetes, BMI]]) | |
prediction = model.predict(input_data) | |
return 'Heart Disease' if prediction[0] == 1 else 'No Heart Disease' | |
# Define the input components | |
inputs = [ | |
gr.Radio(choices=["Male","Female"], label="Sex"), | |
gr.Number(label="Age"), | |
gr.Checkbox(label="Do you smoke?"), | |
gr.Number(label="Number of ciggerates a day"), | |
gr.Checkbox(label="Do you take BP medicines?"), | |
gr.Checkbox(label="Have you had strokes previously?"), | |
gr.Checkbox(label="Have you had High BP previously?"), | |
gr.Checkbox(label="Do you have Diabetes?"), | |
gr.Number(value=float, label="BMI") | |
] | |
# Define the output component | |
outputs = gr.Textbox(label="Prediction") | |
# Create and launch the Gradio interface | |
gr.Interface(fn=predict_heart_disease, inputs=inputs, outputs=outputs).launch() |