Spaces:
Running
Running
Bobholamovic
commited on
Commit
·
db7a2e8
1
Parent(s):
31204be
Replace global lock with event
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import atexit
|
2 |
import functools
|
3 |
from queue import Queue
|
4 |
-
from threading import
|
5 |
|
6 |
from paddleocr import PaddleOCR, draw_ocr
|
7 |
from PIL import Image
|
@@ -9,8 +9,8 @@ import gradio as gr
|
|
9 |
|
10 |
|
11 |
LANG_CONFIG = {
|
12 |
-
"ch": {"num_workers":
|
13 |
-
"en": {"num_workers":
|
14 |
"fr": {"num_workers": 1},
|
15 |
"german": {"num_workers": 1},
|
16 |
"korean": {"num_workers": 1},
|
@@ -18,8 +18,6 @@ LANG_CONFIG = {
|
|
18 |
}
|
19 |
CONCURRENCY_LIMIT = 8
|
20 |
|
21 |
-
model_init_lock = Lock()
|
22 |
-
|
23 |
|
24 |
class PaddleOCRModelManager(object):
|
25 |
def __init__(self,
|
@@ -29,9 +27,12 @@ class PaddleOCRModelManager(object):
|
|
29 |
self._model_factory = model_factory
|
30 |
self._queue = Queue()
|
31 |
self._workers = []
|
|
|
32 |
for _ in range(num_workers):
|
33 |
worker = Thread(target=self._worker, daemon=False)
|
34 |
worker.start()
|
|
|
|
|
35 |
self._workers.append(worker)
|
36 |
|
37 |
def infer(self, *args, **kwargs):
|
@@ -51,8 +52,8 @@ class PaddleOCRModelManager(object):
|
|
51 |
worker.join()
|
52 |
|
53 |
def _worker(self):
|
54 |
-
|
55 |
-
|
56 |
while True:
|
57 |
item = self._queue.get()
|
58 |
if item is None:
|
|
|
1 |
import atexit
|
2 |
import functools
|
3 |
from queue import Queue
|
4 |
+
from threading import Event, Thread
|
5 |
|
6 |
from paddleocr import PaddleOCR, draw_ocr
|
7 |
from PIL import Image
|
|
|
9 |
|
10 |
|
11 |
LANG_CONFIG = {
|
12 |
+
"ch": {"num_workers": 2},
|
13 |
+
"en": {"num_workers": 2},
|
14 |
"fr": {"num_workers": 1},
|
15 |
"german": {"num_workers": 1},
|
16 |
"korean": {"num_workers": 1},
|
|
|
18 |
}
|
19 |
CONCURRENCY_LIMIT = 8
|
20 |
|
|
|
|
|
21 |
|
22 |
class PaddleOCRModelManager(object):
|
23 |
def __init__(self,
|
|
|
27 |
self._model_factory = model_factory
|
28 |
self._queue = Queue()
|
29 |
self._workers = []
|
30 |
+
self._model_initialized_event = Event()
|
31 |
for _ in range(num_workers):
|
32 |
worker = Thread(target=self._worker, daemon=False)
|
33 |
worker.start()
|
34 |
+
self._model_initialized_event.wait()
|
35 |
+
self._model_initialized_event.clear()
|
36 |
self._workers.append(worker)
|
37 |
|
38 |
def infer(self, *args, **kwargs):
|
|
|
52 |
worker.join()
|
53 |
|
54 |
def _worker(self):
|
55 |
+
model = self._model_factory()
|
56 |
+
self._model_initialized_event.set()
|
57 |
while True:
|
58 |
item = self._queue.get()
|
59 |
if item is None:
|