Skip to content

Instantly share code, notes, and snippets.

@Sande3p
Created January 11, 2021 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sande3p/a9d85cff18a7b8f51290bb641f656f5f to your computer and use it in GitHub Desktop.
Save Sande3p/a9d85cff18a7b8f51290bb641f656f5f to your computer and use it in GitHub Desktop.
demo_textract_functioin
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