我知道有一种方法可以在本地系统中从python环境中调用文档AI。在该过程中,需要将本地文件上传到GCS存储桶,以便文档AI可以从那里访问该文件。有没有什么方法可以让我们使用python直接访问本地文件访问文档AI (即,不将文件上传到GCS bucket)?请注意,这是我必须在本地系统中运行python代码的强制要求,而不是在GCP中。
发布于 2021-07-21 19:03:34
DocumentAI不能自己从本地文件系统中“打开”文件。
如果您不想/不能将文档上传到存储桶,您可以将它们作为REST API的一部分发送。但在这种情况下,您不能使用BatchProcessing:我的意思是,您必须逐个处理文件并等待响应。
相关的REST API文档在这里:https://cloud.google.com/document-ai/docs/reference/rest/v1/projects.locations.processors/process
在quickstart documentation for python中,您已经获得了读取文件并将其作为请求的一部分内联发送的示例代码:
# 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
name = f"projects/{project_id}/locations/{location}/processors/{processor_id}"
# Read the file into memory
with open(file_path, "rb") as image:
image_content = image.read()
document = {"content": image_content, "mime_type": "application/pdf"}
# Configure the process request
request = {"name": name, "raw_document": document}
result = client.process_document(request=request)https://stackoverflow.com/questions/68464420
复制相似问题