From 07723d495abec38dfa5dbd7c4ddaa2da50c39d10 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Fri, 7 Feb 2025 10:34:29 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B[bugfix]=20controller:=20offline?= =?UTF-8?q?=E6=99=82=E3=81=AE=E5=87=A6=E7=90=86=E3=81=A7=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=81=AB=E3=81=AA=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/controller.py | 51 +++++++++++++++++++++++----------------- src-python/mainloop.py | 1 - 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src-python/controller.py b/src-python/controller.py index 715886c4..bc57ae1d 100644 --- a/src-python/controller.py +++ b/src-python/controller.py @@ -29,12 +29,14 @@ class Controller: self.run( 200, self.run_mapping["connected_network"], + True, ) def disconnectedNetwork(self) -> None: self.run( 200, - self.run_mapping["disconnected_network"], + self.run_mapping["connected_network"], + False, ) def updateMicHostList(self) -> None: @@ -526,7 +528,10 @@ class Controller: your_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"] for target_language in config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO].values(): if your_language["language"] == target_language["language"] and target_language["enable"] is True: - engines = ["CTranslate2"] + if config.SELECTABLE_TRANSLATION_ENGINE_STATUS["CTranslate2"] is True: + engines = ["CTranslate2"] + else: + engines = [] return {"status":200, "result":engines} @@ -1707,6 +1712,7 @@ class Controller: self.connectedNetwork() else: self.disconnectedNetwork() + printLog(f"Connected Network: {connected_network}") printLog("Init Translation Engine Status") for engine in config.SELECTABLE_TRANSLATION_ENGINE_LIST: @@ -1724,28 +1730,29 @@ class Controller: config.AUTH_KEYS = auth_keys self.initializationProgress(1) - # download CTranslate2 Model Weight - printLog("Download CTranslate2 Model Weight") - weight_type = config.CTRANSLATE2_WEIGHT_TYPE - th_download_ctranslate2 = None - if model.checkTranslatorCTranslate2ModelWeight(weight_type) is False: - th_download_ctranslate2 = Thread(target=self.downloadCtranslate2Weight, args=(weight_type, False)) - th_download_ctranslate2.daemon = True - th_download_ctranslate2.start() + if connected_network is True: + # download CTranslate2 Model Weight + printLog("Download CTranslate2 Model Weight") + weight_type = config.CTRANSLATE2_WEIGHT_TYPE + th_download_ctranslate2 = None + if model.checkTranslatorCTranslate2ModelWeight(weight_type) is False: + th_download_ctranslate2 = Thread(target=self.downloadCtranslate2Weight, args=(weight_type, False)) + th_download_ctranslate2.daemon = True + th_download_ctranslate2.start() - # download Whisper Model Weight - printLog("Download Whisper Model Weight") - weight_type = config.WHISPER_WEIGHT_TYPE - th_download_whisper = None - if model.checkTranscriptionWhisperModelWeight(weight_type) is False: - th_download_whisper = Thread(target=self.downloadWhisperWeight, args=(weight_type, False)) - th_download_whisper.daemon = True - th_download_whisper.start() + # download Whisper Model Weight + printLog("Download Whisper Model Weight") + weight_type = config.WHISPER_WEIGHT_TYPE + th_download_whisper = None + if model.checkTranscriptionWhisperModelWeight(weight_type) is False: + th_download_whisper = Thread(target=self.downloadWhisperWeight, args=(weight_type, False)) + th_download_whisper.daemon = True + th_download_whisper.start() - if isinstance(th_download_ctranslate2, Thread): - th_download_ctranslate2.join() - if isinstance(th_download_whisper, Thread): - th_download_whisper.join() + if isinstance(th_download_ctranslate2, Thread): + th_download_ctranslate2.join() + if isinstance(th_download_whisper, Thread): + th_download_whisper.join() for engine in config.SELECTABLE_TRANSLATION_ENGINE_LIST: match engine: diff --git a/src-python/mainloop.py b/src-python/mainloop.py index 7c7ab51d..67b5e36b 100644 --- a/src-python/mainloop.py +++ b/src-python/mainloop.py @@ -9,7 +9,6 @@ from utils import printLog, printResponse, errorLogging, encodeBase64 run_mapping = { "connected_network":"/run/connected_network", - "disconnected_network":"/run/disconnected_network", "transcription_mic":"/run/transcription_send_mic_message", "transcription_speaker":"/run/transcription_receive_speaker_message",