Created
January 11, 2021 17:51
-
-
Save Sande3p/a9d85cff18a7b8f51290bb641f656f5f to your computer and use it in GitHub Desktop.
demo_textract_functioin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import boto3 | |
import base64 | |
def lambda_handler(event, context): | |
eventBody = json.loads(json.dumps(event))['body'] | |
imageBase64 = json.loads(eventBody)['Image'] | |
# Amazon Textract client | |
textract = boto3.client('textract') | |
# Call Amazon Textracttt | |
response = textract.detect_document_text( | |
Document={ | |
'Bytes': base64.b64decode(imageBase64) | |
}) | |
detectedText = '' | |
# Print detected text | |
for item in response['Blocks']: | |
if item['BlockType'] == 'LINE': | |
detectedText += item['Text'] + ', ' | |
return { | |
'statusCode': 200, | |
'body': json.dumps(response) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment