|
import gradio as gr |
|
import joblib |
|
import numpy as np |
|
|
|
|
|
model = joblib.load("random_forest_model.pkl") |
|
|
|
|
|
def predict_heart_disease(age, sex, cp, trestbps, chol, fbs, |
|
restecg, thalach, exang, oldpeak, slope, ca, thal): |
|
features = np.array([[age, sex, cp, trestbps, chol, fbs, |
|
restecg, thalach, exang, oldpeak, slope, ca, thal]]) |
|
prediction = model.predict(features)[0] |
|
if prediction == 1: |
|
return "π¨ High Risk of Heart Disease" |
|
else: |
|
return "β
Low Risk of Heart Disease" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_heart_disease, |
|
inputs=[ |
|
gr.Number(label="Age", value=50), |
|
gr.Radio([0, 1], label="Sex (0 = Female, 1 = Male)"), |
|
gr.Radio([0, 1, 2, 3], label="Chest Pain Type"), |
|
gr.Number(label="Resting Blood Pressure", value=120), |
|
gr.Number(label="Serum Cholesterol", value=200), |
|
gr.Radio([0, 1], label="Fasting Blood Sugar > 120mg/dl"), |
|
gr.Radio([0, 1, 2], label="Resting ECG"), |
|
gr.Number(label="Max Heart Rate", value=150), |
|
gr.Radio([0, 1], label="Exercise-Induced Angina"), |
|
gr.Slider(0.0, 7.0, step=0.1, label="ST Depression (Oldpeak)"), |
|
gr.Radio([0, 1, 2], label="Slope"), |
|
gr.Radio([0, 1, 2, 3, 4], label="Number of Major Vessels (ca)"), |
|
gr.Radio([1, 2, 3], label="Thalassemia (1: Normal, 2: Fixed, 3: Reversible)") |
|
], |
|
outputs="text", |
|
title="π Heart Disease Prediction", |
|
description="Enter the patient's information to predict heart disease risk.", |
|
) |
|
|
|
iface.launch() |
|
|