Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 868 |
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 884 |
|
| 885 |
-
|
| 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 |
|