Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -42,13 +42,13 @@ def process_image(image):
|
|
42 |
match = re.search(r'(\d{1,3}\.\d{1,3})\s*(kg|g)?', weight)
|
43 |
if match:
|
44 |
numeric_value = float(match.group(1))
|
45 |
-
unit = match.group(2) if match.group(2) else extract_unit_from_text(raw_text)
|
46 |
else:
|
47 |
cleaned = re.sub(r"[^\d]", "", weight)
|
48 |
decimal_fixed = restore_decimal(cleaned)
|
49 |
try:
|
50 |
numeric_value = float(decimal_fixed)
|
51 |
-
unit = extract_unit_from_text(raw_text)
|
52 |
except:
|
53 |
return f"❌ Could not extract number | OCR: {weight}", "", image, gr.update(visible=True)
|
54 |
|
|
|
42 |
match = re.search(r'(\d{1,3}\.\d{1,3})\s*(kg|g)?', weight)
|
43 |
if match:
|
44 |
numeric_value = float(match.group(1))
|
45 |
+
unit = match.group(2) if match.group(2) else extract_unit_from_text(raw_text) or "kg"
|
46 |
else:
|
47 |
cleaned = re.sub(r"[^\d]", "", weight)
|
48 |
decimal_fixed = restore_decimal(cleaned)
|
49 |
try:
|
50 |
numeric_value = float(decimal_fixed)
|
51 |
+
unit = extract_unit_from_text(raw_text) or "kg"
|
52 |
except:
|
53 |
return f"❌ Could not extract number | OCR: {weight}", "", image, gr.update(visible=True)
|
54 |
|