Nassira commited on
Commit
7c74c02
·
verified ·
1 Parent(s): 1aed4ce

Create ocr_utils.py

Browse files
Files changed (1) hide show
  1. ocr_utils.py +12 -0
ocr_utils.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import boto3
2
+
3
+ # AWS Textract client
4
+ textract_client = boto3.client('textract', region_name='us-west-2')
5
+
6
+ def extract_text_aws(image_bytes):
7
+ response = textract_client.detect_document_text(Document={'Bytes': image_bytes})
8
+ return " ".join([item['Text'] for item in response['Blocks'] if item['BlockType'] == 'WORD'])
9
+
10
+ def extract_text_combined(file):
11
+ file_bytes = file.getvalue()
12
+ return extract_text_aws(file_bytes)