1313# limitations under the License.
1414
1515from google .cloud .documentai_v1 .types .document import Document
16- from google .cloud .documentai_v1 .types .processor import Processor
1716
1817
1918def quickstart (
2019 project_id : str ,
20+ processor_id : str ,
2121 location : str ,
2222 file_path : str ,
23- processor_display_name : str ,
24- ) -> tuple [Processor , Document ]:
23+ ) -> Document :
2524 # [START documentai_quickstart]
2625 from google .api_core .client_options import ClientOptions
27- from google .cloud import documentai_v1 # type: ignore
26+ from google .cloud import documentai_v1
27+
28+ # TODO(developer): Create a processor of type "OCR_PROCESSOR".
2829
2930 # TODO(developer): Update and uncomment these variables before running the sample.
3031 # project_id = "MY_PROJECT_ID"
3132
33+ # Processor ID as hexadecimal characters.
34+ # Not to be confused with the Processor Display Name.
35+ # processor_id = "MY_PROCESSOR_ID"
36+
3237 # Processor location. For example: "us" or "eu".
3338 # location = "MY_PROCESSOR_LOCATION"
3439
3540 # Path for file to process.
3641 # file_path = "/path/to/local/pdf"
3742
38- # Processor display name must be unique per project.
39- # processor_display_name = "MY_PROCESSOR_DISPLAY_NAME"
40-
4143 # Set `api_endpoint` if you use a location other than "us".
4244 opts = ClientOptions (api_endpoint = f"{ location } -documentai.googleapis.com" )
4345
4446 # Initialize Document AI client.
4547 client = documentai_v1 .DocumentProcessorServiceClient (client_options = opts )
4648
47- # Get the full resource name of the location.
48- # For example: `projects/{project_id}/locations/{location}`
49- parent = client .common_location_path (project_id , location )
50-
51- # Create a Processor.
52- # For available types, refer to https://cloud.google.com/document-ai/docs/create-processor
53- processor = client .create_processor (
54- parent = parent ,
55- processor = documentai_v1 .Processor (
56- type_ = "OCR_PROCESSOR" ,
57- display_name = processor_display_name ,
58- ),
59- )
49+ # Get the Fully-qualified Processor path.
50+ full_processor_name = client .processor_path (project_id , location , processor_id )
6051
61- # Print the processor information.
52+ # Get a Processor reference.
53+ request = documentai_v1 .GetProcessorRequest (name = full_processor_name )
54+ processor = client .get_processor (request = request )
55+
56+ # `processor.name` is the full resource name of the processor.
57+ # For example: `projects/{project_id}/locations/{location}/processors/{processor_id}`
6258 print (f"Processor Name: { processor .name } " )
6359
6460 # Read the file into memory.
@@ -72,11 +68,8 @@ def quickstart(
7268 mime_type = "application/pdf" ,
7369 )
7470
75- # Configure the process request.
76- # `processor.name` is the full resource name of the processor,
77- # For example: `projects/{project_id}/locations/{location}/processors/{processor_id}`
71+ # Send a request and get the processed document.
7872 request = documentai_v1 .ProcessRequest (name = processor .name , raw_document = raw_document )
79-
8073 result = client .process_document (request = request )
8174 document = result .document
8275
@@ -87,4 +80,4 @@ def quickstart(
8780 print (document .text )
8881 # [END documentai_quickstart]
8982
90- return processor , document
83+ return document
0 commit comments