22from contextlib import AbstractContextManager , contextmanager
33from itertools import tee
44from pathlib import Path
5- from typing import Any
5+ from typing import Any , cast
66
77from caul .objects import ASRResult , PreprocessedInput
88from caul .tasks import (
1212 Postprocessor ,
1313 Preprocessor ,
1414)
15+ from datashare_python .dependencies import lifespan_worker_config
1516from datashare_python .types_ import ProgressRateHandler
1617from datashare_python .utils import (
1718 ActivityWithProgress ,
@@ -67,7 +68,7 @@ async def search_audios(
6768 self , project : str , query : dict [str , Any ], batch_size : int
6869 ) -> list [Path ]:
6970 es_client = lifespan_es_client ()
70- worker_config = ASRWorkerConfig ( )
71+ worker_config = cast ( ASRWorkerConfig , lifespan_worker_config () )
7172 batch_dir_name = activity_contextual_id ()
7273 workdir = worker_config .workdir
7374 batch_root = workdir / batch_dir_name
@@ -87,7 +88,7 @@ def preprocess(
8788 self , paths : list [Path ] | Path , config : ParakeetPreprocessorConfig
8889 ) -> list [Path ]:
8990 # TODO: this shouldn't be necessary, fix this bug
90- worker_config = ASRWorkerConfig ( )
91+ worker_config = cast ( ASRWorkerConfig , lifespan_worker_config () )
9192 audio_root = worker_config .audios_root
9293 workdir = worker_config .workdir
9394 # TODO: implement caching
@@ -120,7 +121,7 @@ def infer(
120121 ) -> list [Path ]:
121122 # TODO: fix this temporal by, we shouldn't have to reload
122123 config = _INFERENCE_CONFIG_TYPE_ADAPTER .validate_python (config )
123- worker_config = ASRWorkerConfig ( )
124+ worker_config = cast ( ASRWorkerConfig , lifespan_worker_config () )
124125 workdir = worker_config .workdir
125126 preprocessed_inputs = _LIST_OF_PATH_ADAPTER .validate_python (preprocessed_inputs )
126127 if progress is not None :
@@ -168,7 +169,7 @@ def postprocess(
168169 # TODO: this shouldn't be necessary, fix this bug
169170 input_paths = _LIST_OF_PATH_ADAPTER .validate_python (input_paths )
170171 config = ParakeetPostprocessorConfig .model_validate (config )
171- worker_config = ASRWorkerConfig ( )
172+ worker_config = cast ( ASRWorkerConfig , lifespan_worker_config () )
172173 workdir = worker_config .workdir
173174 artifacts_root = worker_config .artifacts_root
174175 inference_results = _LIST_OF_PATH_ADAPTER .validate_python (inference_results )
0 commit comments