👍️[Update] Controller : 翻訳エンジンがlimit error時にerror対象の翻訳エンジンのみを使用不可にするように変更
This commit is contained in:
@@ -228,6 +228,15 @@ class Config:
|
|||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
self._SELECTABLE_WHISPER_WEIGHT_TYPE_DICT = value
|
self._SELECTABLE_WHISPER_WEIGHT_TYPE_DICT = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def SELECTABLE_TRANSLATION_ENGINE_STATUS(self):
|
||||||
|
return self._SELECTABLE_TRANSLATION_ENGINE_STATUS
|
||||||
|
|
||||||
|
@SELECTABLE_TRANSLATION_ENGINE_STATUS.setter
|
||||||
|
def SELECTABLE_TRANSLATION_ENGINE_STATUS(self, value):
|
||||||
|
if isinstance(value, dict):
|
||||||
|
self._SELECTABLE_TRANSLATION_ENGINE_STATUS = value
|
||||||
|
|
||||||
# Save Json Data
|
# Save Json Data
|
||||||
## Main Window
|
## Main Window
|
||||||
@property
|
@property
|
||||||
@@ -952,6 +961,9 @@ class Config:
|
|||||||
self._SELECTABLE_WHISPER_WEIGHT_TYPE_DICT = {}
|
self._SELECTABLE_WHISPER_WEIGHT_TYPE_DICT = {}
|
||||||
for weight_type in self.SELECTABLE_WHISPER_WEIGHT_TYPE_LIST:
|
for weight_type in self.SELECTABLE_WHISPER_WEIGHT_TYPE_LIST:
|
||||||
self._SELECTABLE_WHISPER_WEIGHT_TYPE_DICT[weight_type] = False
|
self._SELECTABLE_WHISPER_WEIGHT_TYPE_DICT[weight_type] = False
|
||||||
|
self._SELECTABLE_TRANSLATION_ENGINE_STATUS = {}
|
||||||
|
for engine in self.SELECTABLE_TRANSLATION_ENGINE_LIST:
|
||||||
|
self._SELECTABLE_TRANSLATION_ENGINE_STATUS[engine] = False
|
||||||
|
|
||||||
# Save Json Data
|
# Save Json Data
|
||||||
## Main Window
|
## Main Window
|
||||||
|
|||||||
@@ -165,7 +165,8 @@ class Model:
|
|||||||
languages = sorted(languages, key=lambda x: x['language'])
|
languages = sorted(languages, key=lambda x: x['language'])
|
||||||
return languages
|
return languages
|
||||||
|
|
||||||
def findTranslationEngines(self, source_lang, target_lang):
|
def findTranslationEngines(self, source_lang, target_lang, engines_status):
|
||||||
|
selectable_engines = [key for key, value in engines_status.items() if value is True]
|
||||||
compatible_engines = []
|
compatible_engines = []
|
||||||
for engine in list(translation_lang.keys()):
|
for engine in list(translation_lang.keys()):
|
||||||
languages = translation_lang.get(engine, {}).get("source", {})
|
languages = translation_lang.get(engine, {}).get("source", {})
|
||||||
@@ -174,11 +175,9 @@ class Model:
|
|||||||
language_list = list(languages.keys())
|
language_list = list(languages.keys())
|
||||||
|
|
||||||
if all(e in language_list for e in source_langs) and all(e in language_list for e in target_langs):
|
if all(e in language_list for e in source_langs) and all(e in language_list for e in target_langs):
|
||||||
|
if engine in selectable_engines:
|
||||||
compatible_engines.append(engine)
|
compatible_engines.append(engine)
|
||||||
|
|
||||||
if "DeepL_API" in compatible_engines:
|
|
||||||
if config.AUTH_KEYS["DeepL_API"] is None:
|
|
||||||
compatible_engines.remove('DeepL_API')
|
|
||||||
return compatible_engines
|
return compatible_engines
|
||||||
|
|
||||||
def getTranslate(self, translator_name, source_language, target_language, target_country, message):
|
def getTranslate(self, translator_name, source_language, target_language, target_country, message):
|
||||||
|
|||||||
@@ -484,6 +484,7 @@ class Controller:
|
|||||||
engines = model.findTranslationEngines(
|
engines = model.findTranslationEngines(
|
||||||
config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO],
|
config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO],
|
||||||
config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO],
|
config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO],
|
||||||
|
config.SELECTABLE_TRANSLATION_ENGINE_STATUS,
|
||||||
)
|
)
|
||||||
return {"status":200, "result":engines}
|
return {"status":200, "result":engines}
|
||||||
|
|
||||||
@@ -1029,6 +1030,7 @@ class Controller:
|
|||||||
|
|
||||||
def setDeeplAuthKey(self, data, *args, **kwargs) -> dict:
|
def setDeeplAuthKey(self, data, *args, **kwargs) -> dict:
|
||||||
printLog("Set DeepL Auth Key", data)
|
printLog("Set DeepL Auth Key", data)
|
||||||
|
translator_name = "DeepL_API"
|
||||||
try:
|
try:
|
||||||
data = str(data)
|
data = str(data)
|
||||||
if len(data) == 36 or len(data) == 39:
|
if len(data) == 36 or len(data) == 39:
|
||||||
@@ -1036,16 +1038,17 @@ class Controller:
|
|||||||
if result is True:
|
if result is True:
|
||||||
key = data
|
key = data
|
||||||
auth_keys = config.AUTH_KEYS
|
auth_keys = config.AUTH_KEYS
|
||||||
auth_keys["DeepL_API"] = key
|
auth_keys[translator_name] = key
|
||||||
config.AUTH_KEYS = auth_keys
|
config.AUTH_KEYS = auth_keys
|
||||||
|
config.SELECTABLE_TRANSLATION_ENGINE_STATUS[translator_name] = True
|
||||||
self.updateTranslationEngineAndEngineList()
|
self.updateTranslationEngineAndEngineList()
|
||||||
response = {"status":200, "result":config.AUTH_KEYS["DeepL_API"]}
|
response = {"status":200, "result":config.AUTH_KEYS[translator_name]}
|
||||||
else:
|
else:
|
||||||
response = {
|
response = {
|
||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
"message":"DeepL auth key length is not correct",
|
"message":"DeepL auth key length is not correct",
|
||||||
"data": config.AUTH_KEYS["DeepL_API"]
|
"data": config.AUTH_KEYS[translator_name]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
@@ -1053,7 +1056,7 @@ class Controller:
|
|||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
"message":"Authentication failure of deepL auth key",
|
"message":"Authentication failure of deepL auth key",
|
||||||
"data": config.AUTH_KEYS["DeepL_API"]
|
"data": config.AUTH_KEYS[translator_name]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -1062,17 +1065,19 @@ class Controller:
|
|||||||
"status":400,
|
"status":400,
|
||||||
"result":{
|
"result":{
|
||||||
"message":f"Error {e}",
|
"message":f"Error {e}",
|
||||||
"data": config.AUTH_KEYS["DeepL_API"]
|
"data": config.AUTH_KEYS[translator_name]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def delDeeplAuthKey(self, *args, **kwargs) -> dict:
|
def delDeeplAuthKey(self, *args, **kwargs) -> dict:
|
||||||
|
translator_name = "DeepL_API"
|
||||||
auth_keys = config.AUTH_KEYS
|
auth_keys = config.AUTH_KEYS
|
||||||
auth_keys["DeepL_API"] = None
|
auth_keys[translator_name] = None
|
||||||
config.AUTH_KEYS = auth_keys
|
config.AUTH_KEYS = auth_keys
|
||||||
|
config.SELECTABLE_TRANSLATION_ENGINE_STATUS[translator_name] = False
|
||||||
self.updateTranslationEngineAndEngineList()
|
self.updateTranslationEngineAndEngineList()
|
||||||
return {"status":200, "result":config.AUTH_KEYS["DeepL_API"]}
|
return {"status":200, "result":config.AUTH_KEYS[translator_name]}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getCtranslate2WeightType(*args, **kwargs) -> dict:
|
def getCtranslate2WeightType(*args, **kwargs) -> dict:
|
||||||
@@ -1429,8 +1434,12 @@ class Controller:
|
|||||||
return osc_message
|
return osc_message
|
||||||
|
|
||||||
def changeToCTranslate2Process(self) -> None:
|
def changeToCTranslate2Process(self) -> None:
|
||||||
|
selected_engines = config.SELECTED_TRANSLATION_ENGINES[config.SELECTED_TAB_NO]
|
||||||
|
config.SELECTABLE_TRANSLATION_ENGINE_STATUS[selected_engines] = False
|
||||||
config.SELECTED_TRANSLATION_ENGINES[config.SELECTED_TAB_NO] = "CTranslate2"
|
config.SELECTED_TRANSLATION_ENGINES[config.SELECTED_TAB_NO] = "CTranslate2"
|
||||||
self.run(200, self.run_mapping["translation_engines"], "CTranslate2")
|
selectable_engines = self.getTranslationEngines()["result"]
|
||||||
|
self.run(200, self.run_mapping["selected_translation_engines"], config.SELECTED_TRANSLATION_ENGINES)
|
||||||
|
self.run(200, self.run_mapping["translation_engines"], selectable_engines)
|
||||||
|
|
||||||
def startTranscriptionSendMessage(self) -> None:
|
def startTranscriptionSendMessage(self) -> None:
|
||||||
while self.device_access_status is False:
|
while self.device_access_status is False:
|
||||||
@@ -1626,13 +1635,22 @@ class Controller:
|
|||||||
printLog("Start Initialization")
|
printLog("Start Initialization")
|
||||||
removeLog()
|
removeLog()
|
||||||
|
|
||||||
|
printLog("Init Translation Engine Status")
|
||||||
|
for engine in config.SELECTABLE_TRANSLATION_ENGINE_LIST:
|
||||||
|
match engine:
|
||||||
|
case "DeepL_API":
|
||||||
printLog("Start check DeepL API Key")
|
printLog("Start check DeepL API Key")
|
||||||
if config.AUTH_KEYS["DeepL_API"] is not None:
|
config.SELECTABLE_TRANSLATION_ENGINE_STATUS[engine] = False
|
||||||
if model.authenticationTranslatorDeepLAuthKey(auth_key=config.AUTH_KEYS["DeepL_API"]) is False:
|
if config.AUTH_KEYS[engine] is not None:
|
||||||
|
if model.authenticationTranslatorDeepLAuthKey(auth_key=config.AUTH_KEYS[engine]) is True:
|
||||||
|
config.SELECTABLE_TRANSLATION_ENGINE_STATUS[engine] = True
|
||||||
|
else:
|
||||||
# error update Auth key
|
# error update Auth key
|
||||||
auth_keys = config.AUTH_KEYS
|
auth_keys = config.AUTH_KEYS
|
||||||
auth_keys["DeepL_API"] = None
|
auth_keys[engine] = None
|
||||||
config.AUTH_KEYS = auth_keys
|
config.AUTH_KEYS = auth_keys
|
||||||
|
case _:
|
||||||
|
config.SELECTABLE_TRANSLATION_ENGINE_STATUS[engine] = True
|
||||||
|
|
||||||
self.initializationProgress(1)
|
self.initializationProgress(1)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user