googleapis / python-documentai-toolbox

Document AI Toolbox is an SDK for Python that provides utility functions for managing, manipulating, and extracting information from the document response. It creates a "wrapped" document object from JSON files in Cloud Storage, local JSON files, or output directly from the Document AI API.
https://cloud.google.com/document-ai/docs/toolbox
Apache License 2.0
33 stars 13 forks source link

High latency exporting to hocr #312

Closed smanero closed 1 month ago

smanero commented 1 month ago

Hello,

Coming from a Google Support Case 51622001: High latency exporting to hocr, which has derived to this issue.

Details

In the method from google.cloud.documentai_toolbox import document as documentai_document_wrapper

documentai_document_wrapper.Document.from_documentai_document(
        documentai_document=result.document
    ).export_hocr_str(title="title")

When transforming tables, the latency takes from 30 to 50 seconds, depending on the complexity of the page (high data in table formats).

Looking for any type of optimization.

Environment details

Steps to reproduce

  1. create venv with the provided requirements.txt
  2. execute python3 main-hocr.py test.pdf

Code example

 request = documentai.ProcessRequest(
      name=resource_name,
      raw_document=raw_document,
      process_options=process_options,
  )

  start = time.time()
  result = client.process_document(request=request)
  print(f"process_document {(time.time() - start)}")

  start = time.time()
  wrapped_document = documentai_document_wrapper.Document.from_documentai_document(
      documentai_document=result.document
  )
  print(f"wrapped_document {(time.time() - start)}")

  start = time.time()
  hocr_result = wrapped_document.export_hocr_str(title="hocr")
  print(f"export_hocr_str {(time.time() - start)}")

Stack trace

N/A, the execution is correct, but the latency takes 35 seconds long

Attached sources to reply the test: sources.zip

Thanks!