I am trying to run the quickstart code snippet from Google Cloud tutorials and somehow the line
from google.cloud import documentai_v1 as documentai
I get this error:
Cannot find reference 'documentai_v1' in 'imported module google.cloud'
The only module which is accessible for import is Storage. Same issue with Pub/Sub, BigQuery, etc.
The Google imports in requirements.txt
are:
google-api-core==2.10.2
google-cloud-core==2.3.2
google-auth==2.12.0
google-cloud-documentai==2.0.0
googleapis-common-protos==1.56.4
from google.api_core.client_options import ClientOptions
from google.cloud import documentai_v1 as documentai
from tabulate import tabulate
def quickstart(project_id: str, location: str, processor_id: str, file_path: str, mime_type: str):
# You must set the api_endpoint if you use a location other than 'us', e.g.:
opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com")
client = documentai.DocumentProcessorServiceClient(client_options=opts)
# The full resource name of the processor, e.g.:
# projects/project_id/locations/location/processor/processor_id
name = client.processor_path(project_id, location, processor_id)
# Read the file into memory
with open(file_path, "rb") as image:
image_content = image.read()
# Load Binary Data into Document AI RawDocument Object
raw_document = documentai.RawDocument(content=image_content, mime_type=mime_type)
# Configure the process request
request = documentai.ProcessRequest(name=name, raw_document=raw_document)
result = client.process_document(request=request)
# For a full list of Document object attributes, please reference this page:
# https://cloud.google.com/python/docs/reference/documentai/latest/google.cloud.documentai_v1.types.Document
document = result.document
# Read the text recognition output from the processor
print("The document contains the following text:")
print(document.text)