REALCOMP / ocr_utils.py
Nassira's picture
Update ocr_utils.py
b0f26ed verified
Raw History Blame Contribute Delete
428 Bytes
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'])