Chhagan005 commited on
Commit
f43b38d
Β·
verified Β·
1 Parent(s): 60e62f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -25
app.py CHANGED
@@ -859,34 +859,47 @@ def run_step2_structure(model, processor, metadata: dict, device,
859
  thread.start()
860
 
861
  # Pre-build Python-verified sections
862
- python_sections = f"""## πŸ–ΌοΈ Visual Elements
863
- | Element | Status | Location |
864
- |---------|--------|----------|
865
- | πŸ“· Profile Photo | {metadata['photo_present']} | {metadata['photo_location']} |
866
- | ✍️ Signature | {metadata['sig_present']} | {metadata['sig_location']} |
867
- | πŸ” MRZ Zone | {metadata['mrz_present']} | Bottom strip |
 
 
 
 
 
 
868
 
869
- ---
870
-
871
- ## βœ… English Fields (Direct from Card β€” Not Modified)
872
- {cal_note}
873
-
874
- {tbl}
875
-
876
- ---
877
-
878
- ## πŸ“œ Original Script
879
-
880
- {raw_text}
881
- ---
882
-
883
- ## πŸ” MRZ Data
 
 
 
 
 
 
 
 
 
 
884
 
885
- {chr(10).join([l for l in raw_text.split(chr(10)) if re.match(r'^[A-Z0-9<]{25,50}$', re.sub(r'\s+','',l.strip()))]) or 'NOT PRESENT'}
886
- {build_mrz_table(mrz_data) if mrz_data else '_No MRZ detected._'}
887
 
888
- ---
889
- """
890
 
891
  return streamer, thread, mrz_data, python_sections
892
 
 
859
  thread.start()
860
 
861
  # Pre-build Python-verified sections
862
+ # ── Pre-compute outside f-string (backslash fix for Python < 3.12) ──
863
+ newline = "\n"
864
+ mrz_pattern = r'^[A-Z0-9<]{25,50}$'
865
+ ws_pattern = r'\s+'
866
+
867
+ mrz_raw_lines = []
868
+ for _l in raw_text.split("\n"):
869
+ _c = re.sub(ws_pattern, '', _l.strip())
870
+ if re.match(mrz_pattern, _c):
871
+ mrz_raw_lines.append(_c)
872
+ mrz_raw_display = newline.join(mrz_raw_lines) if mrz_raw_lines else "NOT PRESENT"
873
+ mrz_table_str = build_mrz_table(mrz_data) if mrz_data else "_No MRZ detected._"
874
 
875
+ # Pre-build Python-verified sections
876
+ python_sections = (
877
+ "## πŸ–ΌοΈ Visual Elements\n\n"
878
+ "| Element | Status | Location |\n"
879
+ "|---------|--------|----------|\n"
880
+ f"| πŸ“· Profile Photo | {metadata['photo_present']} | {metadata['photo_location']} |\n"
881
+ f"| ✍️ Signature | {metadata['sig_present']} | {metadata['sig_location']} |\n"
882
+ f"| πŸ” MRZ Zone | {metadata['mrz_present']} | Bottom strip |\n\n"
883
+ "---\n\n"
884
+ "## βœ… English Fields (Direct from Card β€” Not Modified)\n"
885
+ f"{cal_note}\n\n"
886
+ f"{tbl}\n\n"
887
+ "---\n\n"
888
+ "## πŸ“œ Original Script\n\n"
889
+ "```\n"
890
+ f"{raw_text}\n"
891
+ "```\n\n"
892
+ "---\n\n"
893
+ "## πŸ” MRZ Data\n\n"
894
+ "```\n"
895
+ f"{mrz_raw_display}\n"
896
+ "```\n\n"
897
+ f"{mrz_table_str}\n\n"
898
+ "---\n\n"
899
+ )
900
 
901
+ return streamer, thread, mrz_data, python_sections
 
902
 
 
 
903
 
904
  return streamer, thread, mrz_data, python_sections
905