Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2480,7 +2480,7 @@ def _extract_nfcu_summary_table(pdf_path: str, page_num: int) -> str:
|
|
| 2480 |
money_re = re.compile(r"^\$?[\d,]+\.\d{2}-?$")
|
| 2481 |
acct_no_re = re.compile(r"^\d{8,12}$")
|
| 2482 |
stop_re = re.compile(
|
| 2483 |
-
r"(business checking\s*-|mbr business savings\s*-|date\s+transaction\s+detail|items paid
|
| 2484 |
re.IGNORECASE,
|
| 2485 |
)
|
| 2486 |
|
|
@@ -2600,26 +2600,29 @@ def _split_fused_date_transaction_header(grid):
|
|
| 2600 |
if ncols < 3:
|
| 2601 |
return grid
|
| 2602 |
|
| 2603 |
-
|
| 2604 |
-
|
| 2605 |
-
|
| 2606 |
-
|
| 2607 |
-
|
| 2608 |
-
|
| 2609 |
-
|
| 2610 |
-
|
| 2611 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2612 |
return grid
|
| 2613 |
|
| 2614 |
date_tok = re.compile(r"^\d{1,2}(?:[-/])\d{2}(?:[-/]\d{2,4})?$")
|
| 2615 |
|
| 2616 |
new_grid = []
|
| 2617 |
-
|
| 2618 |
-
new_grid.append(new_header)
|
| 2619 |
-
|
| 2620 |
-
for row in grid[1:]:
|
| 2621 |
cells = [str(c or "").strip() for c in (row + [""] * (ncols - len(row)))]
|
| 2622 |
-
first = cells[
|
| 2623 |
dval = ""
|
| 2624 |
tval = first
|
| 2625 |
if first:
|
|
@@ -2627,7 +2630,17 @@ def _split_fused_date_transaction_header(grid):
|
|
| 2627 |
if parts and date_tok.match(parts[0]):
|
| 2628 |
dval = parts[0]
|
| 2629 |
tval = " ".join(parts[1:]).strip()
|
| 2630 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2631 |
return new_grid
|
| 2632 |
|
| 2633 |
def normalize_html_tables(text: str) -> str:
|
|
|
|
| 2480 |
money_re = re.compile(r"^\$?[\d,]+\.\d{2}-?$")
|
| 2481 |
acct_no_re = re.compile(r"^\d{8,12}$")
|
| 2482 |
stop_re = re.compile(
|
| 2483 |
+
r"(business checking\s*-|mbr business savings\s*-|date\s+transaction\s+detail|items paid)",
|
| 2484 |
re.IGNORECASE,
|
| 2485 |
)
|
| 2486 |
|
|
|
|
| 2600 |
if ncols < 3:
|
| 2601 |
return grid
|
| 2602 |
|
| 2603 |
+
header_row_idx = None
|
| 2604 |
+
fused_col_idx = None
|
| 2605 |
+
for ri in range(min(4, len(grid))):
|
| 2606 |
+
r = [str(c or "").strip() for c in (grid[ri] + [""] * (ncols - len(grid[ri])))]
|
| 2607 |
+
for ci, c in enumerate(r):
|
| 2608 |
+
cc = re.sub(r"\s+", " ", c).strip().lower()
|
| 2609 |
+
if cc == "date transaction detail":
|
| 2610 |
+
row_text = " ".join(re.sub(r"\s+", " ", x).strip().lower() for x in r)
|
| 2611 |
+
if "amount" in row_text and "balance" in row_text:
|
| 2612 |
+
header_row_idx = ri
|
| 2613 |
+
fused_col_idx = ci
|
| 2614 |
+
break
|
| 2615 |
+
if header_row_idx is not None:
|
| 2616 |
+
break
|
| 2617 |
+
if header_row_idx is None or fused_col_idx is None:
|
| 2618 |
return grid
|
| 2619 |
|
| 2620 |
date_tok = re.compile(r"^\d{1,2}(?:[-/])\d{2}(?:[-/]\d{2,4})?$")
|
| 2621 |
|
| 2622 |
new_grid = []
|
| 2623 |
+
for ri, row in enumerate(grid):
|
|
|
|
|
|
|
|
|
|
| 2624 |
cells = [str(c or "").strip() for c in (row + [""] * (ncols - len(row)))]
|
| 2625 |
+
first = cells[fused_col_idx]
|
| 2626 |
dval = ""
|
| 2627 |
tval = first
|
| 2628 |
if first:
|
|
|
|
| 2630 |
if parts and date_tok.match(parts[0]):
|
| 2631 |
dval = parts[0]
|
| 2632 |
tval = " ".join(parts[1:]).strip()
|
| 2633 |
+
if ri == header_row_idx:
|
| 2634 |
+
split_row = (
|
| 2635 |
+
cells[:fused_col_idx]
|
| 2636 |
+
+ ["Date", "Transaction Detail"]
|
| 2637 |
+
+ cells[fused_col_idx + 1:]
|
| 2638 |
+
)
|
| 2639 |
+
elif ri < header_row_idx:
|
| 2640 |
+
split_row = cells[:fused_col_idx] + [cells[fused_col_idx], ""] + cells[fused_col_idx + 1:]
|
| 2641 |
+
else:
|
| 2642 |
+
split_row = cells[:fused_col_idx] + [dval, tval] + cells[fused_col_idx + 1:]
|
| 2643 |
+
new_grid.append(split_row)
|
| 2644 |
return new_grid
|
| 2645 |
|
| 2646 |
def normalize_html_tables(text: str) -> str:
|