Spaces:
Sleeping
Sleeping
Update utility/utils.py
Browse files- utility/utils.py +14 -5
utility/utils.py
CHANGED
|
@@ -21,8 +21,9 @@ logging.basicConfig(
|
|
| 21 |
)
|
| 22 |
|
| 23 |
# Set the PaddleOCR home directory to a writable location
|
|
|
|
| 24 |
|
| 25 |
-
os.environ[
|
| 26 |
|
| 27 |
RESULT_FOLDER = 'static/results/'
|
| 28 |
JSON_FOLDER = 'static/json/'
|
|
@@ -107,14 +108,22 @@ def ocr_with_paddle(img):
|
|
| 107 |
boxes = []
|
| 108 |
|
| 109 |
# Initialize PaddleOCR
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
ocr = PaddleOCR(
|
| 111 |
-
lang='en',
|
| 112 |
use_angle_cls=True,
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
| 116 |
)
|
| 117 |
|
|
|
|
| 118 |
# Check if img is a file path or an image array
|
| 119 |
if isinstance(img, str):
|
| 120 |
img = cv2.imread(img)
|
|
|
|
| 21 |
)
|
| 22 |
|
| 23 |
# Set the PaddleOCR home directory to a writable location
|
| 24 |
+
import os
|
| 25 |
|
| 26 |
+
os.environ["PADDLEOCR_HOME"] = "/app/paddleocr_models"
|
| 27 |
|
| 28 |
RESULT_FOLDER = 'static/results/'
|
| 29 |
JSON_FOLDER = 'static/json/'
|
|
|
|
| 108 |
boxes = []
|
| 109 |
|
| 110 |
# Initialize PaddleOCR
|
| 111 |
+
# ocr = PaddleOCR(
|
| 112 |
+
# lang='en',
|
| 113 |
+
# use_angle_cls=True,
|
| 114 |
+
# det_model_dir=os.path.join(os.environ['PADDLEOCR_HOME'], 'whl/det'),
|
| 115 |
+
# rec_model_dir=os.path.join(os.environ['PADDLEOCR_HOME'], 'whl/rec/en/en_PP-OCRv4_rec_infer'),
|
| 116 |
+
# cls_model_dir=os.path.join(os.environ['PADDLEOCR_HOME'], 'whl/cls/ch_ppocr_mobile_v2.0_cls_infer')
|
| 117 |
+
# )
|
| 118 |
ocr = PaddleOCR(
|
|
|
|
| 119 |
use_angle_cls=True,
|
| 120 |
+
lang='en',
|
| 121 |
+
det_model_dir='/app/paddleocr_models/whl/det/ch_ppocr_mobile_v2.0_det_infer',
|
| 122 |
+
rec_model_dir='/app/paddleocr_models/whl/rec/ch_ppocr_mobile_v2.0_rec_infer',
|
| 123 |
+
cls_model_dir='/app/paddleocr_models/whl/cls/ch_ppocr_mobile_v2.0_cls_infer'
|
| 124 |
)
|
| 125 |
|
| 126 |
+
|
| 127 |
# Check if img is a file path or an image array
|
| 128 |
if isinstance(img, str):
|
| 129 |
img = cv2.imread(img)
|