IbraahimLab's picture
Create app.py
f04df91 verified
import gradio as gr
import joblib
import numpy as np
# Load your trained model
model = joblib.load("random_forest_model.pkl")
# Define prediction function
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"
# Define Gradio inputs and interface
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()