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