Nassira commited on
Commit
172553b
·
verified ·
1 Parent(s): dc1ec63

Create ocr_utils.py

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