|
|
import gradio as gr |
|
|
import numpy as np |
|
|
import joblib |
|
|
|
|
|
|
|
|
model = joblib.load("heart_disease_model.pkl") |
|
|
|
|
|
feature_names = [ |
|
|
"age", "sex", "cp", "trestbps", "chol", "fbs", |
|
|
"restecg", "thalach", "exang", "oldpeak", "slope", "ca", "thal" |
|
|
] |
|
|
|
|
|
def predict_heart_disease(age, sex, cp, trestbps, chol, fbs, restecg, thalach, |
|
|
exang, oldpeak, slope, ca, thal): |
|
|
input_data = np.array([[age, sex, cp, trestbps, chol, fbs, restecg, thalach, |
|
|
exang, oldpeak, slope, ca, thal]]) |
|
|
prediction = model.predict(input_data) |
|
|
if prediction[0] == 0: |
|
|
return "The Person does not have a Heart Disease" |
|
|
else: |
|
|
return "The Person has Heart Disease" |
|
|
|
|
|
inputs = [gr.Number(label=feature) for feature in feature_names] |
|
|
|
|
|
demo = gr.Interface(fn=predict_heart_disease, inputs=inputs, outputs="text", |
|
|
title="Heart Disease Prediction") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|