From 45d9f98e987e74aede53520f0975bedbee164046 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Thu, 21 Mar 2024 22:18:53 +0100 Subject: [PATCH] Added upgrade comfyui --- lollms/server/endpoints/lollms_comfyui.py | 24 ++++++++++++++++++ lollms/server/endpoints/lollms_sd.py | 24 ++++++++++++++++++ lollms/services/comfyui/lollms_comfyui.py | 22 ++++++++++++++-- lollms/services/sd/lollms_sd.py | 31 +++++++++++++++++++++++ 4 files changed, 99 insertions(+), 2 deletions(-) diff --git a/lollms/server/endpoints/lollms_comfyui.py b/lollms/server/endpoints/lollms_comfyui.py index beb0b8e..434db63 100644 --- a/lollms/server/endpoints/lollms_comfyui.py +++ b/lollms/server/endpoints/lollms_comfyui.py @@ -47,6 +47,30 @@ def install_comfyui(): lollmsElfServer.InfoMessage(f"It looks like I could not install Comfyui because of this error:\n{ex}\nThis is commonly caused by a previous version that I couldn't delete. PLease remove {lollmsElfServer.lollms_paths.personal_path}/shared/comfyui manually then try again") return {"status":False, 'error':str(ex)} +@router.get("/upgrade_comfyui") +def upgrade_comfyui(): + try: + if lollmsElfServer.config.headless_server_mode: + return {"status":False,"error":"Service upgrade is blocked when in headless mode for obvious security reasons!"} + + if lollmsElfServer.config.host!="localhost" and lollmsElfServer.config.host!="127.0.0.1": + return {"status":False,"error":"Service upgrade is blocked when the server is exposed outside for very obvious reasons!"} + + lollmsElfServer.ShowBlockingMessage("Upgrading comfyui server\nPlease stand by") + from lollms.services.comfyui.lollms_comfyui import upgrade_comfyui + upgrade_comfyui(lollmsElfServer) + ASCIIColors.success("Done") + lollmsElfServer.HideBlockingMessage() + return {"status":True} + + + except Exception as ex: + lollmsElfServer.HideBlockingMessage() + lollmsElfServer.InfoMessage(f"It looks like I could not install Comfyui because of this error:\n{ex}\nThis is commonly caused by a previous version that I couldn't delete. PLease remove {lollmsElfServer.lollms_paths.personal_path}/shared/comfyui manually then try again") + return {"status":False, 'error':str(ex)} + + + @router.get("/start_comfyui") def start_comfyui(): try: diff --git a/lollms/server/endpoints/lollms_sd.py b/lollms/server/endpoints/lollms_sd.py index 7fba796..32af892 100644 --- a/lollms/server/endpoints/lollms_sd.py +++ b/lollms/server/endpoints/lollms_sd.py @@ -47,6 +47,30 @@ def install_sd(): lollmsElfServer.InfoMessage(f"It looks like I could not install SD because of this error:\n{ex}\nThis is commonly caused by a previous version that I couldn't delete. PLease remove {lollmsElfServer.lollms_paths.personal_path}/shared/auto_sd manually then try again") return {"status":False, 'error':str(ex)} + +@router.get("/upgrade_sd") +def upgrade_sd(): + try: + if lollmsElfServer.config.headless_server_mode: + return {"status":False,"error":"Service installation is blocked when in headless mode for obvious security reasons!"} + + if lollmsElfServer.config.host!="localhost" and lollmsElfServer.config.host!="127.0.0.1": + return {"status":False,"error":"Service installation is blocked when the server is exposed outside for very obvious reasons!"} + + lollmsElfServer.ShowBlockingMessage("Installing SD api server\nPlease stand by") + from lollms.services.sd.lollms_sd import upgrade_sd + upgrade_sd(lollmsElfServer) + ASCIIColors.success("Done") + lollmsElfServer.HideBlockingMessage() + return {"status":True} + except Exception as ex: + lollmsElfServer.HideBlockingMessage() + lollmsElfServer.InfoMessage(f"It looks like I could not install SD because of this error:\n{ex}\nThis is commonly caused by a previous version that I couldn't delete. PLease remove {lollmsElfServer.lollms_paths.personal_path}/shared/auto_sd manually then try again") + return {"status":False, 'error':str(ex)} + + + + @router.get("/start_sd") def start_sd(): try: diff --git a/lollms/services/comfyui/lollms_comfyui.py b/lollms/services/comfyui/lollms_comfyui.py index b38a6c2..d0932bc 100644 --- a/lollms/services/comfyui/lollms_comfyui.py +++ b/lollms/services/comfyui/lollms_comfyui.py @@ -74,9 +74,14 @@ def install_comfyui(lollms_app:LollmsApplication): subprocess.run(["git", "clone", "https://github.com/ParisNeo/ComfyUI.git", str(comfyui_folder)]) subprocess.run(["git", "clone", "https://github.com/ParisNeo/ComfyUI-Manager.git", str(comfyui_folder/"custom_nodes/ComfyUI-Manager")]) - subprocess.run(["git", "clone", "https://github.com/jags111/efficiency-nodes-comfyui.git", str(comfyui_folder/"custom_nodes/efficiency-nodes-comfyui")]) - if show_yes_no_dialog("warning!","Do you want to install a model from civitai?\nIsuggest Juggernaut XL."): + subprocess.run(["git", "clone", "https://github.com/jags111/efficiency-nodes-comfyui.git", str(comfyui_folder/"custom_nodes/efficiency-nodes-comfyui")]) + + if show_yes_no_dialog("warning!","Do you want to install an image model from civitai?\nIsuggest Juggernaut XL."): download_file("https://civitai.com/api/download/models/357609", comfyui_folder/"models/checkpoints","Juggernaut_XL.safetensors") + + if show_yes_no_dialog("warning!","Do you want to install a video model from hugging face?\nIsuggest SVD XL."): + download_file("https://huggingface.co/stabilityai/stable-video-diffusion-img2vid-xt/blob/main/svd_xt.safetensors", comfyui_folder/"models/checkpoints","svd_xt.safetensors") + create_conda_env("comfyui","3.10") if lollms_app.config.hardware_mode in ["nvidia", "nvidia-tensorcores"]: run_python_script_in_env("comfyui", "-m pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu121") @@ -90,6 +95,19 @@ def install_comfyui(lollms_app:LollmsApplication): ASCIIColors.green("Comfyui installed successfully") lollms_app.HideBlockingMessage() +def upgrade_comfyui(lollms_app:LollmsApplication): + root_dir = lollms_app.lollms_paths.personal_path + shared_folder = root_dir/"shared" + comfyui_folder = shared_folder / "comfyui" + if not comfyui_folder.exists(): + lollms_app.InfoMessage("Comfyui is not installed, install it first") + return + + subprocess.run(["git", "pull", str(comfyui_folder)]) + subprocess.run(["git", "pull", str(comfyui_folder/"custom_nodes/ComfyUI-Manager")]) + subprocess.run(["git", "pull", str(comfyui_folder/"custom_nodes/efficiency-nodes-comfyui")]) + ASCIIColors.success("DONE") + def get_comfyui(lollms_paths:LollmsPaths): root_dir = lollms_paths.personal_path diff --git a/lollms/services/sd/lollms_sd.py b/lollms/services/sd/lollms_sd.py index ebacf4a..d31ab2b 100644 --- a/lollms/services/sd/lollms_sd.py +++ b/lollms/services/sd/lollms_sd.py @@ -80,6 +80,37 @@ def install_sd(lollms_app:LollmsApplication): ASCIIColors.green("Stable diffusion installed successfully") +def upgrade_sd(lollms_app:LollmsApplication): + root_dir = lollms_app.lollms_paths.personal_path + shared_folder = root_dir/"shared" + sd_folder = shared_folder / "auto_sd" + if sd_folder.exists(): + if show_yes_no_dialog("warning!","I have detected that there is a previous installation of stable diffusion.\nShould I remove it and continue installing?"): + shutil.rmtree(sd_folder) + elif not show_yes_no_dialog("warning!","Continue installation?"): + return + + ASCIIColors.cyan("Installing autosd conda environment with python 3.10") + create_conda_env("autosd","3.10") + ASCIIColors.cyan("Done") + + subprocess.run(["git", "clone", "https://github.com/ParisNeo/stable-diffusion-webui.git", str(sd_folder)]) + subprocess.run(["git", "clone", "https://github.com/ParisNeo/SD-CN-Animation.git", str(sd_folder/"extensions/SD-CN-Animation")]) + + +def upgrade_sd(lollms_app:LollmsApplication): + root_dir = lollms_app.lollms_paths.personal_path + shared_folder = root_dir/"shared" + sd_folder = shared_folder / "auto_sd" + if not sd_folder.exists(): + lollms_app.InfoMessage("Comfyui is not installed, install it first") + return + + subprocess.run(["git", "pull", str(sd_folder)]) + subprocess.run(["git", "pull", str(sd_folder/"extensions/SD-CN-Animation")]) + ASCIIColors.success("DONE") + + def get_sd(lollms_paths:LollmsPaths): root_dir = lollms_paths.personal_path shared_folder = root_dir/"shared"