hmfayyaz commited on
Commit
b9be6cd
Β·
unverified Β·
1 Parent(s): 61d9b65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -35
app.py CHANGED
@@ -215,22 +215,21 @@ def main():
215
  pass
216
 
217
  # Add source file to results and extend all_results
218
- mrz_found_in_file = False
219
  for res in results:
220
  res['source_file'] = file.name
221
- # Check if MRZ was found in any result
222
- if res.get('mrz_found', False):
223
- mrz_found_in_file = True
224
  all_results.extend(results)
225
 
226
- # Track problematic files - check if MRZ was found OR if no results
227
- if not file_processed or not results or not mrz_found_in_file:
228
  problematic_files.append({
229
  'file_name': file.name,
230
  'issue': 'No MRZ data found - image may be blurry or passport not detected'
231
  })
232
  # Debug output
233
- print(f"DEBUG: Added problematic file: {file.name} (file_processed: {file_processed}, results: {len(results)}, mrz_found: {mrz_found_in_file})")
234
 
235
  except Exception as e:
236
  # Track files that caused errors
@@ -285,41 +284,39 @@ def main():
285
 
286
  st.dataframe(df)
287
 
288
- # Handle problematic files export popup - ALWAYS SHOW WHEN THERE ARE PROBLEMATIC FILES
 
289
  if problematic_files:
290
- # Create a prominent warning box
291
- st.warning("🚨 ATTENTION: Some files could not be processed!")
292
-
293
- # Show the problematic files prominently
294
- st.error(f"**{len(problematic_files)} file(s) have issues:**")
295
-
296
- # Always show details expanded for problematic files
297
- with st.expander(f"πŸ“‹ Click to see details of {len(problematic_files)} problematic file(s)", expanded=True):
298
- for problem in problematic_files:
299
- st.write(f"β€’ **{problem['file_name']}**: {problem['issue']}")
300
-
301
  # Initialize session state for export decision if not exists
302
  if 'export_decision_made' not in st.session_state:
303
  st.session_state.export_decision_made = False
304
  if 'include_problematic_files' not in st.session_state:
305
  st.session_state.include_problematic_files = False
306
 
307
- # Show export confirmation dialog in a prominent box
308
  if not st.session_state.export_decision_made:
309
- st.info("**πŸ“€ EXPORT OPTIONS:**")
310
- st.write("**Would you like to include these problematic files in your export?**")
311
- st.write("βœ… **YES**: Include all files (problematic ones will show β€’β€’β€’ for missing data)")
312
- st.write("❌ **NO**: Export only successfully processed files")
 
 
 
 
 
 
 
313
 
314
  col1, col2 = st.columns(2)
315
  with col1:
316
- if st.button("βœ… YES, Include All Files", type="primary", use_container_width=True):
317
  st.session_state.include_problematic_files = True
318
  st.session_state.export_decision_made = True
319
  st.rerun()
320
 
321
  with col2:
322
- if st.button("❌ NO, Export Only Good Files", type="secondary", use_container_width=True):
323
  st.session_state.include_problematic_files = False
324
  st.session_state.export_decision_made = True
325
  st.rerun()
@@ -352,21 +349,14 @@ def main():
352
  else:
353
  export_df = df
354
 
355
- # Show current decision
356
- decision_text = "βœ… Including problematic files" if st.session_state.include_problematic_files else "❌ Excluding problematic files"
357
- st.success(f"Export decision: {decision_text}")
358
-
359
  # Add reset button to change decision
360
- if st.button("πŸ”„ Change Export Decision", help="Click to change your export preference"):
361
  st.session_state.export_decision_made = False
362
  st.rerun()
363
- else:
364
- # No decision made yet, use only successful files for now
365
- export_df = df
366
  else:
367
  export_df = df
368
 
369
- # Download buttons - now export_df is guaranteed to be defined
370
  col1, col2 = st.columns(2)
371
 
372
  with col1:
 
215
  pass
216
 
217
  # Add source file to results and extend all_results
 
218
  for res in results:
219
  res['source_file'] = file.name
220
+ # Add status field to indicate if MRZ was found
221
+ if 'mrz_found' not in res:
222
+ res['mrz_found'] = True
223
  all_results.extend(results)
224
 
225
+ # Track problematic files
226
+ if not file_processed or not results:
227
  problematic_files.append({
228
  'file_name': file.name,
229
  'issue': 'No MRZ data found - image may be blurry or passport not detected'
230
  })
231
  # Debug output
232
+ print(f"DEBUG: Added problematic file: {file.name} (file_processed: {file_processed}, results: {len(results)})")
233
 
234
  except Exception as e:
235
  # Track files that caused errors
 
284
 
285
  st.dataframe(df)
286
 
287
+ # Handle problematic files export popup
288
+ print(f"DEBUG: About to check problematic_files popup. Length: {len(problematic_files)}")
289
  if problematic_files:
290
+ print(f"DEBUG: Showing popup for {len(problematic_files)} problematic files")
 
 
 
 
 
 
 
 
 
 
291
  # Initialize session state for export decision if not exists
292
  if 'export_decision_made' not in st.session_state:
293
  st.session_state.export_decision_made = False
294
  if 'include_problematic_files' not in st.session_state:
295
  st.session_state.include_problematic_files = False
296
 
297
+ # Show export confirmation dialog
298
  if not st.session_state.export_decision_made:
299
+ st.subheader("⚠️ Export Confirmation Required")
300
+ st.write(f"**{len(problematic_files)} file(s) could not be processed properly:**")
301
+
302
+ # Show problematic files details
303
+ with st.expander(f"Click to see details of {len(problematic_files)} problematic file(s)"):
304
+ for problem in problematic_files:
305
+ st.write(f"β€’ **{problem['file_name']}**: {problem['issue']}")
306
+
307
+ st.write("**Would you like to include these files in your export?**")
308
+ st.write("β€’ **Yes**: Files will show dots (β€’β€’β€’) for missing data")
309
+ st.write("β€’ **No**: Only successfully processed files will be exported")
310
 
311
  col1, col2 = st.columns(2)
312
  with col1:
313
+ if st.button("βœ… Yes, Include All Files", type="primary", use_container_width=True):
314
  st.session_state.include_problematic_files = True
315
  st.session_state.export_decision_made = True
316
  st.rerun()
317
 
318
  with col2:
319
+ if st.button("❌ No, Export Only Good Files", type="secondary", use_container_width=True):
320
  st.session_state.include_problematic_files = False
321
  st.session_state.export_decision_made = True
322
  st.rerun()
 
349
  else:
350
  export_df = df
351
 
 
 
 
 
352
  # Add reset button to change decision
353
+ if st.button("πŸ”„ Change Export Decision"):
354
  st.session_state.export_decision_made = False
355
  st.rerun()
 
 
 
356
  else:
357
  export_df = df
358
 
359
+ # Download buttons - moved inside try block where df is guaranteed to be defined
360
  col1, col2 = st.columns(2)
361
 
362
  with col1: