File size: 2,099 Bytes
c4752ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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()