Download ocr_utils.py from Nassira/REALCOMP: direct link, hf CLI and curl.
- Browser
- Download file 428 Bytes
-
https://huggingface.co/spaces/Nassira/REALCOMP/resolve/main/ocr_utils.py
- Command line
-
hf download hf://spaces/Nassira/REALCOMP/ocr_utils.py
-
curl -L -o ocr_utils.py https://huggingface.co/spaces/Nassira/REALCOMP/resolve/main/ocr_utils.py
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']) |