Skip to content

Conversation

alcholiclg
Copy link
Collaborator

Change Summary

  1. Add examples in unittest.
  2. Support capturing current base url in docling htmlbackend.
  3. Support fecthing image using base url.
  4. Support normalizing base url.
  5. Rename the validate_url function to resolve_url.
  6. Slightly repackage image extraction logic.

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Run pre-commit install and pre-commit run --all-files before git commit, and passed lint check.
  • Some cases need DASHSCOPE_TOKEN_API to pass the Unit Tests, I have at least pass the Unit tests on local
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

alcholiclg added 2 commits July 22, 2025 11:41
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @alcholiclg, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the image extraction capabilities within the docling HTML backend. The primary goal is to improve the handling of relative image URLs by accurately capturing and utilizing the base URL of the document being processed, and by centralizing and refining the image fetching and URL resolution logic.

Highlights

  • Improved Base URL Handling: The system now captures the current_url of a document during conversion and makes it available to the HTML backend, allowing for more accurate resolution of relative image paths. This is achieved by patching DocumentConverter._convert to inject the current_url into the document's backend attributes and updating DocLoader.load to set this URL for each document.
  • Refactored URL Resolution Logic: The validate_url utility function has been renamed to resolve_url and significantly enhanced. It now accepts an explicit base_url parameter and includes a new normalized_base helper to correctly append a trailing slash to base URLs that represent directories, ensuring more robust URL concatenation.
  • Centralized Image Extraction: A new extract_image utility function has been introduced. This function consolidates the logic for fetching images from both data URIs and standard URLs, leveraging the updated resolve_url for non-absolute paths. The html_handle_figure and html_handle_image methods in the docling backend now utilize this centralized function.
  • Expanded Unit Tests: The unit tests for image extraction (tests/doc/test_img.py) have been updated to include more comprehensive scenarios. Test variables for URLs are now lists, allowing for multiple URLs to be tested per category, and extracted images are saved into task-specific directories for better organization and verification.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The code changes introduce the ability to load multiple signed images to a registry using a bulk load feature. The review focuses on a potential UnboundLocalError, a hardcoded special case, and the handling of lists of URLs in the tests.

Comment on lines +406 to +407
need_append_slash = ('.' not in parsed.path.split('/')[-1]
or 'arxiv.org' in parsed.netloc)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic includes a hardcoded special case for arxiv.org. This makes the function less generic and might require adding more special cases in the future as you encounter other sites with similar URL structures. Consider adding a code comment to explain why this special case is necessary. If a more general solution is feasible, that would be even better for long-term maintainability.

os.path.join(save_dir, 'picture_' + str(idx) + '.png'))
assert len(
doc_results[0].pictures) > 0, 'No pictures found in the document.'
doc_results = doc_loader.load(urls_or_files=self.absolute_path_img_url)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The load method is called with self.absolute_path_img_url, which is a list. However, the loop iterates through doc_results without using the task_id to access the corresponding URL from the list. This could lead to incorrect assertions or errors if the number of documents loaded doesn't match the number of URLs.

os.path.join(save_dir, 'picture_' + str(idx) + '.png'))
assert len(
doc_results[0].pictures) > 0, 'No pictures found in the document.'
doc_results = doc_loader.load(urls_or_files=self.relative_path_img_url)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The load method is called with self.relative_path_img_url, which is a list. However, the loop iterates through doc_results without using the task_id to access the corresponding URL from the list. This could lead to incorrect assertions or errors if the number of documents loaded doesn't match the number of URLs.

os.path.join(save_dir, 'picture_' + str(idx) + '.png'))
assert len(
doc_results[0].pictures) > 0, 'No pictures found in the document.'
doc_results = doc_loader.load(urls_or_files=self.figure_tag_img_url)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The load method is called with self.figure_tag_img_url, which is a list. However, the loop iterates through doc_results without using the task_id to access the corresponding URL from the list. This could lead to incorrect assertions or errors if the number of documents loaded doesn't match the number of URLs.

os.path.join(save_dir, 'picture_' + str(idx) + '.png'))
assert len(
doc_results[0].pictures) > 0, 'No pictures found in the document.'
doc_results = doc_loader.load(urls_or_files=self.data_uri_img_url)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The load method is called with self.data_uri_img_url, which is a list. However, the loop iterates through doc_results without using the task_id to access the corresponding URL from the list. This could lead to incorrect assertions or errors if the number of documents loaded doesn't match the number of URLs.

initialize need_append_slash to False

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@alcholiclg alcholiclg changed the title feature: support more general image extraction [WIP]feature: support more general image extraction Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant