rehan953 commited on
Commit
1d3dd4c
·
verified ·
1 Parent(s): 870dc2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -977,10 +977,11 @@ def _extract_textlayer_rows(pdf_path: str, page_num: int):
977
  line_words = sorted(lines_by_y[y], key=lambda t: t[0])
978
  sorted_lines.append([w for _, w in line_words])
979
 
980
- # Date patterns — numeric (MM/DD variants) or month-name (Jan 16)
981
  _MONTHS = r"(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"
982
  date_re = re.compile(
983
  r"^\d{1,2}/\d{2}(?:/\d{2,4})?$" # MM/DD, MM/DD/YY, MM/DD/YYYY
 
984
  r"|^\d{4}-\d{2}-\d{2}$" # YYYY-MM-DD
985
  r"|^" + _MONTHS + r"$", # "Jan", "Feb" etc (month-name date part 1)
986
  re.IGNORECASE,
@@ -1553,6 +1554,8 @@ def run_ocr(uploaded_file):
1553
  ftr = ocr_zone(page_images[page_num], fs, 1.0)
1554
  if ftr and ftr.strip():
1555
  ftr_clean = normalize_money_glyphs(ftr.strip())
 
 
1556
  ftr_first_line = next(
1557
  (ln.strip().lower() for ln in ftr_clean.splitlines() if ln.strip()),
1558
  ""
@@ -1560,7 +1563,19 @@ def run_ocr(uploaded_file):
1560
  already_present = ftr_first_line and any(
1561
  ftr_first_line in part.lower() for part in parts
1562
  )
1563
- if not already_present:
 
 
 
 
 
 
 
 
 
 
 
 
1564
  parts.append(ftr_clean)
1565
 
1566
  if parts:
 
977
  line_words = sorted(lines_by_y[y], key=lambda t: t[0])
978
  sorted_lines.append([w for _, w in line_words])
979
 
980
+ # Date patterns — numeric (MM/DD, MM-DD variants) or month-name (Jan 16)
981
  _MONTHS = r"(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"
982
  date_re = re.compile(
983
  r"^\d{1,2}/\d{2}(?:/\d{2,4})?$" # MM/DD, MM/DD/YY, MM/DD/YYYY
984
+ r"|^\d{1,2}-\d{2}(?:-\d{2,4})?$" # MM-DD, MM-DD-YY (East West Bank)
985
  r"|^\d{4}-\d{2}-\d{2}$" # YYYY-MM-DD
986
  r"|^" + _MONTHS + r"$", # "Jan", "Feb" etc (month-name date part 1)
987
  re.IGNORECASE,
 
1554
  ftr = ocr_zone(page_images[page_num], fs, 1.0)
1555
  if ftr and ftr.strip():
1556
  ftr_clean = normalize_money_glyphs(ftr.strip())
1557
+
1558
+ # Guard 1: first-line dedup (original check)
1559
  ftr_first_line = next(
1560
  (ln.strip().lower() for ln in ftr_clean.splitlines() if ln.strip()),
1561
  ""
 
1563
  already_present = ftr_first_line and any(
1564
  ftr_first_line in part.lower() for part in parts
1565
  )
1566
+
1567
+ # Guard 2: suppress footer that is a raw text-layer dump of
1568
+ # transaction rows (e.g. East West Bank two-column layout).
1569
+ # Detected when the footer contains 3+ date tokens (MM/DD or MM-DD)
1570
+ # AND the page already has an OCR table — the table already
1571
+ # captured this data correctly, so the footer text is redundant.
1572
+ _footer_date_re = re.compile(r"\b\d{1,2}[-/]\d{2}\b")
1573
+ is_txn_dump = (
1574
+ len(_footer_date_re.findall(ftr_clean)) >= 3
1575
+ and any("<table" in part.lower() for part in parts)
1576
+ )
1577
+
1578
+ if not already_present and not is_txn_dump:
1579
  parts.append(ftr_clean)
1580
 
1581
  if parts: