arittrabag's picture
Add 3 Files
716e241 verified
import gradio as gr
import joblib
import pandas as pd
import numpy as np
# Load the saved XGBoost model
model = joblib.load("xgboost_cardiovascular_model.pkl")
# Define feature names (same as training)
feature_names = ["age", "ap_hi", "ap_lo", "cholesterol", "gluc", "smoke", "alco", "active", "weight"]
# Define the prediction function
def predict_heart_disease(age, systolic_bp, diastolic_bp, cholesterol, glucose, smoking, alcohol, active, weight):
# Convert inputs into a DataFrame
input_data = pd.DataFrame([[age, systolic_bp, diastolic_bp, cholesterol, glucose, smoking, alcohol, active, weight]], columns=feature_names)
# Make prediction
prediction = model.predict(input_data)[0]
# Return result
return "High Risk of Cardiovascular Disease" if prediction == 1 else "Low Risk of Cardiovascular Disease"
# Define Gradio interface
inputs = [
gr.Slider(29, 64, step=1, label="Age (in years)"),
gr.Slider(90, 180, step=1, label="Systolic Blood Pressure (ap_hi)"),
gr.Slider(60, 120, step=1, label="Diastolic Blood Pressure (ap_lo)"),
gr.Radio([1, 2, 3], label="Cholesterol Level (1=Normal, 2=Above Normal, 3=Well Above Normal)"),
gr.Radio([1, 2, 3], label="Glucose Level (1=Normal, 2=Above Normal, 3=Well Above Normal)"),
gr.Radio([0, 1], label="Smoking (0=No, 1=Yes)"),
gr.Radio([0, 1], label="Alcohol Intake (0=No, 1=Yes)"),
gr.Radio([0, 1], label="Physically Active (0=No, 1=Yes)"),
gr.Slider(40, 180, step=1, label="Weight (in kg)")
]
output = gr.Textbox(label="Cardiovascular Disease Risk")
gr.Interface(fn=predict_heart_disease, inputs=inputs, outputs=output, title="Heart Disease Risk Predictor",
description="Enter your health details to estimate your cardiovascular disease risk using AI.",
theme="compact").launch(share=True)