Last active
June 27, 2019 10:23
-
-
Save SumindaD/462f4d74721b2335866dc88d7df461af to your computer and use it in GitHub Desktop.
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 Textract | |
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'] + '\n' | |
return { | |
'statusCode': 200, | |
'body': json.dumps(detectedText) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment