Parallel processing
Some checks failed
Python application / build (push) Has been cancelled

This commit is contained in:
illian64 2025-10-25 11:32:09 +07:00 committed by GitHub
parent 8c92dcc028
commit 17ade3687f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 345 additions and 72 deletions

View file

@ -2,9 +2,8 @@ import os
import pysrt
from app import file_processor, params
from app import file_processor, params, parallel_process, dto
from app.app_core import AppCore
from app.dto import ProcessingFileDirReq, ProcessingFileResp, FileProcessingPluginInitInfo, ProcessingFileStruct
plugin_name = os.path.basename(__file__)[:-3] # calculating modname
@ -45,15 +44,31 @@ def start_with_options(core: AppCore, manifest: dict):
pass
def init(core: AppCore) -> FileProcessingPluginInitInfo:
return FileProcessingPluginInitInfo(plugin_name=plugin_name, supported_extensions={"srt"})
def init(core: AppCore) -> dto.FileProcessingPluginInitInfo:
return dto.FileProcessingPluginInitInfo(plugin_name=plugin_name, supported_extensions={"srt"})
def file_processing(core: AppCore, file_struct: ProcessingFileStruct, req: ProcessingFileDirReq) -> ProcessingFileResp:
def parallel_preprocessing(subs, core: AppCore, req: dto.ProcessingFileDirReq) -> None:
gpu_count_for_parallel = parallel_process.translate_plugin_support_parallel_gpu_count(core, req.translator_plugin)
if gpu_count_for_parallel is None:
return None
# First pre-pass - translate without any actions, for fill cache. Next pass get translated text from cache.
translate_params: list[dto.TranslateCommonRequest] = list()
for sub in subs:
translate_req = req.translate_req(sub.text, "")
translate_params.append(translate_req)
parallel_process.start_parallel_processing(gpu_count_for_parallel, core, translate_params)
def file_processing(core: AppCore, file_struct: dto.ProcessingFileStruct, req: dto.ProcessingFileDirReq) -> dto.ProcessingFileResp:
options = core.plugin_options(plugin_name)
text_format = params.read_plugin_file_processing_text_format(options)
subs = pysrt.open(file_struct.path_file_in())
parallel_preprocessing(subs, core, req)
for sub in subs:
text = sub.text
translate_req = req.translate_req(text, "")
@ -71,7 +86,7 @@ def file_processing(core: AppCore, file_struct: ProcessingFileStruct, req: Proce
return file_processor.get_processing_file_resp_ok(file_struct=file_struct, file_out=out_file_name)
def processed_file_name(core: AppCore, file_struct: ProcessingFileStruct, req: ProcessingFileDirReq) -> str:
def processed_file_name(core: AppCore, file_struct: dto.ProcessingFileStruct, req: dto.ProcessingFileDirReq) -> str:
options = core.plugin_options(plugin_name)
src_postfix = options["remove_src_filename_postfix"]