rehan953 commited on
Commit
499765d
·
verified ·
1 Parent(s): 678d4a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -208,15 +208,27 @@ def ocr_zone(image_path, y_start_frac, y_end_frac):
208
 
209
 
210
  def fix_account_number(hdr):
211
- """If hdr contains Account Number: with no value, inject the number from hdr."""
 
 
 
212
  import re
213
  if not hdr:
214
  return hdr
 
215
  if "Account Number:" in hdr and not re.search("Account Number: [0-9]", hdr):
216
  match = re.search("[0-9]{5,}", hdr)
217
  if match:
218
  acct = match.group(0)
219
  hdr = hdr.replace("Account Number:", "Account Number: " + acct)
 
 
 
 
 
 
 
 
220
  return hdr
221
 
222
 
 
208
 
209
 
210
  def fix_account_number(hdr):
211
+ """Fix header text:
212
+ 1. If Account Number: has no value, find the number and inject it.
213
+ 2. Remove any leading standalone number that is duplicated elsewhere in hdr.
214
+ """
215
  import re
216
  if not hdr:
217
  return hdr
218
+ # Step 1: inject account number if missing after label
219
  if "Account Number:" in hdr and not re.search("Account Number: [0-9]", hdr):
220
  match = re.search("[0-9]{5,}", hdr)
221
  if match:
222
  acct = match.group(0)
223
  hdr = hdr.replace("Account Number:", "Account Number: " + acct)
224
+ # Step 2: remove leading number that is duplicated after Account Number:
225
+ # e.g. "000000731823008 JPMorgan ... Account Number: 000000731823008"
226
+ # -> "JPMorgan ... Account Number: 000000731823008"
227
+ acct_match = re.search("Account Number:\s*([0-9]{5,})", hdr)
228
+ if acct_match:
229
+ acct = acct_match.group(1)
230
+ # If hdr starts with that same number, remove it from the start
231
+ hdr = re.sub("^" + re.escape(acct) + "\s*", "", hdr)
232
  return hdr
233
 
234