From c257591b217098c38987ad28d86847c59f6d7b6a Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Tue, 13 Jan 2026 15:25:01 +0900 Subject: [PATCH] =?UTF-8?q?[Update]=20=E5=BE=8C=E6=96=B9=E4=BA=92=E6=8F=9B?= =?UTF-8?q?=E6=80=A7=E3=81=AE=E3=81=9F=E3=82=81=E3=81=AE=E3=83=A2=E3=83=87?= =?UTF-8?q?=E3=83=AB=E3=81=AE=E9=87=8D=E3=81=BF=E3=83=87=E3=82=A3=E3=83=AC?= =?UTF-8?q?=E3=82=AF=E3=83=88=E3=83=AA=E5=90=8D=E5=A4=89=E6=9B=B4=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/controller.py | 25 +++++++++++++------ src-python/model.py | 5 +++- .../models/translation/translation_utils.py | 25 ++++++++++--------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src-python/controller.py b/src-python/controller.py index 4bc07e2f..99167a64 100644 --- a/src-python/controller.py +++ b/src-python/controller.py @@ -2870,10 +2870,13 @@ class Controller: if hasattr(self, '_ctranslate2_available_cache'): # 起動時のキャッシュを使用: 選択中の重みタイプのみ設定 config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT[config.CTRANSLATE2_WEIGHT_TYPE] = self._ctranslate2_available_cache - else: - # 通常時は全重みタイプをチェック - for weight_type in config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT.keys(): - config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT[weight_type] = model.checkTranslatorCTranslate2ModelWeight(weight_type) + + # すべての重みタイプをチェック(キャッシュされていないものだけ) + for weight_type in config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT.keys(): + # 選択中のウェイトはキャッシュで設定済みなのでスキップ + if hasattr(self, '_ctranslate2_available_cache') and weight_type == config.CTRANSLATE2_WEIGHT_TYPE: + continue + config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT[weight_type] = model.checkTranslatorCTranslate2ModelWeight(weight_type) def updateTranslationEngineAndEngineList(self): engines = config.SELECTED_TRANSLATION_ENGINES @@ -2899,10 +2902,13 @@ class Controller: if hasattr(self, '_whisper_available_cache'): # 起動時のキャッシュを使用: 選択中の重みタイプのみ設定 config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT[config.WHISPER_WEIGHT_TYPE] = self._whisper_available_cache - else: - # 通常時は全重みタイプをチェック - for weight_type in config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT.keys(): - config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT[weight_type] = model.checkTranscriptionWhisperModelWeight(weight_type) + + # すべての重みタイプをチェック(キャッシュされていないものだけ) + for weight_type in config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT.keys(): + # 選択中のウェイトはキャッシュで設定済みなのでスキップ + if hasattr(self, '_whisper_available_cache') and weight_type == config.WHISPER_WEIGHT_TYPE: + continue + config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT[weight_type] = model.checkTranscriptionWhisperModelWeight(weight_type) def updateTranscriptionEngine(self): weight_type = config.WHISPER_WEIGHT_TYPE @@ -3134,6 +3140,9 @@ class Controller: # Download weights if connected_network is True: printLog("Download CTranslate2 Model Weight") + # 後方互換用 + model.backwardCompatibleTranslatorCTranslate2ModelRenameWeightsDir() + weight_type = config.CTRANSLATE2_WEIGHT_TYPE th_download_ctranslate2 = None if model.checkTranslatorCTranslate2ModelWeight(weight_type) is False: diff --git a/src-python/model.py b/src-python/model.py index 0632396c..bd989485 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -25,7 +25,7 @@ from models.transcription.transcription_recorder import SelectedMicEnergyRecorde from models.transcription.transcription_transcriber import AudioTranscriber from models.translation.translation_languages import translation_lang from models.transcription.transcription_languages import transcription_lang -from models.translation.translation_utils import checkCTranslate2Weight, downloadCTranslate2Weight, downloadCTranslate2Tokenizer +from models.translation.translation_utils import checkCTranslate2Weight, downloadCTranslate2Weight, downloadCTranslate2Tokenizer, backwardCompatibleRenameWeightsDir from models.transcription.transcription_whisper import checkWhisperWeight, downloadWhisperWeight from models.transliteration.transliteration_transliterator import Transliterator from models.overlay.overlay import Overlay @@ -158,6 +158,9 @@ class Model: # Log and continue; callers should handle missing features. errorLogging() + def backwardCompatibleTranslatorCTranslate2ModelRenameWeightsDir(self): + return backwardCompatibleRenameWeightsDir(config.PATH_LOCAL) + def checkTranslatorCTranslate2ModelWeight(self, weight_type:str): return checkCTranslate2Weight(config.PATH_LOCAL, weight_type) diff --git a/src-python/models/translation/translation_utils.py b/src-python/models/translation/translation_utils.py index f647c828..c5207061 100644 --- a/src-python/models/translation/translation_utils.py +++ b/src-python/models/translation/translation_utils.py @@ -48,22 +48,23 @@ ctranslate2_weights = { }, } +def backwardCompatibleRenameWeightsDir(root: str): + # 後方互換のためファイル名を変更する + legacy_dirs = { + "m2m100_418M": "m2m100_418M-ct2-int8", + "m2m100_12b": "m2m100_1.2B-ct2-int8", + } + + for weight_type_old, weight_type_new in legacy_dirs.items(): + path = os_path.join(root, "weights", "ctranslate2", weight_type_new) + old_path = os_path.join(root, "weights", "ctranslate2", weight_type_old) + if os_path.isdir(old_path): + os_rename(old_path, path) + def checkCTranslate2Weight(root: str, weight_type: str = "m2m100_418M-ct2-int8"): weight_directory_name = ctranslate2_weights[weight_type]["directory_name"] path = os_path.join(root, "weights", "ctranslate2", weight_directory_name) - # 後方互換のためファイル名を変更する - legacy_dirs = { - "m2m100_418M-ct2-int8": "m2m100_418M", - "m2m100_1.2B-ct2-int8": "m2m100_12b", - } - - legacy_dir = legacy_dirs.get(weight_type, None) - if legacy_dir: - old_path = os_path.join(root, "weights", "ctranslate2", legacy_dir) - if os_path.isdir(old_path): - os_rename(old_path, path) - try: # モデルロード可能かどうかで判定 compute_type = getBestComputeType("cpu", 0)