Spaces:
Build error
Build error
| import pytesseract | |
| from PIL import Image | |
| from langchain_core.tools import tool | |
| def extract_text_from_image(image_path: str) -> str: | |
| """ | |
| Extract text from an image in using the pytesseract library. | |
| Args: | |
| image_path (str): the path to the image file. | |
| """ | |
| try: | |
| # Open the image | |
| image = Image.open(image_path) | |
| # Extract text from the image | |
| text = pytesseract.image_to_string(image) | |
| return f"Extracted text from image:\n\n{text}" | |
| except Exception as e: | |
| return f"Error extracting text from image: {str(e)}" | |