rehan953 commited on
Commit
97234d4
·
verified ·
1 Parent(s): 4e256e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -2682,6 +2682,20 @@ def run_ocr(uploaded_file):
2682
 
2683
  parts = []
2684
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2685
  # Header inclusion: PDF text -> band words -> OCR band
2686
  hdr = ""
2687
  if is_pdf:
@@ -2732,22 +2746,6 @@ def run_ocr(uploaded_file):
2732
 
2733
  parts.append(stabilized)
2734
 
2735
- # Fix NF-1: full text-layer parse for Navy Federal statements.
2736
- # GLM-OCR fails on NFCU pages (summary table, transaction columns,
2737
- # multi-line descriptions). When NFCU is detected, replace the OCR
2738
- # body with a clean text-layer extraction and clear the parts list
2739
- # to avoid mixing garbled OCR output with correct text-layer data.
2740
- # Safe no-op for all non-NFCU PDFs (_parse_nfcu_page returns "").
2741
- if is_pdf:
2742
- try:
2743
- nfcu_html = _parse_nfcu_page(path, page_num)
2744
- if nfcu_html:
2745
- # Replace ALL parts with the text-layer result —
2746
- # discard garbled OCR header/body/footer for this page
2747
- parts = [nfcu_html]
2748
- except Exception:
2749
- pass # safe no-op — falls back to OCR output on any error
2750
-
2751
  # Footer extraction: PDF text layer -> band words -> OCR crop
2752
  # Deduplication guard prevents double-printing when body OCR already captured it.
2753
  if ENABLE_FOOTER_OCR and page_num < len(page_images):
 
2682
 
2683
  parts = []
2684
 
2685
+ # Fix NF-1: Navy Federal full text-layer parse.
2686
+ # Must run FIRST — before header/OCR/footer — so that when NFCU is
2687
+ # detected, the entire page output is replaced with clean text-layer
2688
+ # data and none of the garbled OCR pipeline runs at all.
2689
+ # Safe no-op for all other banks (_parse_nfcu_page returns "").
2690
+ if is_pdf:
2691
+ try:
2692
+ nfcu_html = _parse_nfcu_page(path, page_num)
2693
+ if nfcu_html:
2694
+ all_pages.append(nfcu_html)
2695
+ continue # skip ALL OCR processing for this page
2696
+ except Exception:
2697
+ pass # fall through to normal OCR pipeline on any error
2698
+
2699
  # Header inclusion: PDF text -> band words -> OCR band
2700
  hdr = ""
2701
  if is_pdf:
 
2746
 
2747
  parts.append(stabilized)
2748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2749
  # Footer extraction: PDF text layer -> band words -> OCR crop
2750
  # Deduplication guard prevents double-printing when body OCR already captured it.
2751
  if ENABLE_FOOTER_OCR and page_num < len(page_images):