rawshal commited on
Commit
72aa2b1
Β·
verified Β·
1 Parent(s): 25e8c9e

Update pages/1_Water_Tank_Report.py

Browse files
Files changed (1) hide show
  1. pages/1_Water_Tank_Report.py +44 -9
pages/1_Water_Tank_Report.py CHANGED
@@ -9,7 +9,15 @@ from dateutil.relativedelta import relativedelta
9
  # ── 1. CONFIG & ASSETS ────────────────────────────────────────────────────────
10
  st.set_page_config(page_title="Wercore | Water Tank Engine", page_icon="πŸ’§", layout="wide")
11
 
12
- # Pins the logo to the absolute top of the sidebar above navigation!
 
 
 
 
 
 
 
 
13
  st.logo("WERCORE logo.png")
14
 
15
  # ── SECURITY CHECK ──
@@ -98,7 +106,12 @@ with st.sidebar:
98
  expiry_date_str = expiry_date.strftime("%d-%m-%Y")
99
 
100
  st.markdown("---")
101
- handwritten_files = st.file_uploader("Upload physical reports (PDFs only)*", type=["pdf", "PDF"], accept_multiple_files=True)
 
 
 
 
 
102
 
103
  # ── 4. UI: TANK ENGINEERING DATA ──────────────────────────────────────────────
104
  st.header("Water Tank Cleaning Report Maker")
@@ -161,14 +174,25 @@ for i, tank in enumerate(st.session_state.tanks):
161
  tank["mould"] = bc2.checkbox("πŸ„ Mould", tank["mould"], key=f"mld_{i}")
162
  tank["rust"] = bc3.checkbox("🟀 Rust", tank["rust"], key=f"rst_{i}")
163
 
164
- st.file_uploader(f"Before Photos (1 or 2 max)*", type=["jpg","jpeg","png"], accept_multiple_files=True, key=f"b_img_{i}")
 
 
 
 
 
165
 
166
  with col_a:
167
  st.markdown("🟒 **AFTER CLEANING**")
168
  tank["a_water"] = st.selectbox("Quantity of Water", ["Empty", "Quarter", "Half", "Full"], index=["Empty", "Quarter", "Half", "Full"].index(tank["a_water"]), key=f"aw_{i}")
169
  tank["a_cond"] = st.selectbox("Condition of Water", ["Clean", "Dirty", "Very Dirty"], index=["Clean", "Dirty", "Very Dirty"].index(tank["a_cond"]), key=f"ac_{i}")
170
  st.info("βœ… *All contaminants are automatically set to 'No' for the final report.*")
171
- st.file_uploader(f"After Photos (1 or 2 max)*", type=["jpg","jpeg","png"], accept_multiple_files=True, key=f"a_img_{i}")
 
 
 
 
 
 
172
 
173
  if st.button("βž• Add Another Tank"):
174
  new_tank = default_tank.copy()
@@ -179,7 +203,6 @@ if st.button("βž• Add Another Tank"):
179
  st.markdown("---")
180
 
181
  # ── 5. ENGINE: MASTER PDF ASSEMBLY ────────────────────────────────────────────
182
- # We create a dedicated visual container ABOVE the button for alerts and loading spinners
183
  notification_zone = st.empty()
184
 
185
  if st.button("πŸš€ Generate Master Report", type="primary", use_container_width=True):
@@ -191,13 +214,25 @@ if st.button("πŸš€ Generate Master Report", type="primary", use_container_width=
191
  if not project_location: errors.append("Project Location is missing.")
192
  if not handwritten_files: errors.append("At least one Physical Report PDF must be uploaded.")
193
 
 
 
 
 
 
194
  for i, t in enumerate(st.session_state.tanks):
195
  if not t["name"].strip(): errors.append(f"Tank {i+1} is missing a name.")
196
- before_count = len(st.session_state.get(f"b_img_{i}") or [])
197
- after_count = len(st.session_state.get(f"a_img_{i}") or [])
198
 
199
- if before_count not in [1, 2]: errors.append(f"Tank '{t['name']}' requires 1 or 2 'Before' photos (Currently has {before_count}).")
200
- if after_count not in [1, 2]: errors.append(f"Tank '{t['name']}' requires 1 or 2 'After' photos (Currently has {after_count}).")
 
 
 
 
 
 
 
 
 
201
 
202
  if errors:
203
  with notification_zone.container():
 
9
  # ── 1. CONFIG & ASSETS ────────────────────────────────────────────────────────
10
  st.set_page_config(page_title="Wercore | Water Tank Engine", page_icon="πŸ’§", layout="wide")
11
 
12
+ # CSS Hack for the large top-left logo
13
+ st.markdown("""
14
+ <style>
15
+ [data-testid="stLogo"] {
16
+ height: 4rem !important;
17
+ }
18
+ </style>
19
+ """, unsafe_allow_html=True)
20
+
21
  st.logo("WERCORE logo.png")
22
 
23
  # ── SECURITY CHECK ──
 
106
  expiry_date_str = expiry_date.strftime("%d-%m-%Y")
107
 
108
  st.markdown("---")
109
+ # Updated text and instant size check
110
+ handwritten_files = st.file_uploader("Upload physical reports (PDFs only - Max 5MB)*", type=["pdf", "PDF"], accept_multiple_files=True)
111
+ if handwritten_files:
112
+ for f in handwritten_files:
113
+ if f.size > 5 * 1024 * 1024:
114
+ st.error(f"❌ '{f.name}' exceeds the 5MB limit. Please compress it.")
115
 
116
  # ── 4. UI: TANK ENGINEERING DATA ──────────────────────────────────────────────
117
  st.header("Water Tank Cleaning Report Maker")
 
174
  tank["mould"] = bc2.checkbox("πŸ„ Mould", tank["mould"], key=f"mld_{i}")
175
  tank["rust"] = bc3.checkbox("🟀 Rust", tank["rust"], key=f"rst_{i}")
176
 
177
+ # Live Size Checking for Before Photos
178
+ b_imgs = st.file_uploader(f"Before Photos (1 or 2 max - Max 2MB each)*", type=["jpg","jpeg","png"], accept_multiple_files=True, key=f"b_img_{i}")
179
+ if b_imgs:
180
+ for f in b_imgs:
181
+ if f.size > 2 * 1024 * 1024:
182
+ st.error(f"❌ '{f.name}' exceeds the 2MB limit.")
183
 
184
  with col_a:
185
  st.markdown("🟒 **AFTER CLEANING**")
186
  tank["a_water"] = st.selectbox("Quantity of Water", ["Empty", "Quarter", "Half", "Full"], index=["Empty", "Quarter", "Half", "Full"].index(tank["a_water"]), key=f"aw_{i}")
187
  tank["a_cond"] = st.selectbox("Condition of Water", ["Clean", "Dirty", "Very Dirty"], index=["Clean", "Dirty", "Very Dirty"].index(tank["a_cond"]), key=f"ac_{i}")
188
  st.info("βœ… *All contaminants are automatically set to 'No' for the final report.*")
189
+
190
+ # Live Size Checking for After Photos
191
+ a_imgs = st.file_uploader(f"After Photos (1 or 2 max - Max 2MB each)*", type=["jpg","jpeg","png"], accept_multiple_files=True, key=f"a_img_{i}")
192
+ if a_imgs:
193
+ for f in a_imgs:
194
+ if f.size > 2 * 1024 * 1024:
195
+ st.error(f"❌ '{f.name}' exceeds the 2MB limit.")
196
 
197
  if st.button("βž• Add Another Tank"):
198
  new_tank = default_tank.copy()
 
203
  st.markdown("---")
204
 
205
  # ── 5. ENGINE: MASTER PDF ASSEMBLY ────────────────────────────────────────────
 
206
  notification_zone = st.empty()
207
 
208
  if st.button("πŸš€ Generate Master Report", type="primary", use_container_width=True):
 
214
  if not project_location: errors.append("Project Location is missing.")
215
  if not handwritten_files: errors.append("At least one Physical Report PDF must be uploaded.")
216
 
217
+ # Validation check for oversized physical PDFs
218
+ if handwritten_files:
219
+ for f in handwritten_files:
220
+ if f.size > 5 * 1024 * 1024: errors.append(f"Physical report '{f.name}' exceeds the 5MB limit.")
221
+
222
  for i, t in enumerate(st.session_state.tanks):
223
  if not t["name"].strip(): errors.append(f"Tank {i+1} is missing a name.")
 
 
224
 
225
+ b_imgs = st.session_state.get(f"b_img_{i}") or []
226
+ a_imgs = st.session_state.get(f"a_img_{i}") or []
227
+
228
+ if len(b_imgs) not in [1, 2]: errors.append(f"Tank '{t['name']}' requires 1 or 2 'Before' photos.")
229
+ if len(a_imgs) not in [1, 2]: errors.append(f"Tank '{t['name']}' requires 1 or 2 'After' photos.")
230
+
231
+ # Validation check for oversized images
232
+ for f in b_imgs:
233
+ if f.size > 2 * 1024 * 1024: errors.append(f"Tank '{t['name']}' Before Photo '{f.name}' exceeds 2MB.")
234
+ for f in a_imgs:
235
+ if f.size > 2 * 1024 * 1024: errors.append(f"Tank '{t['name']}' After Photo '{f.name}' exceeds 2MB.")
236
 
237
  if errors:
238
  with notification_zone.container():