rehan953 commited on
Commit
5b740d1
Β·
verified Β·
1 Parent(s): e39f572

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -19
app.py CHANGED
@@ -79,25 +79,9 @@ def run_ocr(uploaded_file):
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 []
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 (set in Space secrets).
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",