将A2I(Amazon Augmented AI)与异步textract调用集成的方法如下所示:
代码示例:
import boto3
import botocore
import json
s3 = boto3.resource('s3')
textract = boto3.client('textract')
a2i = boto3.client('sagemaker-a2i-runtime')
def start_async_textract_job(bucketName, objectName):
response = textract.start_document_analysis(
DocumentLocation={
'S3Object': {
'Bucket': bucketName,
'Name': objectName
}
},
FeatureTypes=['FORMS']
)
async_client = AsyncAWSClient()
async_client.start_document_analysis(
document_location={
'S3Object': {
'Bucket': bucketName,
'Name': objectName
},
},
feature_types=['FORMS'],
client_request_token=response['JobId']
)
return response['JobId']
class AsyncAWSClient(textract.AsyncAnalysisClient):
def start_document_analysis(self, document_location, feature_types, client_request_token=None):
response = super(AsyncAWSClient, self).start_document_analysis(
DocumentLocation=document_location,
FeatureTypes=feature_types,
ClientRequestToken=client_request_token
)
human_loop_name = 'textract-job-' + response['JobId']
flow_definition_arn = ''
human_loop_input_content = {