Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -54,28 +54,20 @@ def run_ocr(uploaded_file):
|
|
| 54 |
else:
|
| 55 |
result = parse(path)
|
| 56 |
|
| 57 |
-
# ------ DEBUG: right after parse() ------
|
| 58 |
debug_lines = ["========== DEBUG =========="]
|
| 59 |
debug_lines.append(f"1. result type: {type(result).__name__}")
|
| 60 |
-
debug_lines.append(f"2. result length: {len(result) if isinstance(result, list) else 'N/A
|
| 61 |
if isinstance(result, list) and len(result) > 0:
|
| 62 |
first = result[0]
|
| 63 |
debug_lines.append(f"3. first element type: {type(first).__name__}")
|
| 64 |
-
debug_lines.append(f"4.
|
| 65 |
-
debug_lines.append(f"5. has
|
| 66 |
-
debug_lines.append(f"6. has json_result: {hasattr(first, 'json_result')}")
|
| 67 |
if hasattr(first, "markdown_result"):
|
| 68 |
md = getattr(first, "markdown_result", None)
|
| 69 |
-
debug_lines.append(f"
|
| 70 |
-
if md:
|
| 71 |
-
debug_lines.append(f"8. markdown_result snippet (first 200 chars): {repr((md or '')[:200])}")
|
| 72 |
if hasattr(first, "json_result"):
|
| 73 |
j = getattr(first, "json_result", None)
|
| 74 |
-
debug_lines.append(f"
|
| 75 |
-
if j and len(j) > 0:
|
| 76 |
-
debug_lines.append(f"10. json_result[0] (first page) type: {type(j[0]).__name__}, len: {len(j[0]) if isinstance(j[0], list) else 'N/A'}")
|
| 77 |
-
if isinstance(j[0], list) and len(j[0]) > 0:
|
| 78 |
-
debug_lines.append(f"11. first region keys: {list(j[0][0].keys()) if isinstance(j[0][0], dict) else 'not a dict'}")
|
| 79 |
debug_lines.append("==========================")
|
| 80 |
|
| 81 |
if not isinstance(result, list):
|
|
@@ -98,8 +90,15 @@ def run_ocr(uploaded_file):
|
|
| 98 |
pages_data.append(page)
|
| 99 |
markdown = "\n\n---\n\n".join(markdown_parts)
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
total_headers = 0
|
| 105 |
total_footers = 0
|
|
@@ -181,7 +180,7 @@ def run_ocr(uploaded_file):
|
|
| 181 |
|
| 182 |
|
| 183 |
with gr.Blocks(title="GLM-OCR β MaaS") as demo:
|
| 184 |
-
gr.Markdown("# π GLM-OCR β Zhipu MaaS\nUpload PDF or image.
|
| 185 |
file_input = gr.File(label="Upload PDF or Image", file_types=[".pdf", ".png", ".jpg", ".jpeg", ".tiff", ".bmp"])
|
| 186 |
run_btn = gr.Button("βΆ Run OCR", variant="primary", size="lg")
|
| 187 |
with gr.Row():
|
|
|
|
| 54 |
else:
|
| 55 |
result = parse(path)
|
| 56 |
|
|
|
|
| 57 |
debug_lines = ["========== DEBUG =========="]
|
| 58 |
debug_lines.append(f"1. result type: {type(result).__name__}")
|
| 59 |
+
debug_lines.append(f"2. result length: {len(result) if isinstance(result, list) else 'N/A'}")
|
| 60 |
if isinstance(result, list) and len(result) > 0:
|
| 61 |
first = result[0]
|
| 62 |
debug_lines.append(f"3. first element type: {type(first).__name__}")
|
| 63 |
+
debug_lines.append(f"4. has markdown_result: {hasattr(first, 'markdown_result')}")
|
| 64 |
+
debug_lines.append(f"5. has json_result: {hasattr(first, 'json_result')}")
|
|
|
|
| 65 |
if hasattr(first, "markdown_result"):
|
| 66 |
md = getattr(first, "markdown_result", None)
|
| 67 |
+
debug_lines.append(f"6. markdown_result len: {len(md) if md else 0}")
|
|
|
|
|
|
|
| 68 |
if hasattr(first, "json_result"):
|
| 69 |
j = getattr(first, "json_result", None)
|
| 70 |
+
debug_lines.append(f"7. json_result len: {len(j) if j else 0}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
debug_lines.append("==========================")
|
| 72 |
|
| 73 |
if not isinstance(result, list):
|
|
|
|
| 90 |
pages_data.append(page)
|
| 91 |
markdown = "\n\n---\n\n".join(markdown_parts)
|
| 92 |
|
| 93 |
+
labels_seen = set()
|
| 94 |
+
for page in pages_data:
|
| 95 |
+
if not isinstance(page, list):
|
| 96 |
+
continue
|
| 97 |
+
for r in page:
|
| 98 |
+
if isinstance(r, dict):
|
| 99 |
+
labels_seen.add(r.get("label", ""))
|
| 100 |
+
debug_lines.append(f"8. ALL labels from API: {sorted(labels_seen)}")
|
| 101 |
+
debug_lines.append(f"9. markdown_parts: {len(markdown_parts)}, pages_data: {len(pages_data)}")
|
| 102 |
|
| 103 |
total_headers = 0
|
| 104 |
total_footers = 0
|
|
|
|
| 180 |
|
| 181 |
|
| 182 |
with gr.Blocks(title="GLM-OCR β MaaS") as demo:
|
| 183 |
+
gr.Markdown("# π GLM-OCR β Zhipu MaaS\nUpload PDF or image.")
|
| 184 |
file_input = gr.File(label="Upload PDF or Image", file_types=[".pdf", ".png", ".jpg", ".jpeg", ".tiff", ".bmp"])
|
| 185 |
run_btn = gr.Button("βΆ Run OCR", variant="primary", size="lg")
|
| 186 |
with gr.Row():
|