From 1717645ae14be8f8247976a0092c85d1fc4e8da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 23 Apr 2024 17:06:25 +0900 Subject: [PATCH] optimize: error handling & update logics --- gui_v1.py | 2 +- infer-web.py | 25 ++++++++++++++----------- infer/lib/rvcmd.py | 10 ++++++++-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/gui_v1.py b/gui_v1.py index 8f910d9..45a5891 100644 --- a/gui_v1.py +++ b/gui_v1.py @@ -159,7 +159,7 @@ if __name__ == "__main__": if not check_all_assets(update=self.config.update): if self.config.update: download_all_assets(tmpdir=tmp) - if not check_all_assets(update=False): + if not check_all_assets(update=self.config.update): printt("counld not satisfy all assets needed.") exit(1) diff --git a/infer-web.py b/infer-web.py index bdf3357..306c448 100644 --- a/infer-web.py +++ b/infer-web.py @@ -60,7 +60,7 @@ if not config.nocheck: if not check_all_assets(update=config.update): if config.update: download_all_assets(tmpdir=tmp) - if not check_all_assets(update=False): + if not check_all_assets(update=config.update): logging.error("counld not satisfy all assets needed.") exit(1) @@ -1608,13 +1608,16 @@ with gr.Blocks(title="RVC WebUI") as app: except: gr.Markdown(traceback.format_exc()) - if config.iscolab: - app.queue(max_size=1022).launch(share=True, max_threads=511) - else: - app.queue(max_size=1022).launch( - max_threads=511, - server_name="0.0.0.0", - inbrowser=not config.noautoopen, - server_port=config.listen_port, - quiet=True, - ) + try: + if config.iscolab: + app.queue(max_size=1022).launch(share=True, max_threads=511) + else: + app.queue(max_size=1022).launch( + max_threads=511, + server_name="0.0.0.0", + inbrowser=not config.noautoopen, + server_port=config.listen_port, + quiet=True, + ) + except Exception as e: + logger.error(str(e)) diff --git a/infer/lib/rvcmd.py b/infer/lib/rvcmd.py index d1e357b..167853f 100644 --- a/infer/lib/rvcmd.py +++ b/infer/lib/rvcmd.py @@ -28,13 +28,19 @@ def check_model( return False with open(target, "rb") as f: digest = sha256(f) + bakfile = f"{target}.bak" if digest != hash: - logger.info(f"{target} sha256 hash mismatch.") + logger.warn(f"{target} sha256 hash mismatch.") logger.info(f"expected: {hash}") logger.info(f"real val: {digest}") + logger.warn("please add parameter --update to download the latest assets.") if remove_incorrect: - os.remove(str(target)) + if not os.path.exists(bakfile): + os.rename(str(target), bakfile) + else: os.remove(str(target)) return False + if remove_incorrect and os.path.exists(bakfile): + os.remove(bakfile) return True