from langchain_core.tools import tool import easyocr import logging import os logger = logging.getLogger(__name__) reader = easyocr.Reader(['en']) @tool async def image_parser_tool(file_path: str, task: str = "describe", match_query: str = "") -> str: """Parse text from an image""" try: if not os.path.exists(file_path): logger.warning(f"Image not found: {file_path}") return "Image not found" results = reader.readtext(file_path) text = " ".join(result[1] for result in results) if task == "match" and match_query: return str(match_query.lower() in text.lower()) return text except Exception as e: logger.error(f"Error parsing image {file_path}: {e}") return f"Error: {str(e)}"