Abhisikta-26201 commited on
Commit
ab3924d
·
verified ·
1 Parent(s): da09bd0

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +114 -0
  2. requirements.txt +46 -0
  3. rfc.pkl +3 -0
app.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ #import pandas as pd
3
+ #from sklearn.preprocessing import MinMaxScaler, OneHotEncoder, PowerTransformer, OrdinalEncoder
4
+ from sklearn.compose import ColumnTransformer
5
+ from sklearn.pipeline import Pipeline
6
+ from sklearn.metrics import accuracy_score, confusion_matrix, ConfusionMatrixDisplay
7
+ from sklearn.ensemble import RandomForestClassifier
8
+ import streamlit as st
9
+ import pickle
10
+
11
+ # Page configuration
12
+ st.set_page_config(page_title="Heart Disease Prediction App", page_icon="\u2764\ufe0f", layout="wide")
13
+
14
+ # Custom styles
15
+ st.markdown(
16
+ """
17
+ <style>
18
+ .main {background-color: #f0f2f6;}
19
+ h1 {color: #d63384; text-align: center; font-family: 'Arial', sans-serif;}
20
+ .stButton > button {background-color: #d63384; color: white; border-radius: 10px;}
21
+ .stButton > button:hover {background-color: #a02364;}
22
+ </style>
23
+ """,
24
+ unsafe_allow_html=True,
25
+ )
26
+
27
+ # Header
28
+ st.title("\u2764\ufe0f Heart Disease Prediction App \u2764\ufe0f")
29
+ st.image("https://huggingface.co/spaces/Abhisikta-26201/Heart_Disease_Classification/resolve/main/IMG_20241212_011225.jpg", use_container_width=True)
30
+
31
+ # Input fields
32
+ with st.form("input_form"):
33
+ st.header("Enter Patient Information")
34
+
35
+ # Column layout for inputs
36
+ col1, col2 = st.columns(2)
37
+
38
+ with col1:
39
+ age = st.number_input("Age", min_value=0, max_value=120, step=1, format="%d", help="Enter the age of the patient (in Years)")
40
+ gender = st.radio("Gender", ['Male', 'Female'], horizontal=True, help="Select the patient's gender")
41
+ chestpain = st.selectbox(
42
+ "Chest Pain Type",
43
+ ['No Data Available','Non-anginal_pain', 'Typical_angina', 'Atypical_angina','Asymptomatic'],
44
+ help="Select the type of chest pain",
45
+ )
46
+ chestpain = np.nan if chestpain == 'No Data Available' else chestpain
47
+ restingBP = st.number_input("Resting Blood Pressure", min_value = (-1), max_value=300, step=1, format="%d", help="Enter the resting blood pressure (in mmHg), '-1' corresponds to unknown resting blood pressure")
48
+ restingBP = np.nan if restingBP == (-1) else restingBP
49
+
50
+ with col2:
51
+ serum_cholesterol = st.number_input(
52
+ "Serum Cholesterol", min_value=(-1), max_value=1000, step=1, format="%d", help="Enter serum cholesterol level (in mg/dL), '-1' corresponds to unknown serum choesterol level"
53
+ )
54
+ serum_cholesterol = np.nan if serum_cholesterol == (-1) else serum_cholesterol
55
+ fasting_blood_sugar = st.radio(
56
+ "Fasting Blood Sugar > 120 mg/dL", ['Yes', 'No','No Data Available'], horizontal=True, help ="Indicate if fasting blood sugar is greater than 120 mg/dL"
57
+ )
58
+ fasting_blood_sugar = np.nan if fasting_blood_sugar == 'No Data Available' else fasting_blood_sugar
59
+ restingrelectro = st.selectbox(
60
+ "Resting Electrocardiographic Results",
61
+ ['No Data Available','ST-T_wave_abnormality', 'Normal', 'Left_ventricular_hypertrophy'],
62
+ help="Select the resting electrocardiographic result",
63
+ )
64
+ restingrelectro = np.nan if restingrelectro == 'No Data Available' else restingrelectro
65
+ maxheartrate = st.number_input(
66
+ "Maximum Heart Rate Achieved", min_value=(-1), max_value=250, step=1, format="%d", help="Enter the maximum heart rate achieved, '-1' corresponds to unknown maximum heart rate"
67
+ )
68
+ maxheartrate = np.nan if maxheartrate == (-1) else maxheartrate
69
+
70
+
71
+ # Second row of inputs
72
+ exerciseangia = st.radio("Exercise-Induced Angina", ['Yes', 'No','No Data Available'], horizontal=True)
73
+ exerciseangia = np.nan if exerciseangia == 'No Data Available' else exerciseangia
74
+ oldpeak = st.number_input("ST Depression Induced by Exercise", step = 0.1, help="Enter ST depression value induced by exercise relative to rest, any negetive value corresponds to unknown oldpeak value")
75
+ oldpeak = np.nan if oldpeak < 0 else oldpeak
76
+ slope = st.selectbox("Slope of Peak Exercise ST Segment", ['No Data Available','Downsloping', 'Upsloping', 'Flat'])
77
+ slope = np.nan if slope == 'No Data Available' else slope
78
+ noofmajorvessels = st.selectbox(
79
+ "Number of Major Vessels Colored by Fluoroscopy", ['No Data Available','Zero', 'One', 'Two', 'Three']
80
+ )
81
+ noofmajorvessels = np.nan if noofmajorvessels == 'No Data Available' else noofmajorvessels
82
+
83
+ # Submit button
84
+ submitted = st.form_submit_button("Predict")
85
+
86
+ # Load model
87
+ model_1 = pickle.load(open(r"C:\Users\user\Downloads\New folder\rfc.pkl", "rb"))
88
+
89
+ # Prediction
90
+ if submitted:
91
+ with st.spinner("Analyzing the data..."):
92
+ result = model_1.predict([[
93
+ age, gender, chestpain, restingBP, serum_cholesterol,
94
+ fasting_blood_sugar, restingrelectro, maxheartrate, exerciseangia,
95
+ oldpeak, slope, noofmajorvessels
96
+ ]])
97
+
98
+ # Display result
99
+ st.markdown(
100
+ "### Prediction Result:", unsafe_allow_html=True
101
+ )
102
+
103
+ if result[0] == "Present":
104
+ st.info("The patient is likely to have heart disease. Please consult a doctor for further evaluation.")
105
+ else:
106
+ st.success("The patient is unlikely to have heart disease. However, maintaining regular check-ups is recommended.")
107
+
108
+ # Footer
109
+ st.markdown(
110
+ '''---\n
111
+ Developed by Abhisikta Moharana (https://www.linkedin.com/in/abhisikta-moharana-983052270)''',
112
+ unsafe_allow_html=True,
113
+ )
114
+
requirements.txt ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==5.5.0
2
+ attrs==24.2.0
3
+ blinker==1.9.0
4
+ cachetools==5.5.0
5
+ certifi==2024.8.30
6
+ charset-normalizer==3.4.0
7
+ click==8.1.7
8
+ colorama==0.4.6
9
+ gitdb==4.0.11
10
+ GitPython==3.1.43
11
+ idna==3.10
12
+ Jinja2==3.1.4
13
+ joblib==1.4.2
14
+ jsonschema==4.23.0
15
+ jsonschema-specifications==2024.10.1
16
+ markdown-it-py==3.0.0
17
+ MarkupSafe==3.0.2
18
+ mdurl==0.1.2
19
+ narwhals==1.17.0
20
+ numpy==2.2.0
21
+ packaging==24.2
22
+ pandas==2.2.3
23
+ pillow==11.0.0
24
+ protobuf==5.29.1
25
+ pyarrow==18.1.0
26
+ pydeck==0.9.1
27
+ Pygments==2.18.0
28
+ python-dateutil==2.9.0.post0
29
+ pytz==2024.2
30
+ referencing==0.35.1
31
+ requests==2.32.3
32
+ rich==13.9.4
33
+ rpds-py==0.22.3
34
+ scikit-learn==1.4.2
35
+ scipy==1.14.1
36
+ six==1.17.0
37
+ smmap==5.0.1
38
+ streamlit==1.41.0
39
+ tenacity==9.0.0
40
+ threadpoolctl==3.5.0
41
+ toml==0.10.2
42
+ tornado==6.4.2
43
+ typing_extensions==4.12.2
44
+ tzdata==2024.2
45
+ urllib3==2.2.3
46
+ watchdog==6.0.0
rfc.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e7d16756669b08d7cf1784bb0e41a549f95f2a35fe15124a66ba93bd1c757911
3
+ size 6664693