diff --git a/lollms/app.py b/lollms/app.py index 97ccc26..5cf8cef 100644 --- a/lollms/app.py +++ b/lollms/app.py @@ -233,6 +233,13 @@ class LollmsApplication(LoLLMsCom): except: self.warning(f"Couldn't load SD") + if self.config.enable_comfyui_service: + try: + from lollms.services.comfyui.lollms_comfyui import LollmsComfyUI + self.comfyui = LollmsComfyUI(self, auto_comfyui_base_url=self.config.comfyui_base_url) + except: + self.warning(f"Couldn't load SD") + if self.config.enable_motion_ctrl_service: try: from lollms.services.motion_ctrl.lollms_motion_ctrl import Service diff --git a/lollms/server/endpoints/lollms_comfyui.py b/lollms/server/endpoints/lollms_comfyui.py index 8093279..a3a7f75 100644 --- a/lollms/server/endpoints/lollms_comfyui.py +++ b/lollms/server/endpoints/lollms_comfyui.py @@ -37,14 +37,14 @@ def install_comfyui(): return {"status":False,"error":"Service installation is blocked when the server is exposed outside for very obvious reasons!"} lollmsElfServer.ShowBlockingMessage("Installing comfyui server\nPlease stand by") - from lollms.services.comfyui.lollms_comfyui import install_sd + from lollms.services.comfyui.lollms_comfyui import install_comfyui install_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 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_comfyui manually then try again") + 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/auto_comfyui manually then try again") return {"status":False, 'error':str(ex)} @router.get("/start_comfyui") diff --git a/lollms/server/endpoints/lollms_sd.py b/lollms/server/endpoints/lollms_sd.py index 5b4bcff..7fba796 100644 --- a/lollms/server/endpoints/lollms_sd.py +++ b/lollms/server/endpoints/lollms_sd.py @@ -67,8 +67,8 @@ def start_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("/show_comfyui") -def show_comfyui(): +@router.get("/show_sd") +def show_sd(): import webbrowser webbrowser.open(lollmsElfServer.config.sd_base_url) return {"status":True} \ No newline at end of file diff --git a/lollms/services/comfyui/lollms_comfyui.py b/lollms/services/comfyui/lollms_comfyui.py index f51743b..2135c21 100644 --- a/lollms/services/comfyui/lollms_comfyui.py +++ b/lollms/services/comfyui/lollms_comfyui.py @@ -28,7 +28,7 @@ from typing import List, Dict, Any from ascii_colors import ASCIIColors, trace_exception from lollms.paths import LollmsPaths -from lollms.utilities import git_pull, show_yes_no_dialog, run_script_in_env, create_conda_env +from lollms.utilities import git_pull, show_yes_no_dialog, run_script_in_env, create_conda_env, run_python_script_in_env import subprocess import shutil from tqdm import tqdm @@ -76,7 +76,14 @@ def install_comfyui(lollms_app:LollmsApplication): subprocess.run(["git", "clone", "https://github.com/ParisNeo/ComfyUI-Manager.git", str(comfyui_folder/"custom_nodes")]) if show_yes_no_dialog("warning!","Do you want to install a model from civitai?\nIsuggest dreamshaper xl."): download_file("https://civitai.com/api/download/models/351306", comfyui_folder/"models/checkpoints","dreamshaperXL_v21TurboDPMSDE.safetensors") - create_conda_env("comfyui","3.10") + create_conda_env("comfyui","3.10") + if lollms_app.config.hardware_mode in ["nvidia", "nvidia-tensorcores"]: + run_script_in_env("comfyui", "pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu121") + if lollms_app.config.hardware_mode in ["amd", "amd-noavx"]: + run_script_in_env("comfyui", "pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.7") + elif lollms_app.config.hardware_mode in ["cpu", "cpu-noavx"]: + run_script_in_env("comfyui", "pip install --pre torch torchvision torchaudio") + run_script_in_env("comfyui", f"pip install -r {comfyui_folder}/requirements.txt") lollms_app.comfyui = LollmsComfyUI(lollms_app) ASCIIColors.green("Comfyui installed successfully") @@ -151,13 +158,13 @@ class LollmsComfyUI: ASCIIColors.info("Loading lollms_comfyui") if platform.system() == "Windows": ASCIIColors.info("Running on windows") - script_path = self.comfyui_folder / "lollms_comfyui.bat" + script_path = self.comfyui_folder / "main.py" if share: - run_script_in_env("comfyui", str(script_path) +" --share", cwd=self.comfyui_folder) + run_python_script_in_env("comfyui", str(script_path), cwd=self.comfyui_folder) # subprocess.Popen("conda activate " + str(script_path) +" --share", cwd=self.comfyui_folder) else: - run_script_in_env("comfyui", str(script_path), cwd=self.comfyui_folder) + run_python_script_in_env("comfyui", str(script_path), cwd=self.comfyui_folder) # subprocess.Popen(script_path, cwd=self.comfyui_folder) else: ASCIIColors.info("Running on linux/MacOs") @@ -188,3 +195,27 @@ class LollmsComfyUI: self.set_auth(username, password) else: self.check_controlnet() + + def wait_for_service(self, max_retries = 50, show_warning=True): + url = f"{self.comfyui_base_url}" + # Adjust this value as needed + retries = 0 + + while retries < max_retries or max_retries<0: + try: + response = requests.get(url) + if response.status_code == 200: + print("Service is available.") + if self.app is not None: + self.app.success("Comfyui Service is now available.") + return True + except requests.exceptions.RequestException: + pass + + retries += 1 + time.sleep(1) + if show_warning: + print("Service did not become available within the given time.") + if self.app is not None: + self.app.error("Comfyui Service did not become available within the given time.") + return False \ No newline at end of file