Spaces:
Sleeping
Sleeping
File size: 718 Bytes
d75dae7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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
|