Spaces:
Build error
Build error
Upload processor/redaction.py with huggingface_hub
Browse files- processor/redaction.py +10 -4
processor/redaction.py
CHANGED
|
@@ -1,9 +1,15 @@
|
|
| 1 |
import cv2
|
| 2 |
-
import easyocr
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def redact_names(img: np.ndarray) -> np.ndarray:
|
| 9 |
"""
|
|
@@ -16,7 +22,7 @@ def redact_names(img: np.ndarray) -> np.ndarray:
|
|
| 16 |
h, w = img.shape[:2]
|
| 17 |
|
| 18 |
# Run OCR on the image
|
| 19 |
-
results =
|
| 20 |
|
| 21 |
has_text = False
|
| 22 |
for (bbox, text, prob) in results:
|
|
|
|
| 1 |
import cv2
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
+
# Lazy-loaded EasyOCR reader (only initialized when redact_names is called)
|
| 5 |
+
_reader = None
|
| 6 |
+
|
| 7 |
+
def _get_reader():
|
| 8 |
+
global _reader
|
| 9 |
+
if _reader is None:
|
| 10 |
+
import easyocr
|
| 11 |
+
_reader = easyocr.Reader(['en'], gpu=False)
|
| 12 |
+
return _reader
|
| 13 |
|
| 14 |
def redact_names(img: np.ndarray) -> np.ndarray:
|
| 15 |
"""
|
|
|
|
| 22 |
h, w = img.shape[:2]
|
| 23 |
|
| 24 |
# Run OCR on the image
|
| 25 |
+
results = _get_reader().readtext(img)
|
| 26 |
|
| 27 |
has_text = False
|
| 28 |
for (bbox, text, prob) in results:
|