Imperial-EE-Microsoft / co_op_translator

Easily automate multilingual translations for your projects with co_op_translator, powered by advanced LLM technology.
https://techcommunity.microsoft.com/t5/educator-developer-blog/localizing-github-repositories-with-llms/ba-p/4216434
MIT License
1 stars 2 forks source link

IndexError when translating some images in project using `co_op_translator` #26

Closed skytin1004 closed 2 months ago

skytin1004 commented 2 months ago

The following error occurs when attempting to translate an image (petsmusic.png) in the project using co_op_translator:

ERROR:co_op_translator.translators.project_translator:Failed to translate image C:\Users\sms79\dev\Phi-3CookBook\md\07.Labs\Csharp\src\LabsPhi304\imgs\petsmusic.png: list index out of range
Traceback (most recent call last):
  File "C:\Users\sms79\dev\Phi-3CookBook\.venv\lib\site-packages\co_op_translator\translators\project_translator.py", line 52, in translate_image
    translated_image_path = self.image_translator.translate_image(image_path, language_code, self.image_dir)
  File "C:\Users\sms79\dev\Phi-3CookBook\.venv\lib\site-packages\co_op_translator\translators\image_translator.py", line 181, in translate_image
    line_bounding_boxes = self.extract_line_bounding_boxes(image_path)
  File "C:\Users\sms79\dev\Phi-3CookBook\.venv\lib\site-packages\co_op_translator\translators\image_translator.py", line 72, in extract_line_bounding_boxes
    for line in result.read.blocks[0].lines:
IndexError: list index out of range
ERROR:co_op_translator.translators.project_translator:Failed to translate image C:\Users\sms79\dev\Phi-3CookBook\md\07.Labs\Csharp\src\LabsPhi304\imgs\ultrarunningmug.png: list index out of range
Traceback (most recent call last):
  File "C:\Users\sms79\dev\Phi-3CookBook\.venv\lib\site-packages\co_op_translator\translators\project_translator.py", line 52, in translate_image
    translated_image_path = self.image_translator.translate_image(image_path, language_code, self.image_dir)
  File "C:\Users\sms79\dev\Phi-3CookBook\.venv\lib\site-packages\co_op_translator\translators\image_translator.py", line 181, in translate_image
    line_bounding_boxes = self.extract_line_bounding_boxes(image_path)
  File "C:\Users\sms79\dev\Phi-3CookBook\.venv\lib\site-packages\co_op_translator\translators\image_translator.py", line 72, in extract_line_bounding_boxes
    for line in result.read.blocks[0].lines:
IndexError: list index out of range

Cause:

Proposed Solution:

  1. Check for empty results: Before accessing blocks[0], ensure that result.read.blocks contains at least one block. This will prevent the IndexError from occurring when the list is empty.

    Example fix:

    if result.read.blocks and result.read.blocks[0].lines:
       for line in result.read.blocks[0].lines:
           # Process the lines
    else:
       # Handle the case where no blocks or lines are found
  2. Image Link Update Handling:

    • Implement logic to handle cases where image link updates fail during translation. If the image link is not updated correctly, ensure there is a fallback mechanism to handle these cases gracefully and retry the update process.
    • Add validation to check if the image link has been successfully updated, and if not, attempt to fix or retry the process.

    This will ensure that the translation process doesn't fail entirely due to an image translation issue, and the markdown file processing can continue safely even if an image link fails.