Devashishraghav commited on
Commit
1d828f9
·
verified ·
1 Parent(s): 3c628b4

Upload processor/redaction.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. 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
- # Initialize the EasyOCR reader (loads model on first run)
6
- reader = easyocr.Reader(['en'], gpu=False) # Set gpu=True if applicable
 
 
 
 
 
 
 
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 = reader.readtext(img)
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: