edcelbogs commited on
Commit
59bd23e
Β·
verified Β·
1 Parent(s): addc16a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +171 -31
app.py CHANGED
@@ -4,51 +4,191 @@ import tensorflow as tf
4
  import joblib
5
 
6
  # --- Load model and label encoder ---
7
- model = tf.keras.models.load_model("lung_cancer_classifier.h5") # Load H5 model
8
  le_target = joblib.load("label_encoder.pkl")
9
 
10
  # --- Page configuration ---
11
- st.set_page_config(page_title="Lung Cancer Risk Classifier", layout="centered")
 
 
 
12
 
13
  # --- Title and description ---
14
  st.title("Lung Cancer Risk Prediction")
15
  st.write("""
16
- This application predicts the **level of lung cancer risk** for a patient.
17
- **Note:** The data used to train this model consists of patients already diagnosed with lung cancer.
18
- The target of this classification is the **Lung Cancer Level**.
 
 
19
  """)
20
 
21
  # --- Input fields ---
22
  Age = st.number_input("Age", min_value=1, max_value=100, value=37)
23
 
24
- # Gender dropdown fixed to show Male/Female but return encoded value
25
  Gender = st.selectbox(
26
  "Gender",
27
  options=[("Male", 1), ("Female", 2)],
28
- format_func=lambda x: x[0] # show only label
29
- )[1] # get encoded value
30
-
31
- Air_Pollution = st.slider("Air Pollution Exposure", 1, 8, 4)
32
- Alcohol_use = st.slider("Alcohol Use", 1, 8, 5)
33
- Dust_Allergy = st.slider("Dust Allergy", 1, 8, 5)
34
- Occupational_Hazards = st.slider("Occupational Hazards", 1, 8, 5)
35
- Genetic_Risk = st.slider("Genetic Risk", 1, 7, 5)
36
- Chronic_Lung_Disease = st.slider("Chronic Lung Disease", 1, 7, 4)
37
- Balanced_Diet = st.slider("Balanced Diet", 1, 7, 4)
38
- Obesity = st.slider("Obesity", 1, 7, 4)
39
- Smoking = st.slider("Smoking", 1, 8, 4)
40
- Passive_Smoker = st.slider("Passive Smoker", 1, 8, 4)
41
- Chest_Pain = st.slider("Chest Pain", 1, 9, 4)
42
- Coughing_of_Blood = st.slider("Coughing of Blood", 1, 9, 4)
43
- Fatigue = st.slider("Fatigue", 1, 9, 4)
44
- Weight_Loss = st.slider("Weight Loss", 1, 8, 4)
45
- Shortness_of_Breath = st.slider("Shortness of Breath", 1, 9, 4)
46
- Wheezing = st.slider("Wheezing", 1, 8, 4)
47
- Swallowing_Difficulty = st.slider("Swallowing Difficulty", 1, 8, 4)
48
- Clubbing_of_Finger_Nails = st.slider("Clubbing of Finger Nails", 1, 9, 4)
49
- Frequent_Cold = st.slider("Frequent Cold", 1, 7, 4)
50
- Dry_Cough = st.slider("Dry Cough", 1, 7, 4)
51
- Snoring = st.slider("Snoring", 1, 7, 3)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  # --- Combine inputs ---
54
  input_data = np.array([[
@@ -73,4 +213,4 @@ if st.button("Predict"):
73
 
74
  # --- Footer ---
75
  st.markdown("---")
76
- st.markdown("**Train By:** Edcel Bogay")
 
4
  import joblib
5
 
6
  # --- Load model and label encoder ---
7
+ model = tf.keras.models.load_model("lung_cancer_classifier.h5")
8
  le_target = joblib.load("label_encoder.pkl")
9
 
10
  # --- Page configuration ---
11
+ st.set_page_config(
12
+ page_title="Lung Cancer Risk Classifier",
13
+ layout="centered"
14
+ )
15
 
16
  # --- Title and description ---
17
  st.title("Lung Cancer Risk Prediction")
18
  st.write("""
19
+ This application predicts the **level of lung cancer risk** for a patient.
20
+
21
+ **Important:**
22
+ The model was trained using data from patients **already diagnosed** with lung cancer.
23
+ The output represents a **risk/severity level**, not a medical diagnosis.
24
  """)
25
 
26
  # --- Input fields ---
27
  Age = st.number_input("Age", min_value=1, max_value=100, value=37)
28
 
 
29
  Gender = st.selectbox(
30
  "Gender",
31
  options=[("Male", 1), ("Female", 2)],
32
+ format_func=lambda x: x[0]
33
+ )[1]
34
+
35
+ Air_Pollution = st.slider(
36
+ "Air Pollution Exposure",
37
+ 1, 8, 4,
38
+ help="""
39
+ 1 – Rural area
40
+ 2 – Small town
41
+ 3 – Urban residential
42
+ 4 – Heavy traffic area
43
+ 5 – Near industrial zone
44
+ 6 – Factory worker
45
+ 7 – High industrial exposure
46
+ 8 – Extremely polluted environment
47
+ """
48
+ )
49
+
50
+ Alcohol_use = st.slider(
51
+ "Alcohol Use",
52
+ 1, 8, 5,
53
+ help="""
54
+ 1 – Never drinks
55
+ 2 – Rare
56
+ 3 – Occasional
57
+ 4 – Social drinking
58
+ 5 – Weekly
59
+ 6 – Several times a week
60
+ 7 – Daily
61
+ 8 – Heavy drinker
62
+ """
63
+ )
64
+
65
+ Dust_Allergy = st.slider(
66
+ "Dust Allergy",
67
+ 1, 8, 5,
68
+ help="1=None | 3=Mild | 5=Moderate | 7=Severe | 8=Chronic"
69
+ )
70
+
71
+ Occupational_Hazards = st.slider(
72
+ "Occupational Hazards",
73
+ 1, 8, 5,
74
+ help="""
75
+ 1 – Office / home work
76
+ 3 – Outdoor non-industrial
77
+ 5 – Factory work
78
+ 6 – Chemical exposure
79
+ 8 – Extreme industrial hazard
80
+ """
81
+ )
82
+
83
+ Genetic_Risk = st.slider(
84
+ "Genetic Risk",
85
+ 1, 7, 5,
86
+ help="1=None | 3=Distant family history | 5=Immediate family | 7=Strong genetic risk"
87
+ )
88
+
89
+ Chronic_Lung_Disease = st.slider(
90
+ "Chronic Lung Disease",
91
+ 1, 7, 4,
92
+ help="1=None | 3=Past condition | 5=Ongoing | 7=Severe"
93
+ )
94
+
95
+ Balanced_Diet = st.slider(
96
+ "Balanced Diet",
97
+ 1, 7, 4,
98
+ help="1=Very poor | 3=Poor | 5=Mostly balanced | 7=Highly balanced"
99
+ )
100
+
101
+ Obesity = st.slider(
102
+ "Obesity",
103
+ 1, 7, 4,
104
+ help="1=Normal | 3=Overweight | 5=Obese | 7=Severely obese"
105
+ )
106
+
107
+ Smoking = st.slider(
108
+ "Smoking",
109
+ 1, 8, 4,
110
+ help="""
111
+ 1 – Never smoked
112
+ 3 – Former smoker
113
+ 4 – Occasional smoker
114
+ 5 – Light daily smoker
115
+ 6 – Moderate smoker
116
+ 7 – Heavy smoker
117
+ 8 – Chain smoker
118
+ """
119
+ )
120
+
121
+ Passive_Smoker = st.slider(
122
+ "Passive Smoker",
123
+ 1, 8, 4,
124
+ help="1=None | 3=Occasional | 5=Daily exposure | 8=Constant exposure"
125
+ )
126
+
127
+ Chest_Pain = st.slider(
128
+ "Chest Pain",
129
+ 1, 9, 4,
130
+ help="1=None | 3=Mild | 5=Moderate | 7=Severe | 9=Extreme"
131
+ )
132
+
133
+ Coughing_of_Blood = st.slider(
134
+ "Coughing of Blood",
135
+ 1, 9, 4,
136
+ help="1=None | 5=Occasional | 9=Frequent / severe"
137
+ )
138
+
139
+ Fatigue = st.slider(
140
+ "Fatigue",
141
+ 1, 9, 4,
142
+ help="1=None | 3=Mild | 5=Moderate | 7=Severe | 9=Extreme"
143
+ )
144
+
145
+ Weight_Loss = st.slider(
146
+ "Weight Loss",
147
+ 1, 8, 4,
148
+ help="1=None | 4=Noticeable | 6=Significant | 8=Severe"
149
+ )
150
+
151
+ Shortness_of_Breath = st.slider(
152
+ "Shortness of Breath",
153
+ 1, 9, 4,
154
+ help="1=None | 3=Mild | 5=Moderate | 7=Severe | 9=Extreme"
155
+ )
156
+
157
+ Wheezing = st.slider(
158
+ "Wheezing",
159
+ 1, 8, 4,
160
+ help="1=None | 4=Occasional | 6=Frequent | 8=Constant"
161
+ )
162
+
163
+ Swallowing_Difficulty = st.slider(
164
+ "Swallowing Difficulty",
165
+ 1, 8, 4,
166
+ help="1=None | 4=Occasional | 6=Frequent | 8=Severe"
167
+ )
168
+
169
+ Clubbing_of_Finger_Nails = st.slider(
170
+ "Clubbing of Finger Nails",
171
+ 1, 9, 4,
172
+ help="1=None | 5=Visible | 9=Severe"
173
+ )
174
+
175
+ Frequent_Cold = st.slider(
176
+ "Frequent Cold",
177
+ 1, 7, 4,
178
+ help="1=Rare | 3=Occasional | 5=Frequent | 7=Very frequent"
179
+ )
180
+
181
+ Dry_Cough = st.slider(
182
+ "Dry Cough",
183
+ 1, 7, 4,
184
+ help="1=None | 3=Mild | 5=Persistent | 7=Severe"
185
+ )
186
+
187
+ Snoring = st.slider(
188
+ "Snoring",
189
+ 1, 7, 3,
190
+ help="1=None | 3=Occasional | 5=Frequent | 7=Severe"
191
+ )
192
 
193
  # --- Combine inputs ---
194
  input_data = np.array([[
 
213
 
214
  # --- Footer ---
215
  st.markdown("---")
216
+ st.markdown("**Trained By:** Edcel Bogay")