File size: 565 Bytes
172553b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # ocr_utils.py
import boto3
import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
textract_client = boto3.client('textract', region_name='us-west-2')
def extract_text_aws(file_content):
try:
response = textract_client.detect_document_text(Document={'Bytes': file_content})
text = ' '.join([item['Text'] for item in response['Blocks'] if item['BlockType'] == 'WORD'])
return text
except Exception as e:
logging.error(f"Error in AWS Textract: {str(e)}")
return "" |