Spaces:
Sleeping
Sleeping
hmfayyaz commited on
Update app.py
Browse files
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 |
-
#
|
| 222 |
-
if
|
| 223 |
-
|
| 224 |
all_results.extend(results)
|
| 225 |
|
| 226 |
-
# Track problematic files
|
| 227 |
-
if not file_processed or not results
|
| 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)}
|
| 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
|
|
|
|
| 289 |
if problematic_files:
|
| 290 |
-
|
| 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
|
| 308 |
if not st.session_state.export_decision_made:
|
| 309 |
-
st.
|
| 310 |
-
st.write("**
|
| 311 |
-
|
| 312 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
|
| 314 |
col1, col2 = st.columns(2)
|
| 315 |
with col1:
|
| 316 |
-
if st.button("β
|
| 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("β
|
| 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"
|
| 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 -
|
| 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:
|