diff --git a/.gitignore b/.gitignore index c6967444..75c28a41 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ logs/ weight/ .vscode error.log +*.exe diff --git a/config.py b/config.py index dc882684..371ec121 100644 --- a/config.py +++ b/config.py @@ -731,7 +731,7 @@ class Config: def init_config(self): # Read Only - self._VERSION = "2.1.0" + self._VERSION = "2.1.1" self._ENABLE_SPEAKER2CHATBOX = False # Speaker2Chatbox self._PATH_LOCAL = os_path.dirname(sys.argv[0]) self._PATH_CONFIG = os_path.join(self._PATH_LOCAL, "config.json") diff --git a/model.py b/model.py index 8580e85d..573659a7 100644 --- a/model.py +++ b/model.py @@ -12,7 +12,6 @@ from threading import Thread, Event from requests import get as requests_get import webbrowser -from tqdm import tqdm from typing import Callable from flashtext import KeywordProcessor from models.translation.translation_translator import Translator @@ -267,16 +266,13 @@ class Model: with tempfile.TemporaryDirectory() as tmp_path: res = requests_get(url, stream=True) file_size = int(res.headers.get('content-length', 0)) - pbar = tqdm(total=file_size, unit="B", unit_scale=True) total_chunk = 0 with open(os_path.join(tmp_path, filename), 'wb') as file: for chunk in res.iter_content(chunk_size=1024*5): file.write(chunk) - pbar.update(len(chunk)) if isinstance(func, Callable): total_chunk += len(chunk) func(total_chunk/file_size) - pbar.close() with ZipFile(os_path.join(tmp_path, filename)) as zf: zf.extractall(os_path.join(current_directory, tmp_directory_name)) diff --git a/models/translation/translation_translator.py b/models/translation/translation_translator.py index fbe6cf3f..f3d3c99e 100644 --- a/models/translation/translation_translator.py +++ b/models/translation/translation_translator.py @@ -38,11 +38,30 @@ class Translator(): ) self.ctranslate2_tokenizer = transformers.AutoTokenizer.from_pretrained(tokenizer) + @staticmethod + def getLanguageCode(translator_name, target_country, source_language, target_language): + match translator_name: + case "DeepL_API": + if target_language == "English": + if target_country in ["United States", "Canada", "Philippines"]: + target_language = "English American" + else: + target_language = "English British" + elif target_language == "Portuguese": + if target_country in ["Portugal"]: + target_language = "Portuguese European" + else: + target_language = "Portuguese Brazilian" + case _: + pass + source_language=translation_lang[translator_name]["source"][source_language] + target_language=translation_lang[translator_name]["target"][target_language] + return source_language, target_language + def translate(self, translator_name, source_language, target_language, target_country, message): try: result = "" - source_language=translation_lang[translator_name]["source"][source_language] - target_language=translation_lang[translator_name]["target"][target_language] + source_language, target_language = self.getLanguageCode(translator_name, target_country, source_language, target_language) match translator_name: case "DeepL": result = other_web_Translator( @@ -55,16 +74,6 @@ class Translator(): if self.deepl_client is None: result = False else: - if target_language == "English": - if target_country in ["United States", "Canada", "Philippines"]: - target_language = "English American" - else: - target_language = "English British" - elif target_language == "Portuguese": - if target_country in ["Portugal"]: - target_language = "Portuguese European" - else: - target_language = "Portuguese Brazilian" result = self.deepl_client.translate_text( message, source_lang=source_language,