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 == "Yes" else 0 BPMeds = 1 if BPMeds == "Yes" else 0 prevalentStroke = 1 if prevalentStroke == "Yes" else 0 prevalentHyp = 1 if prevalentHyp == "Yes" else 0 diabetes = 1 if diabetes == "Yes" 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.Text(label="Do you smoke? (Yes/No)"), gr.Number(label="Number of ciggerates a day"), gr.Text(label="Do you take BP medicines?"), gr.text(label="Have you hade strokes previously?"), gr.text(label="Have you hade High BP previously?"), gr.text(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()