Skip to content

Commit

Permalink
samples: updates Document AI samples to v1 version of service (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
telpirion authored Apr 12, 2021
1 parent 6eef6ae commit c152dc7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions document_ai/snippets/batch_process_documents_sample_v1beta3.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# [START documentai_batch_process_document]
import re

from google.cloud import documentai_v1beta3 as documentai
from google.cloud import documentai_v1 as documentai
from google.cloud import storage

# TODO(developer): Uncomment these variables before running the sample.
Expand Down Expand Up @@ -47,23 +47,25 @@ def batch_process_documents(

destination_uri = f"{gcs_output_uri}/{gcs_output_uri_prefix}/"

gcs_documents = documentai.GcsDocuments(
documents=[{"gcs_uri": gcs_input_uri, "mime_type": "application/pdf"}]
)

# 'mime_type' can be 'application/pdf', 'image/tiff',
# and 'image/gif', or 'application/json'
input_config = documentai.types.document_processor_service.BatchProcessRequest.BatchInputConfig(
gcs_source=gcs_input_uri, mime_type="application/pdf"
)
input_config = documentai.BatchDocumentsInputConfig(gcs_documents=gcs_documents)

# Where to write results
output_config = documentai.types.document_processor_service.BatchProcessRequest.BatchOutputConfig(
gcs_destination=destination_uri
output_config = documentai.DocumentOutputConfig(
gcs_output_config={"gcs_uri": destination_uri}
)

# Location can be 'us' or 'eu'
name = f"projects/{project_id}/locations/{location}/processors/{processor_id}"
request = documentai.types.document_processor_service.BatchProcessRequest(
name=name,
input_configs=[input_config],
output_config=output_config,
input_documents=input_config,
document_output_config=output_config,
)

operation = client.batch_process_documents(request)
Expand Down

0 comments on commit c152dc7

Please sign in to comment.