Spaces:
Build error
Build error
File size: 684 Bytes
9d7955b 6a65c1f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
from mmocr.utils.ocr import MMOCR
# Load MMOCR model
mmocr = MMOCR(det='DB_r18', recog='CRNN', det_config=None, recog_config=None)
def extract_weight_from_image(image):
result = mmocr.readtext(image, output=None)
texts = [item['text'] for item in result]
debug_text = "\n".join(texts)
# Find the first valid float that could represent a weight
for text in texts:
if any(char.isdigit() for char in text):
cleaned = text.replace('kg', '').replace('KG', '').strip()
try:
weight = float(cleaned)
return str(weight), debug_text
except:
continue
return None, debug_text
|