gopichandra commited on
Commit
951eafd
·
verified ·
1 Parent(s): 90a606e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -46,6 +46,12 @@ def extract_text(image):
46
  extracted_text = [line[1][0] for line in result[0]]
47
  return "\n".join(extracted_text)
48
 
 
 
 
 
 
 
49
  # Function to match product name using fuzzy matching
50
  def match_product_name(extracted_text):
51
  best_match, best_score = None, 0
@@ -66,10 +72,6 @@ def extract_attributes(extracted_text):
66
  if match:
67
  attributes[readable_attr] = match.group(1).strip()
68
 
69
- # Use extracted "Product name" if present; otherwise, apply fuzzy matching
70
- if "Product name" not in attributes or not attributes["Product name"]:
71
- attributes["Product name"] = match_product_name(extracted_text)
72
-
73
  # Extract Quantity from text (e.g., "Quantity: 10")
74
  quantity_match = re.search(r"\bQuantity[:\-]?\s*(\d+)", extracted_text, re.IGNORECASE)
75
  if quantity_match:
@@ -101,7 +103,7 @@ def interact_with_salesforce(mode, entry_type, quantity, extracted_text):
101
  return "❌ Invalid mode or entry type."
102
 
103
  attributes = extract_attributes(extracted_text)
104
- product_name = attributes.get("Product name")
105
 
106
  if not product_name:
107
  return "❌ No matching product found."
 
46
  extracted_text = [line[1][0] for line in result[0]]
47
  return "\n".join(extracted_text)
48
 
49
+ # Function to extract product name from attributes or use fuzzy matching
50
+ def get_product_name(attributes, extracted_text):
51
+ if "Product name" in attributes and attributes["Product name"]:
52
+ return attributes["Product name"]
53
+ return match_product_name(extracted_text)
54
+
55
  # Function to match product name using fuzzy matching
56
  def match_product_name(extracted_text):
57
  best_match, best_score = None, 0
 
72
  if match:
73
  attributes[readable_attr] = match.group(1).strip()
74
 
 
 
 
 
75
  # Extract Quantity from text (e.g., "Quantity: 10")
76
  quantity_match = re.search(r"\bQuantity[:\-]?\s*(\d+)", extracted_text, re.IGNORECASE)
77
  if quantity_match:
 
103
  return "❌ Invalid mode or entry type."
104
 
105
  attributes = extract_attributes(extracted_text)
106
+ product_name = get_product_name(attributes, extracted_text)
107
 
108
  if not product_name:
109
  return "❌ No matching product found."