Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -238,15 +238,18 @@ def run_ocr(uploaded_file):
|
|
| 238 |
if is_pdf:
|
| 239 |
doc = fitz.open(path)
|
| 240 |
page_images = []
|
|
|
|
| 241 |
for i in range(len(doc)):
|
| 242 |
pix = doc[i].get_pixmap(matrix=fitz.Matrix(1.5, 1.5), alpha=False)
|
| 243 |
img_path = os.path.join(tempfile.gettempdir(), f"maas_page_{i}.png")
|
| 244 |
pix.save(img_path)
|
| 245 |
page_images.append(img_path)
|
|
|
|
| 246 |
doc.close()
|
| 247 |
results = parser.parse(page_images)
|
| 248 |
else:
|
| 249 |
page_images = [path]
|
|
|
|
| 250 |
results = parser.parse(path)
|
| 251 |
|
| 252 |
if not isinstance(results, list):
|
|
@@ -255,7 +258,8 @@ def run_ocr(uploaded_file):
|
|
| 255 |
all_pages = []
|
| 256 |
for page_num, page_result in enumerate(results):
|
| 257 |
page_md, regions = get_page_md_and_regions(page_result)
|
| 258 |
-
|
|
|
|
| 259 |
|
| 260 |
# MaaS does not return header/footer regions; always use at least default bands
|
| 261 |
he = header_end_frac if header_end_frac is not None else DEFAULT_ZONE_FRAC
|
|
|
|
| 238 |
if is_pdf:
|
| 239 |
doc = fitz.open(path)
|
| 240 |
page_images = []
|
| 241 |
+
page_heights = []
|
| 242 |
for i in range(len(doc)):
|
| 243 |
pix = doc[i].get_pixmap(matrix=fitz.Matrix(1.5, 1.5), alpha=False)
|
| 244 |
img_path = os.path.join(tempfile.gettempdir(), f"maas_page_{i}.png")
|
| 245 |
pix.save(img_path)
|
| 246 |
page_images.append(img_path)
|
| 247 |
+
page_heights.append(pix.height)
|
| 248 |
doc.close()
|
| 249 |
results = parser.parse(page_images)
|
| 250 |
else:
|
| 251 |
page_images = [path]
|
| 252 |
+
page_heights = []
|
| 253 |
results = parser.parse(path)
|
| 254 |
|
| 255 |
if not isinstance(results, list):
|
|
|
|
| 258 |
all_pages = []
|
| 259 |
for page_num, page_result in enumerate(results):
|
| 260 |
page_md, regions = get_page_md_and_regions(page_result)
|
| 261 |
+
img_h = page_heights[page_num] if page_num < len(page_heights) else 1000
|
| 262 |
+
header_end_frac, footer_start_frac = get_header_footer_zones(regions, img_h)
|
| 263 |
|
| 264 |
# MaaS does not return header/footer regions; always use at least default bands
|
| 265 |
he = header_end_frac if header_end_frac is not None else DEFAULT_ZONE_FRAC
|