I'm a beginner playing around with the Doc AI Cloud library and I was trying the run the program below.
However, even after diligently following the instructions I get no output, no error report, or anything, just another line to try again like I never did anything.
this is my version of the code
from google.api_core.client_options import ClientOptions
from google.cloud import documentai # type: ignore
# TODO(developer): Uncomment these variables before running the sample.
project_id = "document-ai-testing-2"
location = "us"
file_path = "C:/Users/Tyron/OneDrive/Desktop/Software/Document AI/Test Documents/Winnie_the_Pooh_3_Pages.pdf"
processor_display_name = "jumpstart_ocr_processor_version_2"
def quickstart(
project_id: str,
location: str,
file_path: str,
processor_display_name: str = "My Processor",
):
# You must set the `api_endpoint`if you use a location other than "us".
opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com")
client = documentai.DocumentProcessorServiceClient(client_options=opts)
# The full resource name of the location, e.g.:
# `projects/{project_id}/locations/{location}`
parent = client.common_location_path(project_id, location)
# Create a Processor
processor = client.create_processor(
parent=parent,
processor=documentai.Processor(
type_="OCR_PROCESSOR", # Refer to https://cloud.google.com/document-ai/docs/create-processor for how to get available processor types
display_name=processor_display_name,
),
)
# Print the processor information
print(f"Processor Name: {processor.name}")
# Read the file into memory
with open(file_path, "rb") as image:
image_content = image.read()
# Load binary data
raw_document = documentai.RawDocument(
content=image_content,
mime_type="application/pdf", # Refer to https://cloud.google.com/document-ai/docs/file-types for supported file types
)
# Configure the process request
# `processor.name` is the full resource name of the processor, e.g.:
# `projects/{project_id}/locations/{location}/processors/{processor_id}`
request = documentai.ProcessRequest(name=processor.name, raw_document=raw_document)
result = client.process_document(request=request)
# For a full list of `Document` object attributes, reference this page:
# https://cloud.google.com/document-ai/docs/reference/rest/v1/Document
document = result.document
# Read the text recognition output from the processor
print("The document contains the following text:")
print(document.text)
Please Help
- I created a virtual environment using vscode.
- I installed gcloud in the environment
- I did the authentication
- Navigated to the separate directory for the python script: https://cloud.google.com/document-ai/docs/libraries#client-libraries-install-python
- used:
python "The File.py"
- python icon briefly flashes when I press enter
- no output
note: At first I was struggling to create the venv then I had to bypass the execution policy.