Create ocr_utils.py
Browse files- 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)
|