in src/get_text/app.py [0:0]
def lambda_handler(event, context):
attachment_data = event['attachment_data']
response = textract_detect_text(attachment_data)
text_found = []
for block in response['Blocks']:
if block['BlockType'] == "LINE":
text_found.append(block['Text'])
# If no text detected, set text_detected to False
if len(text_found) == 0:
text_detected = False
return {
'text_detected': text_detected,
'attachment_data': attachment_data
}
# If text detected, concatenate lines of text
else:
text_detected = True
concatenated_text = " ".join(text_found)
return {
'text_detected': text_detected,
'attachment_text': concatenated_text,
'attachment_data': attachment_data
}