Spaces:
Sleeping
Sleeping
Download src/ocr_processor.py from Akash076/ocr_product_scanner: direct link, hf CLI and curl.
- Browser
- Download file 670 Bytes
-
https://huggingface.co/spaces/Akash076/ocr_product_scanner/resolve/main/src/ocr_processor.py
- Command line
-
hf download hf://spaces/Akash076/ocr_product_scanner/src/ocr_processor.py
-
curl -L -o ocr_processor.py https://huggingface.co/spaces/Akash076/ocr_product_scanner/resolve/main/src/ocr_processor.py
670 Bytes
| import easyocr | |
| from text_cleaner import clean_product_text, extract_keywords | |
| import re | |
| def extract_info(image_path): | |
| reader = easyocr.Reader(['en']) | |
| results = reader.readtext(image_path, detail=0) | |
| raw_text = " ".join(results) | |
| # Clean and extract the info we did | |
| clean_text = clean_product_text(raw_text) | |
| brand, product_name = extract_keywords(clean_text) | |
| # Barcode detection | |
| barcodes = re.findall(r'\b(\d{12,13})\b', raw_text) | |
| return { | |
| "raw_text": raw_text, | |
| "clean_text": clean_text, | |
| "brand": brand, | |
| "product_name": product_name, | |
| "barcodes": barcodes | |
| } |