Google Vision API (ImageAnnotatorClient). Potentially, the memory limit 256 Mibs was breached

  • Goal: Pass Image URL to google vision to perform OCR.

  • Steps: 1. Tried to resize images from 2048x2048 to 128x128.
    2. Tried streaming of images using io.BytesIO().
    But, Facing "The code terminated for an unknown reason. Potentially, the memory limit 256 Mibs was breached.".

  • Details: """

class GoogleService:
    def ocr_image(cls, image_url):
        Extract text from an image using Google Vision API
        # Request image content
        response = requests.get(image_url, stream=True)
        response.raise_for_status()  # Raise exception for bad status codes
        # Initialize Vision client
        vision_client = vision.ImageAnnotatorClient(credentials=credentials)
        # Process image content in chunks
        with io.BytesIO() as image_buffer:
            for chunk in response.iter_content(chunk_size=8192):
            image_content = image_buffer.getvalue()

        # Process image
        image = vision.Image(content=image_content)
        response = vision_client.text_detection(image=image)
        # Handle response
        if response.error.message:
            raise Exception(f"Google Vision API Error: {response.error.message}")
        return response.text_annotations[0].description

lang = GoogleService.ocr_image(image_url=image_urls[0])


What we are seeing is a message from the workflows executor timing out:

I have personally not used the Google Vision API before, it's likely than when we run this code, we're taking up a lot of memory. If you're on Retool Cloud, share the workflow id with us, and run it one more time, we can take a look at our logs and see if there is a more specific error on our end. If you are on self-hosted Retool, check the logs from Temporal.