Download agentcourse_unit4/tools/image_text_extractor.py from mrpe24/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 718 Bytes
-
https://huggingface.co/spaces/mrpe24/Final_Assignment_Template/resolve/main/agentcourse_unit4/tools/image_text_extractor.py
- Command line
-
hf download hf://spaces/mrpe24/Final_Assignment_Template/agentcourse_unit4/tools/image_text_extractor.py
-
curl -L -o image_text_extractor.py https://huggingface.co/spaces/mrpe24/Final_Assignment_Template/resolve/main/agentcourse_unit4/tools/image_text_extractor.py
718 Bytes
| from smolagents import Tool | |
| import easyocr | |
| class ImageTextExtractorTool(Tool): | |
| name = "image_text_extractor" | |
| description = """ | |
| Multilingual OCR tool to extract key information or presented text from any image. | |
| Supported image extensions: .png, .jpg, .jpeg, .bmp, .svg. | |
| """ | |
| inputs = { | |
| "image_path": { | |
| "type": "string", | |
| "description": "The path to the image file", | |
| } | |
| } | |
| output_type = "array" | |
| def __init__(self): | |
| super().__init__() | |
| self.reader = easyocr.Reader(['ch_sim', 'en']) | |
| def forward(self, image_path: str) -> list[str]: | |
| result = self.reader.readtext(image_path, detail=False) | |
| return result | |