Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -126,6 +126,8 @@ Primary goals for reconcile rate:
|
|
| 126 |
Gap between tables must not contain another <table> or page-separator.
|
| 127 |
- Fix MD-2: Skip blank-header column merge for YOUR CHECKS SEQUENCED–style tables (title + repeated
|
| 128 |
Amount columns + blank th between triplets); merge was collapsing multi-column check rows.
|
|
|
|
|
|
|
| 129 |
- Fix MD-3: Check image pages — GLM often emits  plus <div align="center"> fragments
|
| 130 |
(e.g. 2293 $6,721.00 4/29/2025). Collapse detected gallery pages into one Check #|Amount|Date
|
| 131 |
table when bbox/image markers + repeated check lines are present; skips chunks with YOUR CHECKS SEQUENCED.
|
|
@@ -550,6 +552,28 @@ def _is_multigroup_check_list_header(header: List[str]) -> bool:
|
|
| 550 |
return False
|
| 551 |
|
| 552 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
def _merge_blank_header_text_columns(grid):
|
| 554 |
if not grid or len(grid) < 2:
|
| 555 |
return grid
|
|
@@ -557,6 +581,8 @@ def _merge_blank_header_text_columns(grid):
|
|
| 557 |
header = [str(c or "").strip() for c in grid[0]]
|
| 558 |
if _is_multigroup_check_list_header(header):
|
| 559 |
return grid
|
|
|
|
|
|
|
| 560 |
|
| 561 |
ncols = len(header)
|
| 562 |
body = grid[1:]
|
|
@@ -5009,6 +5035,16 @@ def _maybe_convert_check_image_gallery_chunk(chunk: str) -> str:
|
|
| 5009 |
return chunk
|
| 5010 |
if "YOUR CHECKS SEQUENCED" in chunk.upper():
|
| 5011 |
return chunk
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5012 |
|
| 5013 |
matches = list(_CHECK_IMAGE_GALLERY_LINE_RE.finditer(chunk))
|
| 5014 |
if len(matches) < 2:
|
|
|
|
| 126 |
Gap between tables must not contain another <table> or page-separator.
|
| 127 |
- Fix MD-2: Skip blank-header column merge for YOUR CHECKS SEQUENCED–style tables (title + repeated
|
| 128 |
Amount columns + blank th between triplets); merge was collapsing multi-column check rows.
|
| 129 |
+
Also skip when the table is ACCOUNT HISTORY / DEPOSIT+WITHDRAWAL (First Horizon–style): blank
|
| 130 |
+
<th> align subheaders on the next row; merge was fusing DEPOSIT/WITHDRAWAL/CARD into wrong columns.
|
| 131 |
- Fix MD-3: Check image pages — GLM often emits  plus <div align="center"> fragments
|
| 132 |
(e.g. 2293 $6,721.00 4/29/2025). Collapse detected gallery pages into one Check #|Amount|Date
|
| 133 |
table when bbox/image markers + repeated check lines are present; skips chunks with YOUR CHECKS SEQUENCED.
|
|
|
|
| 552 |
return False
|
| 553 |
|
| 554 |
|
| 555 |
+
def _should_skip_blank_header_merge_multiline_register(grid) -> bool:
|
| 556 |
+
"""
|
| 557 |
+
Some banks (e.g. First Horizon) use a title row with blank <th> cells, then a second header
|
| 558 |
+
row with DATE DESCRIPTION | DEPOSIT | WITHDRAWAL | CARD #. _merge_blank_header_text_columns
|
| 559 |
+
would treat those blanks as OCR splits and merge columns — corrupting the grid.
|
| 560 |
+
"""
|
| 561 |
+
if not grid or len(grid) < 2:
|
| 562 |
+
return False
|
| 563 |
+
h0_join = " ".join(str(c or "").strip() for c in grid[0]).upper()
|
| 564 |
+
if "ACCOUNT HISTORY" in h0_join:
|
| 565 |
+
return True
|
| 566 |
+
for ri in range(1, min(5, len(grid))):
|
| 567 |
+
cells = [str(c or "").strip().upper() for c in grid[ri]]
|
| 568 |
+
if not any(cells):
|
| 569 |
+
continue
|
| 570 |
+
row_join = " ".join(cells)
|
| 571 |
+
if "DEPOSIT" in row_join and "WITHDRAWAL" in row_join:
|
| 572 |
+
if "DATE" in row_join or "DESCRIPTION" in row_join:
|
| 573 |
+
return True
|
| 574 |
+
return False
|
| 575 |
+
|
| 576 |
+
|
| 577 |
def _merge_blank_header_text_columns(grid):
|
| 578 |
if not grid or len(grid) < 2:
|
| 579 |
return grid
|
|
|
|
| 581 |
header = [str(c or "").strip() for c in grid[0]]
|
| 582 |
if _is_multigroup_check_list_header(header):
|
| 583 |
return grid
|
| 584 |
+
if _should_skip_blank_header_merge_multiline_register(grid):
|
| 585 |
+
return grid
|
| 586 |
|
| 587 |
ncols = len(header)
|
| 588 |
body = grid[1:]
|
|
|
|
| 5035 |
return chunk
|
| 5036 |
if "YOUR CHECKS SEQUENCED" in chunk.upper():
|
| 5037 |
return chunk
|
| 5038 |
+
cu = chunk.upper()
|
| 5039 |
+
# Statement summary / register pages (e.g. First Horizon) may include bbox images; do not
|
| 5040 |
+
# replace the whole chunk with a synthetic check table.
|
| 5041 |
+
if "DAILY BALANCE SUMMARY" in cu or "CHECKING ACCOUNT MONTHLY SUMMARY" in cu:
|
| 5042 |
+
return chunk
|
| 5043 |
+
if "ACCOUNT SUMMARY" in cu and "NEW BALANCE" in cu and "<table" in chunk.lower():
|
| 5044 |
+
return chunk
|
| 5045 |
+
n_tr = len(re.findall(r"<tr\b", chunk, re.IGNORECASE))
|
| 5046 |
+
if n_tr > 24:
|
| 5047 |
+
return chunk
|
| 5048 |
|
| 5049 |
matches = list(_CHECK_IMAGE_GALLERY_LINE_RE.finditer(chunk))
|
| 5050 |
if len(matches) < 2:
|