diff --git a/src-python/models/transcription/transcription_whisper.py b/src-python/models/transcription/transcription_whisper.py index 08113b8c..971d8d71 100644 --- a/src-python/models/transcription/transcription_whisper.py +++ b/src-python/models/transcription/transcription_whisper.py @@ -40,6 +40,7 @@ def downloadFile(url, path, func=None): if isinstance(func, Callable): total_chunk += len(chunk) func(total_chunk/file_size) + printLog(f"Downloading Whisper Model: {total_chunk/file_size:.0%}") except Exception as e: printLog("warning:downloadFile()", e) diff --git a/src-python/models/translation/translation_utils.py b/src-python/models/translation/translation_utils.py index 48e97e3a..aa6437da 100644 --- a/src-python/models/translation/translation_utils.py +++ b/src-python/models/translation/translation_utils.py @@ -81,9 +81,9 @@ def downloadCTranslate2Weight(root, weight_type="Small", callbackFunc=None): if isinstance(callbackFunc, Callable): total_chunk += len(chunk) callbackFunc(total_chunk/file_size) - printLog(f"Downloading {filename}: {total_chunk/file_size:.0%}") + printLog(f"Downloading CTranslate Model: {total_chunk/file_size:.0%}") with ZipFile(os_path.join(tmp_path, filename)) as zf: zf.extractall(path) except Exception as e: - printLog("error:downloadCTranslate2Weight()", e) \ No newline at end of file + printLog("warning:downloadCTranslate2Weight()", e) \ No newline at end of file diff --git a/src-python/utils.py b/src-python/utils.py index 2ff40bb8..eb991c39 100644 --- a/src-python/utils.py +++ b/src-python/utils.py @@ -81,7 +81,7 @@ def printLog(log:str, data:Any=None) -> None: response = { "status": 348, "log": log, - "data": data, + "data": str(data), } with open('process.log', 'a', encoding="utf-8") as f: diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index afef99ad..a5d257ef 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -1,4 +1,3 @@ -import json from typing import Callable, Union from time import sleep from subprocess import Popen @@ -701,10 +700,15 @@ class DownloadCTranslate2ProgressBar: } }) +def startThreadingDownloadCtranslate2Weight(callback:Callable[[float], None]) -> None: + th_download = Thread(target=model.downloadCTranslate2ModelWeight, args=(callback,)) + th_download.daemon = True + th_download.start() + def callbackDownloadCtranslate2Weight(data, action, *args, **kwargs) -> dict: printLog("Download CTranslate2 Weight") download = DownloadCTranslate2ProgressBar(action) - model.downloadCTranslate2ModelWeight(download.set) + startThreadingDownloadCtranslate2Weight(download.set) return {"status":200} def callbackSetDeeplAuthKey(data, *args, **kwargs) -> dict: @@ -1034,10 +1038,15 @@ class DownloadWhisperProgressBar: } }) +def startThreadingDownloadWhisperWeight(callback:Callable[[float], None]) -> None: + th_download = Thread(target=model.downloadWhisperModelWeight, args=(callback,)) + th_download.daemon = True + th_download.start() + def callbackDownloadWhisperWeight(data, action, *args, **kwargs) -> dict: printLog("Download Whisper Weight") - download = DownloadCTranslate2ProgressBar(action) - model.downloadWhisperModelWeight(download.set) + download = DownloadWhisperProgressBar(action) + startThreadingDownloadWhisperWeight(download.set) return {"status":200} # VR Tab @@ -1283,8 +1292,7 @@ def init(endpoints:dict, *args, **kwargs) -> None: if config.USE_TRANSLATION_FEATURE is True and model.checkCTranslatorCTranslate2ModelWeight() is False: def callback(progress): printResponse(200, endpoints["ctranslate2"], {"progress":progress}) - printLog("Download CTranslate2 Model Weight") - model.downloadCTranslate2ModelWeight(callback) + startThreadingDownloadCtranslate2Weight(callback) # set Transcription Engine printLog("Set Transcription Engine") @@ -1298,7 +1306,7 @@ def init(endpoints:dict, *args, **kwargs) -> None: if config.USE_WHISPER_FEATURE is True and model.checkTranscriptionWhisperModelWeight() is False: def callback(progress): printResponse(200, endpoints["whisper"], {"progress":progress}) - model.downloadWhisperModelWeight(callback) + startThreadingDownloadWhisperWeight(callback) # set word filter printLog("Set Word Filter") diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index 3eb3f567..0450fd0d 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -297,8 +297,8 @@ def main(): if __name__ == "__main__": controller.init({ - "ctranslate2": action_mapping["/controller/callback_download_ctranslate2_weight"]["download"], - "whisper": action_mapping["/controller/callback_download_whisper_weight"]["download"], + "ctranslate2": action_mapping["/controller/callback_download_ctranslate2_weight"], + "whisper": action_mapping["/controller/callback_download_whisper_weight"], }) process = "main"