rehan953 commited on
Commit
0686c8e
·
verified ·
1 Parent(s): 5bef6c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -2175,15 +2175,13 @@ def _is_nfcu_document(pdf_path: str) -> bool:
2175
  text += "\n" + (doc[i].get_text() or "")
2176
  doc.close()
2177
  t = text.lower()
2178
- # Accept either explicit Navy branding OR the NFCU statement signature fields.
2179
- has_brand = ("navy federal" in t or "navyfederal.org" in t)
2180
- has_signature_fields = (
2181
  ("statement of account" in t)
2182
- and ("statement period" in t)
2183
  and ("access no." in t)
2184
  and ("routing number" in t)
 
2185
  )
2186
- return has_brand or has_signature_fields
2187
  except Exception:
2188
  return False
2189
 
@@ -2544,7 +2542,6 @@ def run_ocr(uploaded_file):
2544
  path = uploaded_file.name if hasattr(uploaded_file, "name") else str(uploaded_file)
2545
  is_pdf = path.lower().endswith(".pdf")
2546
  is_nfcu_doc = _is_nfcu_document(path) if is_pdf else False
2547
- nfcu_mode = is_nfcu_doc
2548
  parser = get_parser()
2549
 
2550
  page_heights = []
@@ -2579,15 +2576,13 @@ def run_ocr(uploaded_file):
2579
  # detected, the entire page output is replaced with clean text-layer
2580
  # data and none of the garbled OCR pipeline runs at all.
2581
  # Safe no-op for all other banks (_parse_nfcu_page returns "").
2582
- # Try NFCU structured parsing on known NFCU docs, and on page 1 as a probe.
2583
- if is_pdf and (nfcu_mode or page_num == 0):
2584
  nfcu_html = _parse_nfcu_page(path, page_num)
2585
  if nfcu_html:
2586
- nfcu_mode = True
2587
  all_pages.append(nfcu_html)
2588
  continue # skip ALL OCR processing for this page
2589
- if nfcu_mode:
2590
- log.warning("NFCU parser returned empty output for page %d", page_num + 1)
2591
 
2592
  # Header inclusion: PDF text -> band words -> OCR band
2593
  hdr = ""
 
2175
  text += "\n" + (doc[i].get_text() or "")
2176
  doc.close()
2177
  t = text.lower()
2178
+ # Strict Navy-only guard to avoid affecting other statement types.
2179
+ return (
 
2180
  ("statement of account" in t)
 
2181
  and ("access no." in t)
2182
  and ("routing number" in t)
2183
+ and ("navy federal" in t or "navyfederal.org" in t)
2184
  )
 
2185
  except Exception:
2186
  return False
2187
 
 
2542
  path = uploaded_file.name if hasattr(uploaded_file, "name") else str(uploaded_file)
2543
  is_pdf = path.lower().endswith(".pdf")
2544
  is_nfcu_doc = _is_nfcu_document(path) if is_pdf else False
 
2545
  parser = get_parser()
2546
 
2547
  page_heights = []
 
2576
  # detected, the entire page output is replaced with clean text-layer
2577
  # data and none of the garbled OCR pipeline runs at all.
2578
  # Safe no-op for all other banks (_parse_nfcu_page returns "").
2579
+ # NFCU-only path; no probing on non-NFCU files.
2580
+ if is_pdf and is_nfcu_doc:
2581
  nfcu_html = _parse_nfcu_page(path, page_num)
2582
  if nfcu_html:
 
2583
  all_pages.append(nfcu_html)
2584
  continue # skip ALL OCR processing for this page
2585
+ log.warning("NFCU parser returned empty output for page %d", page_num + 1)
 
2586
 
2587
  # Header inclusion: PDF text -> band words -> OCR band
2588
  hdr = ""