File size: 428 Bytes
7c74c02 b0f26ed 7c74c02 b0f26ed | 1 2 3 4 5 6 7 8 9 10 11 | import boto3
# Initialize AWS Textract client once
textract_client = boto3.client('textract', region_name='us-west-2')
def extract_text(file):
# Extract text using AWS Textract
response = textract_client.detect_document_text(Document={'Bytes': file.getvalue()})
# Use list comprehension to extract and join text
return " ".join([item['Text'] for item in response['Blocks'] if item['BlockType'] == 'WORD']) |