Simrandhiman's picture
Update app.py
3f0ae21 verified
import gradio as gr
import numpy as np
import joblib
# Load the saved logistic regression model file (place model.pkl in Space repo)
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()