Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -79,25 +79,9 @@ def run_ocr(uploaded_file):
|
|
| 79 |
else:
|
| 80 |
result = parse(path)
|
| 81 |
|
| 82 |
-
#
|
| 83 |
-
try:
|
| 84 |
-
debug = {
|
| 85 |
-
"type_result": type(result).__name__,
|
| 86 |
-
"dir_result": [x for x in dir(result) if not x.startswith("_")],
|
| 87 |
-
"json_result_type": type(getattr(result, "json_result", None)).__name__,
|
| 88 |
-
"json_result_len": len(result.json_result) if getattr(result, "json_result", None) else 0,
|
| 89 |
-
"json_result_sample": str(getattr(result, "json_result", None))[:500],
|
| 90 |
-
}
|
| 91 |
-
return str(debug), "Debug"
|
| 92 |
-
except Exception as e:
|
| 93 |
-
return str(e), "Error"
|
| 94 |
-
# ------ END DEBUG (remove this block after you see the output) ------
|
| 95 |
-
|
| 96 |
-
# result.json_result: list of pages, each page = list of regions
|
| 97 |
# Region: {"label": "header"|"footer"|"text"|..., "content": "...", ...}
|
| 98 |
-
pages_data = result
|
| 99 |
-
if not isinstance(pages_data, list):
|
| 100 |
-
pages_data = [pages_data] if pages_data else []
|
| 101 |
|
| 102 |
total_headers = 0
|
| 103 |
total_footers = 0
|
|
@@ -154,7 +138,7 @@ with gr.Blocks(title="GLM-OCR β MaaS (Header & Footer)") as demo:
|
|
| 154 |
gr.Markdown("""
|
| 155 |
# π GLM-OCR β Zhipu MaaS
|
| 156 |
Upload PDF or image. Headers π΅ and Footers π’ from the **full pipeline** (layout + OCR).
|
| 157 |
-
Uses your Zhipu API key
|
| 158 |
""")
|
| 159 |
file_input = gr.File(
|
| 160 |
label="Upload PDF or Image",
|
|
|
|
| 79 |
else:
|
| 80 |
result = parse(path)
|
| 81 |
|
| 82 |
+
# parse() returns a list directly (list of pages, each page = list of regions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
# Region: {"label": "header"|"footer"|"text"|..., "content": "...", ...}
|
| 84 |
+
pages_data = result if isinstance(result, list) else []
|
|
|
|
|
|
|
| 85 |
|
| 86 |
total_headers = 0
|
| 87 |
total_footers = 0
|
|
|
|
| 138 |
gr.Markdown("""
|
| 139 |
# π GLM-OCR β Zhipu MaaS
|
| 140 |
Upload PDF or image. Headers π΅ and Footers π’ from the **full pipeline** (layout + OCR).
|
| 141 |
+
Uses your Zhipu API key.
|
| 142 |
""")
|
| 143 |
file_input = gr.File(
|
| 144 |
label="Upload PDF or Image",
|