Spaces:
Sleeping
Sleeping
Download utils/ocr_utils.py from vishal1232006/MemeScope: direct link, hf CLI and curl.
- Browser
- Download file 405 Bytes
-
https://huggingface.co/spaces/vishal1232006/MemeScope/resolve/main/utils/ocr_utils.py
- Command line
-
hf download hf://spaces/vishal1232006/MemeScope/utils/ocr_utils.py
-
curl -L -o ocr_utils.py https://huggingface.co/spaces/vishal1232006/MemeScope/resolve/main/utils/ocr_utils.py
405 Bytes
| import easyocr | |
| from PIL import Image | |
| import numpy as np | |
| # Initialize EasyOCR reader (English for now) | |
| reader = easyocr.Reader(['en']) | |
| def extract_text(image): | |
| """ | |
| Extract text from an image using EasyOCR. | |
| """ | |
| if isinstance(image, Image.Image): | |
| image = np.array(image) | |
| results = reader.readtext(image) | |
| text = " ".join([res[1] for res in results]) | |
| return text.strip() | |