From e4849a50ce3598e92e226e6cbb7a10c973867c40 Mon Sep 17 00:00:00 2001 From: huchenlei Date: Sun, 28 May 2023 23:14:43 -0400 Subject: [PATCH] :wrench: Add cmd arg to disable autoupdate --- preload.py | 7 +++++++ scripts/openpose_editor.py | 19 +++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 preload.py diff --git a/preload.py b/preload.py new file mode 100644 index 0000000..5035e5e --- /dev/null +++ b/preload.py @@ -0,0 +1,7 @@ +def preload(parser): + parser.add_argument( + "--disable-openpose-editor-auto-update", + action='store_true', + help="Disable auto-update of openpose editor", + default=None, + ) diff --git a/scripts/openpose_editor.py b/scripts/openpose_editor.py index 90aa970..bc78ab7 100644 --- a/scripts/openpose_editor.py +++ b/scripts/openpose_editor.py @@ -10,6 +10,7 @@ from pydantic import BaseModel from typing import Optional import modules.script_callbacks as script_callbacks +from modules import shared class Item(BaseModel): @@ -55,21 +56,17 @@ def download_latest_release(owner, repo): filename = "dist.zip" with open(filename, "wb") as file: file.write(response.content) - print("Download successful.") - - if os.path.exists(DIST_DIR): - os.unlink(DIST_DIR) - + # Unzip the file with zipfile.ZipFile(filename, "r") as zip_ref: - zip_ref.extractall(DIST_DIR) + zip_ref.extractall(EXTENSION_DIR) # Remove the zip file os.remove(filename) else: - print("Failed to download the file.") + print(f"Failed to download the file {url}.") else: - print("Could not get the latest release or there are no assets.") + print(f"Could not get the latest release or there are no assets {url}.") def update_app(): @@ -85,8 +82,10 @@ def update_app(): download_latest_release(owner, repo) -def mount_openpose_api(_: gr.Blocks, app: FastAPI): - update_app() +def mount_openpose_api(_: gr.Blocks, app: FastAPI): + if not shared.cmd_opts.disable_openpose_editor_auto_update: + update_app() + templates = Jinja2Templates(directory=DIST_DIR) app.mount( "/openpose_editor",