Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1166,8 +1166,24 @@ def _patch_ocr_with_textlayer(page_md: str, pdf_path: str, page_num: int) -> str
|
|
| 1166 |
return page_md
|
| 1167 |
|
| 1168 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1169 |
tl_rows = _extract_textlayer_rows(pdf_path, page_num)
|
| 1170 |
if not tl_rows:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1171 |
return page_md # scanned PDF or non-transaction page — safe no-op
|
| 1172 |
|
| 1173 |
def _norm(s):
|
|
@@ -1379,17 +1395,8 @@ def _patch_ocr_with_textlayer(page_md: str, pdf_path: str, page_num: int) -> str
|
|
| 1379 |
# if missing from OCR but present in PDF text layer.
|
| 1380 |
needs_checks = "checks" not in result.lower() or "<th>Number</th>" not in result
|
| 1381 |
needs_dab = "daily account balance" not in result.lower()
|
| 1382 |
-
if needs_checks or needs_dab:
|
| 1383 |
-
|
| 1384 |
-
try:
|
| 1385 |
-
import pymupdf as _fitz
|
| 1386 |
-
_doc = _fitz.open(pdf_path)
|
| 1387 |
-
_page = _doc[page_num]
|
| 1388 |
-
raw_tl = _page.get_text()
|
| 1389 |
-
_doc.close()
|
| 1390 |
-
except Exception:
|
| 1391 |
-
raw_tl = ""
|
| 1392 |
-
jb_extra = _extract_jb_summary_sections(raw_tl, needs_checks, needs_dab)
|
| 1393 |
if jb_extra:
|
| 1394 |
result = result.rstrip() + "\n\n" + jb_extra
|
| 1395 |
|
|
|
|
| 1166 |
return page_md
|
| 1167 |
|
| 1168 |
try:
|
| 1169 |
+
# Extract raw page text once — reused by Fix 4D for JB summary sections
|
| 1170 |
+
try:
|
| 1171 |
+
import pymupdf as _fitz_patch
|
| 1172 |
+
_doc_patch = _fitz_patch.open(pdf_path)
|
| 1173 |
+
_raw_page_text = _doc_patch[page_num].get_text()
|
| 1174 |
+
_doc_patch.close()
|
| 1175 |
+
except Exception:
|
| 1176 |
+
_raw_page_text = ""
|
| 1177 |
+
|
| 1178 |
tl_rows = _extract_textlayer_rows(pdf_path, page_num)
|
| 1179 |
if not tl_rows:
|
| 1180 |
+
# Even if no transaction rows, still run Fix 4D for JB summary sections
|
| 1181 |
+
needs_checks = "checks" not in page_md.lower() or "<th>Number</th>" not in page_md
|
| 1182 |
+
needs_dab = "daily account balance" not in page_md.lower()
|
| 1183 |
+
if _raw_page_text and (needs_checks or needs_dab):
|
| 1184 |
+
jb_extra = _extract_jb_summary_sections(_raw_page_text, needs_checks, needs_dab)
|
| 1185 |
+
if jb_extra:
|
| 1186 |
+
return page_md.rstrip() + "\n\n" + jb_extra
|
| 1187 |
return page_md # scanned PDF or non-transaction page — safe no-op
|
| 1188 |
|
| 1189 |
def _norm(s):
|
|
|
|
| 1395 |
# if missing from OCR but present in PDF text layer.
|
| 1396 |
needs_checks = "checks" not in result.lower() or "<th>Number</th>" not in result
|
| 1397 |
needs_dab = "daily account balance" not in result.lower()
|
| 1398 |
+
if _raw_page_text and (needs_checks or needs_dab):
|
| 1399 |
+
jb_extra = _extract_jb_summary_sections(_raw_page_text, needs_checks, needs_dab)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1400 |
if jb_extra:
|
| 1401 |
result = result.rstrip() + "\n\n" + jb_extra
|
| 1402 |
|