Download handler.py from ojasm/image-recognition: direct link, hf CLI and curl.
- Browser
- Download file 453 Bytes
-
https://huggingface.co/ojasm/image-recognition/resolve/main/handler.py
- Command line
-
hf download hf://ojasm/image-recognition/handler.py
-
curl -L -o handler.py https://huggingface.co/ojasm/image-recognition/resolve/main/handler.py
453 Bytes
| from typing import Any | |
| import pytesseract | |
| import urllib.request | |
| from PIL import Image | |
| pytesseract.pytesseract.tesseract_cmd = r'E:\tesseract ocr\tesseract.exe' | |
| class EndpointHandler(): | |
| def __init__(self): | |
| pass | |
| def __call__(self, imageUrl: str) -> str: | |
| urllib.request.urlretrieve(imageUrl, "image.jpg") | |
| img = Image.open("image.jpg") | |
| text = pytesseract.image_to_string(img) | |
| print(text) | |
| return text |