import joblib import numpy as np # Load the trained heart disease model heart_model = joblib.load("heart_model.joblib") def encode_sex(sex): return 1 if sex == "Male" else 0 def predict_heart(age, sex, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal): # Encode 'sex' from string to numeric sex_encoded = encode_sex(sex) # Create feature array (13 features) features = np.array([[age, sex_encoded, cp, trestbps, chol, fbs, restecg, thalach, exang, oldpeak, slope, ca, thal]]) # Predict using the loaded model prediction = heart_model.predict(features)[0] return "Heart Disease Detected" if prediction == 1 else "No Heart Disease Detected"