From 8d9013ef51fd8ddc901c6aca1f16756421fe3924 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:46:45 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Model=20:=20cud?= =?UTF-8?q?a=E7=89=88=E3=81=AEsoftware=E3=82=92=E3=83=80=E3=82=A6=E3=83=B3?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=89=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=ABendpoint=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/model.py | 22 ++++++++++++++++++++++ src-python/webui_controller.py | 6 ++++++ src-python/webui_mainloop.py | 1 + 3 files changed, 29 insertions(+) diff --git a/src-python/model.py b/src-python/model.py index ec23039d..f06db96d 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -357,6 +357,28 @@ class Model: # run updater Popen(program_name, cwd=current_directory) + @staticmethod + def updateCudaSoftware(): + # try to update at most 5 times + for _ in range(5): + try: + program_name = "update.exe" + current_directory = config.PATH_LOCAL + res = requests_get(config.UPDATER_URL) + assets = res.json()['assets'] + url = [i["browser_download_url"] for i in assets if i["name"] == program_name][0] + res = requests_get(url, stream=True) + with open(os_path.join(current_directory, program_name), 'wb') as file: + for chunk in res.iter_content(chunk_size=1024*5): + file.write(chunk) + break + except Exception: + import traceback + with open('error.log', 'a') as f: + traceback.print_exc(file=f) + # run updater + Popen([program_name, "--cuda"], cwd=current_directory) + def getListMicHost(self): result = [host for host in device_manager.getMicDevices().keys()] return result diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index c35c5743..3022f78e 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -1416,6 +1416,12 @@ class Controller: th_start_update_software.start() return {"status":200, "result":True} + def updateCudaSoftware(self, *args, **kwargs) -> dict: + th_start_update_cuda_software = Thread(target=model.updateCudaSoftware) + th_start_update_cuda_software.daemon = True + th_start_update_cuda_software.start() + return {"status":200, "result":True} + def downloadCtranslate2Weight(self, data:str, *args, **kwargs) -> dict: weight_type = str(data) download_ctranslate2 = self.DownloadCTranslate2( diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index 75518655..45d4c284 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -92,6 +92,7 @@ mapping = { "/run/swap_your_language_and_target_language": {"status": True, "variable":controller.swapYourLanguageAndTargetLanguage}, "/run/update_software": {"status": True, "variable":controller.updateSoftware}, + "/run/update_cuda_software": {"status": True, "variable":controller.updateCudaSoftware}, # Config Window # Appearance