Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -75,11 +75,24 @@ def run_ocr(uploaded_file):
|
|
| 75 |
pix.save(img_path)
|
| 76 |
page_images.append(img_path)
|
| 77 |
doc.close()
|
| 78 |
-
# parse() with list = one document, multiple pages
|
| 79 |
result = parse(page_images)
|
| 80 |
else:
|
| 81 |
result = parse(path)
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
# result.json_result: list of pages, each page = list of regions
|
| 84 |
# Region: {"label": "header"|"footer"|"text"|..., "content": "...", ...}
|
| 85 |
pages_data = result.json_result if hasattr(result, "json_result") else []
|
|
|
|
| 75 |
pix.save(img_path)
|
| 76 |
page_images.append(img_path)
|
| 77 |
doc.close()
|
|
|
|
| 78 |
result = parse(page_images)
|
| 79 |
else:
|
| 80 |
result = parse(path)
|
| 81 |
|
| 82 |
+
# ------ DEBUG: see what the SDK actually returns ------
|
| 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.json_result if hasattr(result, "json_result") else []
|