|
import streamlit as st |
|
import pickle |
|
import numpy as np |
|
|
|
|
|
|
|
|
|
try: |
|
with open('heart_disease_model.pkl', 'rb') as file: |
|
loaded_model = pickle.load(file) |
|
print("Model loaded successfully!") |
|
except FileNotFoundError: |
|
print("Error: The file 'heart_disease_model.pkl' was not found.") |
|
except Exception as e: |
|
print("An error occurred while loading the model:", e) |
|
|
|
|
|
|
|
def predict_cancer(input_data): |
|
input_data_reshaped = np.asarray(input_data).reshape(1, -1) |
|
prediction = loaded_model.predict(input_data_reshaped) |
|
return prediction[0] |
|
|
|
|
|
def main(): |
|
st.set_page_config(layout="centered") |
|
st.title('Heart disease Prediction') |
|
st.markdown('Enter the values for the input features:') |
|
feature_names = [ |
|
'age', |
|
'sex', |
|
'cp', |
|
'trestbps ', |
|
'chol', |
|
'fbs' |
|
'restecg', |
|
'thalach', |
|
'exang', |
|
'oldpeak', |
|
'ca', |
|
'thal', |
|
'target', |
|
|
|
] |
|
col1, col2 = st.columns([2, 1]) |
|
with col1: |
|
input_data = [] |
|
for feature_name in feature_names: |
|
input_value = st.number_input(feature_name, step=0.01,) |
|
input_data.append(float(input_value)) |
|
|
|
if st.button('Predict'): |
|
prediction = predict_cancer(input_data) |
|
if prediction == 0: |
|
st.error('The Person has Heart Disease') |
|
else: |
|
st.success('The Person does not have Heart Disease') |
|
with col2: |
|
st.markdown('**IF YES**') |
|
st.write('the person has heart disease, and he sholuld want to take medical care immediately. ' |
|
'It requires prompt medical attention and treatment.') |
|
|
|
st.markdown('**NO**') |
|
st.write('the person do not have any heart related issues. ' |
|
'and no need to worry.') |
|
|
|
st.markdown('**NOTE:** The prediction provided by this app is for informational purposes only. ' |
|
'It is not a substitute for professional medical advice or diagnosis.') |
|
|
|
st.markdown('<br>', unsafe_allow_html=True) |
|
|
|
|
|
if __name__ == '__main__': |
|
main() |