GoogleCloudPlatform / GoogleCloudPlatform/document-ai-samples

[docai-ocr-python]

Open
#758 5 comments 0 reactions 1 assignee Claimed by @crypto-frog View on GitHub
Dominant language
Jupyter Notebook
Stars
332
Forks
116
PR merge metrics
No merged PRs in 30d

Description

I have followed the tutorial exactly, and i keep getting this error. my key.json is located in home/jonathan_ruben_fernandes/key.json

Here is my error message. Nothing on stack overflow and openai cannot help me figure out the error:

```
/usr/bin/python /home/jonathan_ruben_fernandes/online_processing.py
jonathan_ruben_fernandes@cloudshell:~$ /usr/bin/python /home/jonathan_ruben_fernandes/online_processing.py
Traceback (most recent call last):
File "/home/jonathan_ruben_fernandes/online_processing.py", line 2, in
from google.cloud import documentai
ImportError: cannot import name 'documentai' from 'google.cloud' (unknown location)
jonathan_ruben_fernandes@cloudshell:~$
```

-----------------------------------------------------

```
from google.api_core.client_options import ClientOptions
from google.cloud import documentai

PROJECT_ID = "project-doc-ocr-416018"
LOCATION = "us" # Format is 'us' or 'eu'
PROCESSOR_ID = "51d53e5ecbc3418d" # Create processor in Cloud Console

# The local file in your current working directory
FILE_PATH = "Winnie_the_Pooh_3_Pages.pdf"
# Refer to https://cloud.google.com/document-ai/docs/file-types
# for supported file types
MIME_TYPE = "application/pdf"

# Instantiates a client
docai_client = documentai.DocumentProcessorServiceClient(
client_options=ClientOptions(api_endpoint=f"{LOCATION}-documentai.googleapis.com")
)

# 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
RESOURCE_NAME = docai_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=RESOURCE_NAME, raw_document=raw_document)

# Use the Document AI client to process the sample form
result = docai_client.process_document(request=request)

document_object = result.document
print("Document processing complete.")
print(f"Text: {document_object.text}")
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.