Skip to content

Adding support for image and table annotation for DocAI #13329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
9 changes: 7 additions & 2 deletions documentai/snippets/handle_response_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
# processor_version = "rc" # Refer to https://cloud.google.com/document-ai/docs/manage-processor-versions for more information
# file_path = "/path/to/local/pdf"
# mime_type = "application/pdf" # Refer to https://cloud.google.com/document-ai/docs/file-types for supported file types

# enable_image_annotation = False # Set to TRUE to enable processing. Refer to https://cloud.google.com/document-ai/docs/layout-parse-chunk#layout_parser_features
# enable_table_annotation = False # Set to TRUE to enable processing. Refer to https://cloud.google.com/document-ai/docs/layout-parse-chunk#layout_parser_features

# [END documentai_process_ocr_document]
# [END documentai_process_form_document]
Expand Down Expand Up @@ -463,13 +464,17 @@ def process_document_layout_sample(
processor_version: str,
file_path: str,
mime_type: str,
enable_image_annotation: bool = False, # Enable image annotation
enable_table_annotation: bool = False, # Enable table annotation
) -> documentai.Document:
process_options = documentai.ProcessOptions(
layout_config=documentai.ProcessOptions.LayoutConfig(
chunking_config=documentai.ProcessOptions.LayoutConfig.ChunkingConfig(
chunk_size=1000,
include_ancestor_headings=True,
)
),
enable_image_annotation=enable_image_annotation,
enable_table_annotation=enable_table_annotation,
)
)

Expand Down
2 changes: 2 additions & 0 deletions documentai/snippets/handle_response_sample_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ def test_process_document_layout():
processor_version="pretrained",
file_path="resources/superconductivity.pdf",
mime_type="application/pdf",
enable_image_annotation = True,
enable_table_annotation = True,
)

assert document
Expand Down