mirror of
https://github.com/illian64/llm-translate.git
synced 2026-04-29 04:09:56 +00:00
This commit is contained in:
parent
8c92dcc028
commit
17ade3687f
10 changed files with 345 additions and 72 deletions
|
|
@ -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"]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue