Update app.py
Browse files
app.py
CHANGED
|
@@ -218,7 +218,7 @@ def weighted_fuzzy_score(s1, s2):
|
|
| 218 |
return fuzz.token_set_ratio(str(s1).lower(), str(s2).lower())
|
| 219 |
|
| 220 |
def find_po_number_in_json(po_number, invoice_json):
|
| 221 |
-
"""
|
| 222 |
def _flatten(obj):
|
| 223 |
fields = []
|
| 224 |
if isinstance(obj, dict):
|
|
@@ -227,13 +227,29 @@ def find_po_number_in_json(po_number, invoice_json):
|
|
| 227 |
elif isinstance(obj, list):
|
| 228 |
for item in obj:
|
| 229 |
fields.extend(_flatten(item))
|
| 230 |
-
elif
|
| 231 |
-
fields.append(obj)
|
| 232 |
return fields
|
| 233 |
|
| 234 |
-
|
| 235 |
-
po_str = str(po_number).replace(" ", "").
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
def find_best_po_match(inv, po_df):
|
| 239 |
inv_hdr = inv["invoice_header"]
|
|
@@ -548,7 +564,7 @@ if po_df is not None:
|
|
| 548 |
|
| 549 |
if extracted_info is not None and po_df is not None:
|
| 550 |
st.markdown("---")
|
| 551 |
-
st.subheader("EZOFIS AP AGENT Decision
|
| 552 |
if st.button("Make a decision (EZOFIS AP AGENT)"):
|
| 553 |
tools = [
|
| 554 |
Tool(
|
|
|
|
| 218 |
return fuzz.token_set_ratio(str(s1).lower(), str(s2).lower())
|
| 219 |
|
| 220 |
def find_po_number_in_json(po_number, invoice_json):
|
| 221 |
+
"""Search for PO number (as string/int) anywhere in the invoice JSON, ignoring .0 floats, spaces, and case."""
|
| 222 |
def _flatten(obj):
|
| 223 |
fields = []
|
| 224 |
if isinstance(obj, dict):
|
|
|
|
| 227 |
elif isinstance(obj, list):
|
| 228 |
for item in obj:
|
| 229 |
fields.extend(_flatten(item))
|
| 230 |
+
elif obj is not None:
|
| 231 |
+
fields.append(str(obj))
|
| 232 |
return fields
|
| 233 |
|
| 234 |
+
# Clean up PO number
|
| 235 |
+
po_str = str(po_number).strip().replace(" ", "").replace(".0", "")
|
| 236 |
+
try:
|
| 237 |
+
po_int = str(int(float(po_number))) # also get int version
|
| 238 |
+
except:
|
| 239 |
+
po_int = po_str
|
| 240 |
+
|
| 241 |
+
all_strs = [str(s).strip().replace(" ", "").replace(".0", "") for s in _flatten(invoice_json)]
|
| 242 |
+
|
| 243 |
+
# Check for exact match, or substring match, with all variants
|
| 244 |
+
for s in all_strs:
|
| 245 |
+
if not s:
|
| 246 |
+
continue
|
| 247 |
+
if po_str and (po_str in s or s in po_str):
|
| 248 |
+
return True
|
| 249 |
+
if po_int and (po_int in s or s in po_int):
|
| 250 |
+
return True
|
| 251 |
+
return False
|
| 252 |
+
|
| 253 |
|
| 254 |
def find_best_po_match(inv, po_df):
|
| 255 |
inv_hdr = inv["invoice_header"]
|
|
|
|
| 564 |
|
| 565 |
if extracted_info is not None and po_df is not None:
|
| 566 |
st.markdown("---")
|
| 567 |
+
st.subheader("EZOFIS AP AGENT Decision")
|
| 568 |
if st.button("Make a decision (EZOFIS AP AGENT)"):
|
| 569 |
tools = [
|
| 570 |
Tool(
|