Nisha2004 commited on
Commit
21f6288
1 Parent(s): 47eb924

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import numpy as np
4
+
5
+ loaded_model = None # Define the variable outside the try block
6
+
7
+ try:
8
+ with open('heart_disease_model.pkl', 'rb') as file:
9
+ loaded_model = pickle.load(file)
10
+ print("Model loaded successfully!")
11
+ except FileNotFoundError:
12
+ print("Error: The file 'heart_disease_model.pkl' was not found.")
13
+ except Exception as e:
14
+ print("An error occurred while loading the model:", e)
15
+
16
+ def predict_heart_disease(input_data):
17
+ if loaded_model is None:
18
+ return None # Handle case where the model wasn't loaded successfully
19
+ input_data_reshaped = np.asarray(input_data).reshape(1, -1)
20
+ prediction = loaded_model.predict(input_data_reshaped)
21
+ return prediction[0]
22
+
23
+ def main():
24
+ st.set_page_config(layout="centered")
25
+ st.title('Heart Disease Prediction')
26
+ st.markdown('Enter the values for the input features:')
27
+ feature_names = [
28
+ 'age',
29
+ 'sex',
30
+ 'cp',
31
+ 'trestbps',
32
+ 'chol',
33
+ 'fbs',
34
+ 'restecg',
35
+ 'thalach',
36
+ 'exang',
37
+ 'oldpeak',
38
+ 'ca',
39
+ 'thal',
40
+ 'target',
41
+ ]
42
+
43
+ col1, col2 = st.columns([2, 1])
44
+
45
+ with col1:
46
+ input_data = []
47
+ for feature_name in feature_names:
48
+ input_value = st.number_input(feature_name, step=0.01)
49
+ input_data.append(float(input_value))
50
+
51
+ if st.button('Predict'):
52
+ prediction = predict_heart_disease(input_data)
53
+ if prediction is None:st.warning('The Person has Heart Disease')
54
+ elif prediction == 0:
55
+ st.error('The Person has Heart Disease')
56
+ else:
57
+ st.success('The Person does not have Heart Disease')
58
+
59
+ with col2:
60
+ st.markdown('**IF YES**')
61
+ st.write('The person has heart disease, and they should seek medical care immediately. '
62
+ 'It requires prompt medical attention and treatment.')
63
+
64
+ st.markdown('**NO**')
65
+ st.write('The person does not have any heart-related issues. '
66
+ 'There is no need to worry.')
67
+
68
+ st.markdown('**NOTE:** The prediction provided by this app is for informational purposes only. '
69
+ 'It is not a substitute for professional medical advice or diagnosis.')
70
+
71
+ st.markdown('<br>', unsafe_allow_html=True)
72
+
73
+ if __name__ == '__main__':
74
+ main()