File size: 1,667 Bytes
f04df91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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()