File size: 4,979 Bytes
809b554
 
 
 
 
 
59bd23e
809b554
 
 
59bd23e
 
 
 
809b554
 
 
 
59bd23e
 
 
 
 
809b554
 
 
 
 
 
 
 
59bd23e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
809b554
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59bd23e
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import streamlit as st
import numpy as np
import tensorflow as tf
import joblib

# --- Load model and label encoder ---
model = tf.keras.models.load_model("lung_cancer_classifier.h5")
le_target = joblib.load("label_encoder.pkl")

# --- Page configuration ---
st.set_page_config(
    page_title="Lung Cancer Risk Classifier",
    layout="centered"
)

# --- Title and description ---
st.title("Lung Cancer Risk Prediction")
st.write("""
This application predicts the **level of lung cancer risk** for a patient.

**Important:**  
The model was trained using data from patients **already diagnosed** with lung cancer.  
The output represents a **risk/severity level**, not a medical diagnosis.
""")

# --- Input fields ---
Age = st.number_input("Age", min_value=1, max_value=100, value=37)

Gender = st.selectbox(
    "Gender",
    options=[("Male", 1), ("Female", 2)],
    format_func=lambda x: x[0]
)[1]

Air_Pollution = st.slider(
    "Air Pollution Exposure",
    1, 8, 4,
    help="""
    1 – Rural area
    2 – Small town
    3 – Urban residential
    4 – Heavy traffic area
    5 – Near industrial zone
    6 – Factory worker
    7 – High industrial exposure
    8 – Extremely polluted environment
    """
)

Alcohol_use = st.slider(
    "Alcohol Use",
    1, 8, 5,
    help="""
    1 – Never drinks
    2 – Rare
    3 – Occasional
    4 – Social drinking
    5 – Weekly
    6 – Several times a week
    7 – Daily
    8 – Heavy drinker
    """
)

Dust_Allergy = st.slider(
    "Dust Allergy",
    1, 8, 5,
    help="1=None | 3=Mild | 5=Moderate | 7=Severe | 8=Chronic"
)

Occupational_Hazards = st.slider(
    "Occupational Hazards",
    1, 8, 5,
    help="""
    1 – Office / home work
    3 – Outdoor non-industrial
    5 – Factory work
    6 – Chemical exposure
    8 – Extreme industrial hazard
    """
)

Genetic_Risk = st.slider(
    "Genetic Risk",
    1, 7, 5,
    help="1=None | 3=Distant family history | 5=Immediate family | 7=Strong genetic risk"
)

Chronic_Lung_Disease = st.slider(
    "Chronic Lung Disease",
    1, 7, 4,
    help="1=None | 3=Past condition | 5=Ongoing | 7=Severe"
)

Balanced_Diet = st.slider(
    "Balanced Diet",
    1, 7, 4,
    help="1=Very poor | 3=Poor | 5=Mostly balanced | 7=Highly balanced"
)

Obesity = st.slider(
    "Obesity",
    1, 7, 4,
    help="1=Normal | 3=Overweight | 5=Obese | 7=Severely obese"
)

Smoking = st.slider(
    "Smoking",
    1, 8, 4,
    help="""
    1 – Never smoked
    3 – Former smoker
    4 – Occasional smoker
    5 – Light daily smoker
    6 – Moderate smoker
    7 – Heavy smoker
    8 – Chain smoker
    """
)

Passive_Smoker = st.slider(
    "Passive Smoker",
    1, 8, 4,
    help="1=None | 3=Occasional | 5=Daily exposure | 8=Constant exposure"
)

Chest_Pain = st.slider(
    "Chest Pain",
    1, 9, 4,
    help="1=None | 3=Mild | 5=Moderate | 7=Severe | 9=Extreme"
)

Coughing_of_Blood = st.slider(
    "Coughing of Blood",
    1, 9, 4,
    help="1=None | 5=Occasional | 9=Frequent / severe"
)

Fatigue = st.slider(
    "Fatigue",
    1, 9, 4,
    help="1=None | 3=Mild | 5=Moderate | 7=Severe | 9=Extreme"
)

Weight_Loss = st.slider(
    "Weight Loss",
    1, 8, 4,
    help="1=None | 4=Noticeable | 6=Significant | 8=Severe"
)

Shortness_of_Breath = st.slider(
    "Shortness of Breath",
    1, 9, 4,
    help="1=None | 3=Mild | 5=Moderate | 7=Severe | 9=Extreme"
)

Wheezing = st.slider(
    "Wheezing",
    1, 8, 4,
    help="1=None | 4=Occasional | 6=Frequent | 8=Constant"
)

Swallowing_Difficulty = st.slider(
    "Swallowing Difficulty",
    1, 8, 4,
    help="1=None | 4=Occasional | 6=Frequent | 8=Severe"
)

Clubbing_of_Finger_Nails = st.slider(
    "Clubbing of Finger Nails",
    1, 9, 4,
    help="1=None | 5=Visible | 9=Severe"
)

Frequent_Cold = st.slider(
    "Frequent Cold",
    1, 7, 4,
    help="1=Rare | 3=Occasional | 5=Frequent | 7=Very frequent"
)

Dry_Cough = st.slider(
    "Dry Cough",
    1, 7, 4,
    help="1=None | 3=Mild | 5=Persistent | 7=Severe"
)

Snoring = st.slider(
    "Snoring",
    1, 7, 3,
    help="1=None | 3=Occasional | 5=Frequent | 7=Severe"
)

# --- Combine inputs ---
input_data = np.array([[
    Age, Gender, Air_Pollution, Alcohol_use, Dust_Allergy,
    Occupational_Hazards, Genetic_Risk, Chronic_Lung_Disease,
    Balanced_Diet, Obesity, Smoking, Passive_Smoker,
    Chest_Pain, Coughing_of_Blood, Fatigue, Weight_Loss,
    Shortness_of_Breath, Wheezing, Swallowing_Difficulty,
    Clubbing_of_Finger_Nails, Frequent_Cold, Dry_Cough, Snoring
]])

# --- Prediction ---
if st.button("Predict"):
    prediction = model.predict(input_data)
    predicted_class = prediction.argmax(axis=1)[0]
    confidence = prediction.max(axis=1)[0]

    label = le_target.inverse_transform([predicted_class])[0]

    st.success(f"Predicted Lung Cancer Level: {label}")
    st.info(f"Prediction Confidence: {confidence:.2%}")

# --- Footer ---
st.markdown("---")
st.markdown("**Trained By:** Edcel Bogay")