Spaces:
Sleeping
Sleeping
Update utils/image_processor.py
Browse files- utils/image_processor.py +6 -3
utils/image_processor.py
CHANGED
@@ -4,16 +4,19 @@ import os
|
|
4 |
import easyocr
|
5 |
from PIL import Image
|
6 |
|
7 |
-
#
|
8 |
-
|
|
|
|
|
9 |
try:
|
10 |
-
reader = easyocr.Reader(['en'])
|
11 |
ocr_available = True
|
12 |
except Exception as e:
|
13 |
print(f"Warning: EasyOCR initialization failed: {str(e)}")
|
14 |
print("Text extraction may not work properly.")
|
15 |
ocr_available = False
|
16 |
|
|
|
17 |
def preprocess_image(image):
|
18 |
"""
|
19 |
Preprocess image to improve OCR accuracy
|
|
|
4 |
import easyocr
|
5 |
from PIL import Image
|
6 |
|
7 |
+
# Ensure model downloads go to a writable directory
|
8 |
+
os.environ["EASYOCR_CACHE_DIR"] = "/tmp/.easyocr"
|
9 |
+
|
10 |
+
# Initialize EasyOCR reader once
|
11 |
try:
|
12 |
+
reader = easyocr.Reader(['en'], download_enabled=True, model_storage_directory="/tmp/.easyocr")
|
13 |
ocr_available = True
|
14 |
except Exception as e:
|
15 |
print(f"Warning: EasyOCR initialization failed: {str(e)}")
|
16 |
print("Text extraction may not work properly.")
|
17 |
ocr_available = False
|
18 |
|
19 |
+
|
20 |
def preprocess_image(image):
|
21 |
"""
|
22 |
Preprocess image to improve OCR accuracy
|