From 92ea7914b8f4c74862b8c10dfc7711c01282074e Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Sun, 26 Nov 2023 00:30:59 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8D[Update]=20model=20:=20=E3=83=A2?= =?UTF-8?q?=E3=83=87=E3=83=AB=E3=81=AE=E3=83=AD=E3=83=BC=E3=83=89=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 4 ++++ model.py | 33 --------------------------------- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/main.py b/main.py index def1cb0b..14c97ac4 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,10 @@ if __name__ == "__main__": splash = SplashWindow() splash.showSplash() + from config import config + from models.translation.utils import downloadCTranslate2Weight + downloadCTranslate2Weight(config.PATH_LOCAL, config.WEIGHT_TYPE, config.CTRANSLATE2_WIGHTS) + import controller controller.createMainWindow() splash.destroySplash() diff --git a/model.py b/model.py index 21ea5fd7..ef035613 100644 --- a/model.py +++ b/model.py @@ -72,7 +72,6 @@ class Model: self.speaker_audio_recorder = None self.speaker_energy_recorder = None self.speaker_energy_plot_progressbar = None - self.downloadCTranslate2Weight() self.translator = Translator(config.PATH_LOCAL, config.CTRANSLATE2_WIGHTS[config.WEIGHT_TYPE]) self.keyword_processor = KeywordProcessor() @@ -109,38 +108,6 @@ class Model: self.logger.disabled = True self.logger = None - @staticmethod - def downloadCTranslate2Weight(): - weight_type = config.WEIGHT_TYPE - url = config.CTRANSLATE2_WIGHTS[weight_type]["url"] - filename = 'weight.zip' - directory_name = 'weight' - current_directory = config.PATH_LOCAL - weight_directory_name = config.CTRANSLATE2_WIGHTS[weight_type]["directory_name"] - files = ["model.bin", "sentencepiece.model", "shared_vocabulary.txt"] - - # check already downloaded - if all(os_path.exists(os_path.join(current_directory, directory_name, weight_directory_name, file)) for file in files): - return - - try: - os_makedirs(os_path.join(current_directory, directory_name), exist_ok=True) - print(os_path.join(current_directory, directory_name)) - with tempfile.TemporaryDirectory() as tmp_path: - file_size = int(requests_head(url).headers["content-length"]) - res = requests_get(url, stream=True) - pbar = tqdm(total=file_size, unit="B", unit_scale=True) - with open(os_path.join(tmp_path, filename), 'wb') as file: - for chunk in res.iter_content(chunk_size=1024): - file.write(chunk) - pbar.update(len(chunk)) - pbar.close() - - with ZipFile(os_path.join(tmp_path, filename)) as zf: - zf.extractall(os_path.join(current_directory, directory_name)) - except Exception as e: - print("error:downloadCTranslate2Weight()", e) - @staticmethod def getListLanguageAndCountry(): langs = []