|
|
import gradio as gr
|
|
|
import joblib
|
|
|
import pandas as pd
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
model = joblib.load("xgboost_cardiovascular_model.pkl")
|
|
|
|
|
|
|
|
|
feature_names = ["age", "ap_hi", "ap_lo", "cholesterol", "gluc", "smoke", "alco", "active", "weight"]
|
|
|
|
|
|
|
|
|
def predict_heart_disease(age, systolic_bp, diastolic_bp, cholesterol, glucose, smoking, alcohol, active, weight):
|
|
|
|
|
|
input_data = pd.DataFrame([[age, systolic_bp, diastolic_bp, cholesterol, glucose, smoking, alcohol, active, weight]], columns=feature_names)
|
|
|
|
|
|
|
|
|
prediction = model.predict(input_data)[0]
|
|
|
|
|
|
|
|
|
return "High Risk of Cardiovascular Disease" if prediction == 1 else "Low Risk of Cardiovascular Disease"
|
|
|
|
|
|
|
|
|
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)
|
|
|
|