0

I know there is a way by which we can call Document AI from python environment in local system. In that process one needs to upload the local file to GCS bucket so that Document AI can access the file from there. Is there any way by which we can give direct access of local files to Document AI (i.e., without uploading the file to GCS bucket) using python? [Note that it's a mandatory requirement for me to run python code in local system, not in GCP.]

1 Answers1

3

DocumentAI cannot "open" files by itself from your local filesystem.

If you don't want / cannot upload the documents to a bucket, you can send them in as part of the REST API. BUT in this case you cannot use BatchProcessing: I mean, you must process the files one by one and wait for a response.

The relevant REST API documentation is here: https://cloud.google.com/document-ai/docs/reference/rest/v1/projects.locations.processors/process

In the quickstart documentation for python you've got this sample code that reads a file and sends it inline as part of the request:

# The full resource name of the processor, e.g.:
# projects/project-id/locations/location/processor/processor-id
# You must create new processors in the Cloud Console first
name = f"projects/{project_id}/locations/{location}/processors/{processor_id}"

# Read the file into memory
with open(file_path, "rb") as image:
    image_content = image.read()

document = {"content": image_content, "mime_type": "application/pdf"}

# Configure the process request
request = {"name": name, "raw_document": document}

result = client.process_document(request=request)


Iñigo González
  • 3,735
  • 1
  • 11
  • 27