Manuelle Überprüfung eines Dokuments anfordern

Nachdem Sie Ihr Google Cloud -Konto eingerichtet, einen Prozessor erstellt und die manuelle Überprüfung aktiviert haben, können Sie eine Überprüfungsanfrage an Ihren Prozessor senden. Auf dieser Seite erfahren Sie, wie Sie die manuelle Überprüfung eines Dokuments ad hoc beantragen.

Manuelle Überprüfung beantragen

Web-UI

  1. Öffnen Sie in der Google Cloud Console die Seite „Human in the Loop“.

    Zum Human-in-the-Loop-Dashboard

  2. Klicken Sie auf den Prozessor, den Sie für die manuelle Überprüfung verwenden möchten.

  3. Wählen Sie Dokument hochladen aus und laden Sie eine lokale Datei hoch, die zur Überprüfung gesendet werden soll. Es kann 1 bis 2 Minuten dauern, bis das Dokument in der Warteschlange für die Überprüfung angezeigt wird.

REST

Ersetzen Sie diese Werte in den folgenden Anfragedaten:

  • PROJECT_ID: Ihre Google Cloud Projekt-ID.
  • LOCATION: Standort des Prozessors, z. B.:
    • us – USA
    • eu – Europäische Union
  • PROCESSOR_ID: Die ID des benutzerdefinierten Prozessors.
  • ENABLE_SCHEMA_VALIDATION: Ob die Schemavalidierung für die Ad-hoc-Überprüfungsanfrage durchgeführt werden soll.
    • true: Aktiviert die Schemaüberprüfung für die Ad-hoc-Überprüfungsanfrage.
    • false – Deaktiviert die Schemaüberprüfung für den Ad-hoc-Überprüfungsantrag.
  • PRIORITY: Die Priorität der Aufgabe für die manuelle Überprüfung.
    • DEFAULT: Die Standardprioritätsstufe.
    • URGENT – höchste Prioritätsstufe Der Labelmanager sollte der Warteschlange für dringende Aufgaben eine Labelressource zuweisen, um diese Prioritätsstufe zu berücksichtigen.
  • DOCUMENT: Ein Document-Objekt, das bereits vom für die Überprüfung konfigurierten Prozessor verarbeitet wurde.

HTTP-Methode und URL:

POST https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/humanReviewConfig:reviewDocument

JSON-Text der Anfrage:

{
  "enableSchemaValidation": ENABLE_SCHEMA_VALIDATION,
  "priority": "PRIORITY",
  "inlineDocument": "DOCUMENT"
}

Wenn Sie die Anfrage senden möchten, wählen Sie eine der folgenden Optionen aus:

curl

Speichern Sie den Anfragetext in einer Datei mit dem Namen request.json und führen Sie den folgenden Befehl aus:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/humanReviewConfig:reviewDocument"

PowerShell

Speichern Sie den Anfragetext in einer Datei mit dem Namen request.json und führen Sie den folgenden Befehl aus:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-documentai.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/humanReviewConfig:reviewDocument" | Select-Object -Expand Content

Wenn der Vorgang erfolgreich abgeschlossen wurde, enthält die Antwort eine Instanz von Operation. Weitere Informationen zu lang andauernden Vorgängen finden Sie in der Dokumentation.

{
  "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.documentai.v1.ReviewDocumentOperationMetadata",
    "commonMetadata": {
      "state": "RUNNING",
      "createTime": "TIMESTAMP",
      "updateTime": "TIMESTAMP",
      "resource": "projects/PROJECT_ID/locations/LOCATION/processors/PROCESSOR_ID/humanReviewConfig"
    }
  }
}

Python

Weitere Informationen finden Sie in der Referenzdokumentation zur Document AI Python API.

Richten Sie zur Authentifizierung bei Document AI Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.


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 = 'YOUR_PROJECT_ID'
# location = 'YOUR_PROCESSOR_LOCATION' # Format is 'us' or 'eu'
# processor_id = 'YOUR_PROCESSOR_ID' # Create processor before running sample
# file_path = '/path/to/local/pdf'
# mime_type = 'application/pdf'  # https://cloud.google.com/document-ai/docs/file-types


def review_document_sample(
    project_id: str, location: str, processor_id: str, file_path: str, mime_type: str
) -> None:
    # You must set the api_endpoint if you use a location other than 'us'.
    opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com")

    # Create a client
    client = documentai.DocumentProcessorServiceClient(client_options=opts)

    # Make Processing Request
    inline_document = process_document(
        project_id, location, processor_id, file_path, mime_type
    )

    # Get the full resource name of the human review config, e.g.:
    # projects/project_id/locations/location/processor/processor_id/humanReviewConfig
    human_review_config = client.human_review_config_path(
        project_id, location, processor_id
    )

    # Options are DEFAULT, URGENT
    priority = documentai.ReviewDocumentRequest.Priority.DEFAULT

    # Configure the human review request
    request = documentai.ReviewDocumentRequest(
        inline_document=inline_document,
        human_review_config=human_review_config,
        enable_schema_validation=False,
        priority=priority,
    )

    # Make a request for human review of the processed document
    operation = client.review_document(request=request)

    # Print operation name, can be used to check status of the request
    print(operation.operation.name)


def process_document(
    project_id: str, location: str, processor_id: str, file_path: str, mime_type: str
) -> documentai.Document:
    # 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 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)

    return result.document