in web-app-pix2info-python/src/backend/docai.py [0:0]
def setup_processors(project_id: str):
"""Check if expected processors exist and create them otherwise.
- Display names are arbitrary (index-prefixed here for demo purposes)
- Rights required for the service account: "roles/documentai.editor"
"""
locations = DEMO_PROCESSING_LOCATIONS
proc_types = DEMO_PROCESSOR_TYPES
for location in locations:
client, parent = get_client_and_parent(project_id, location)
existing_names = [
proc.display_name
for proc in get_processors_of_types(client, parent, proc_types)
]
for proc_number, proc_type in enumerate(proc_types, start=1):
display_name = processor_display_name(proc_number, proc_type)
if display_name in existing_names:
logging.info("OK existing: %s / %s", location, display_name)
continue
try:
logging.info(".. Creating: %s / %s", location, display_name)
processor = Processor(display_name=display_name, type_=proc_type)
client.create_processor(parent=parent, processor=processor)
except Exception as err:
logging.exception(err)