improved/fixed start/install/update system

This commit is contained in:
Mathieu Broillet 2024-08-29 12:26:37 +02:00
parent 6687d59e84
commit 40ea9f1cce
Signed by: mathieu
GPG Key ID: A08E484FE95074C1
9 changed files with 37 additions and 38 deletions

View File

@ -39,10 +39,18 @@ class Stack:
self.pid = config.get(f"{self.name}-pid") self.pid = config.get(f"{self.name}-pid")
def install(self): def install(self):
self.check_for_broken_install()
self.create_venv()
self._install()
self.create_file('.installed', 'true') self.create_file('.installed', 'true')
logger.info(f"Installed {self.name}") logger.info(f"Installed {self.name}")
def _install(self):
pass
def is_installed(self): def is_installed(self):
return self.file_exists('.installed') return self.file_exists('.installed')
@ -57,26 +65,25 @@ class Stack:
self.create_dir('') self.create_dir('')
def update(self, folder: str = 'webui'): def update(self, folder: str = 'webui'):
if self.dir_exists(folder): if self.is_installed():
logger.info(f"Updating {self.name}") logger.info(f"Updating {self.name}")
self.git_pull(folder) self.git_pull(folder)
else: else:
logger.warning(f"Could not update {self.name} as {folder} does not exist") logger.warning(f"Could not update {self.name} as {self.name} is not installed")
choices.any_key.ask()
def uninstall(self): def uninstall(self):
logger.info(f"Uninstalling {self.name}")
self.bash(f"rm -rf {self.path}") self.bash(f"rm -rf {self.path}")
def start(self): def start(self):
if self.is_installed(): if self.is_installed():
self.update() self._start()
else: else:
self.check_for_broken_install() logger.error(f"{self.name} is not installed")
self.create_venv() choices.any_key.ask()
self.install()
self._launch() def _start(self):
def _launch(self):
pass pass
def stop(self): def stop(self):
@ -147,7 +154,7 @@ class Stack:
if choice is True: if choice is True:
self.stop() self.stop()
self._launch() self._start()
return return
else: else:
# TODO: attach to subprocess / redirect logs? # TODO: attach to subprocess / redirect logs?

View File

@ -10,7 +10,7 @@ class BackgroundRemovalDis(Stack):
'https://huggingface.co/spaces/ECCV2022/dis-background-removal' 'https://huggingface.co/spaces/ECCV2022/dis-background-removal'
) )
def install(self): def _install(self):
self.git_clone(url=self.url, dest="webui") self.git_clone(url=self.url, dest="webui")
self.install_requirements("webui/requirements.txt") self.install_requirements("webui/requirements.txt")
self.pip_install("gradio") # gradio is not in requirements.txt for some reason self.pip_install("gradio") # gradio is not in requirements.txt for some reason
@ -26,8 +26,6 @@ class BackgroundRemovalDis(Stack):
# self.remove_dir("webui/.git") # saves a lot of space due to big repo # self.remove_dir("webui/.git") # saves a lot of space due to big repo
super().install() def _start(self):
def _launch(self):
self.python(f"app.py", current_dir="webui", self.python(f"app.py", current_dir="webui",
env=["TORCH_BLAS_PREFER_HIPBLASLT=0", f"GRADIO_SERVER_PORT={self.port}"], daemon=True) env=["TORCH_BLAS_PREFER_HIPBLASLT=0", f"GRADIO_SERVER_PORT={self.port}"], daemon=True)

View File

@ -10,7 +10,7 @@ class ComfyUi(Stack):
'https://github.com/comfyanonymous/ComfyUI.git' 'https://github.com/comfyanonymous/ComfyUI.git'
) )
def install(self): def _install(self):
# Install the webui # Install the webui
self.git_clone(url=self.url, dest="webui") self.git_clone(url=self.url, dest="webui")
self.install_requirements("webui/requirements.txt") self.install_requirements("webui/requirements.txt")
@ -26,9 +26,7 @@ class ComfyUi(Stack):
self.git_clone(url="https://github.com/comfyanonymous/ComfyUI_bitsandbytes_NF4.git", self.git_clone(url="https://github.com/comfyanonymous/ComfyUI_bitsandbytes_NF4.git",
dest="webui/custom_nodes/ComfyUI_bitsandbytes_NF4") dest="webui/custom_nodes/ComfyUI_bitsandbytes_NF4")
super().install() def _start(self):
def _launch(self):
args = ["--port", str(self.port)] args = ["--port", str(self.port)]
self.python(f"main.py", args=args, current_dir="webui", self.python(f"main.py", args=args, current_dir="webui",
env=["TORCH_BLAS_PREFER_HIPBLASLT=0"], daemon=True) env=["TORCH_BLAS_PREFER_HIPBLASLT=0"], daemon=True)

View File

@ -10,7 +10,7 @@ class StableDiffusionForge(Stack):
'https://github.com/lllyasviel/stable-diffusion-webui-forge' 'https://github.com/lllyasviel/stable-diffusion-webui-forge'
) )
def install(self): def _install(self):
# Install the webui # Install the webui
self.git_clone(url=self.url, dest="webui") self.git_clone(url=self.url, dest="webui")
@ -19,9 +19,7 @@ class StableDiffusionForge(Stack):
# Add NF4 support for Flux # Add NF4 support for Flux
self.install_from_prebuilt("bitsandbytes") self.install_from_prebuilt("bitsandbytes")
super().install() def _start(self):
def _launch(self):
args = ["--listen", "--enable-insecure-extension-access", "--port", str(self.port)] args = ["--listen", "--enable-insecure-extension-access", "--port", str(self.port)]
self.python(f"launch.py", args=args, current_dir="webui", self.python(f"launch.py", args=args, current_dir="webui",
env=["TORCH_BLAS_PREFER_HIPBLASLT=0"], daemon=True) env=["TORCH_BLAS_PREFER_HIPBLASLT=0"], daemon=True)

View File

@ -10,7 +10,7 @@ class StableDiffusionWebui(Stack):
'https://github.com/AUTOMATIC1111/stable-diffusion-webui' 'https://github.com/AUTOMATIC1111/stable-diffusion-webui'
) )
def install(self): def _install(self):
# Install the webui # Install the webui
self.git_clone(url=self.url, branch="dev", dest="webui") self.git_clone(url=self.url, branch="dev", dest="webui")
@ -19,9 +19,7 @@ class StableDiffusionWebui(Stack):
# Add NF4 support for Flux # Add NF4 support for Flux
self.install_from_prebuilt("bitsandbytes") self.install_from_prebuilt("bitsandbytes")
super().install() def _start(self):
def _launch(self):
args = ["--listen", "--enable-insecure-extension-access", "--port", str(self.port)] args = ["--listen", "--enable-insecure-extension-access", "--port", str(self.port)]
self.python(f"launch.py", args=args, current_dir="webui", self.python(f"launch.py", args=args, current_dir="webui",
env=["TORCH_BLAS_PREFER_HIPBLASLT=0"], daemon=True) env=["TORCH_BLAS_PREFER_HIPBLASLT=0"], daemon=True)

View File

@ -10,7 +10,7 @@ class TextGenerationWebui(Stack):
'https://github.com/oobabooga/text-generation-webui/' 'https://github.com/oobabooga/text-generation-webui/'
) )
def install(self): def _install(self):
# Install LlamaCpp from prebuilt # Install LlamaCpp from prebuilt
self.pip_install("llama-cpp-python", env=["CMAKE_ARGS=\"-DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS\""]) # cpu self.pip_install("llama-cpp-python", env=["CMAKE_ARGS=\"-DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS\""]) # cpu
@ -48,9 +48,7 @@ class TextGenerationWebui(Stack):
self.pip_install("auto-gptq", args=["--no-build-isolation", "--extra-index-url", self.pip_install("auto-gptq", args=["--no-build-isolation", "--extra-index-url",
"https://huggingface.github.io/autogptq-index/whl/rocm573/"]) "https://huggingface.github.io/autogptq-index/whl/rocm573/"])
super().install() def _start(self):
def _launch(self):
args = ["--listen", "--listen-port", str(self.port)] args = ["--listen", "--listen-port", str(self.port)]
self.python(f"server.py", args=args, current_dir="webui", self.python(f"server.py", args=args, current_dir="webui",
env=["TORCH_BLAS_PREFER_HIPBLASLT=0"], daemon=True) env=["TORCH_BLAS_PREFER_HIPBLASLT=0"], daemon=True)

View File

@ -10,7 +10,7 @@ class XttsWebui(Stack):
'https://github.com/daswer123/xtts-webui' 'https://github.com/daswer123/xtts-webui'
) )
def install(self): def _install(self):
# Install the webui # Install the webui
self.git_clone(url=self.url, dest="webui") self.git_clone(url=self.url, dest="webui")
@ -30,9 +30,7 @@ class XttsWebui(Stack):
# Deepspeed and ninja (not working yet) # Deepspeed and ninja (not working yet)
# self.pip_install(["ninja", "deepspeed"]) # self.pip_install(["ninja", "deepspeed"])
super().install() def _start(self):
def _launch(self):
args = ["--host", "0.0.0.0", "--port", str(self.port)] args = ["--host", "0.0.0.0", "--port", str(self.port)]
self.python(f"server.py", current_dir="webui", self.python(f"server.py", current_dir="webui",
env=["TORCH_BLAS_PREFER_HIPBLASLT=0"], args=args, daemon=True) env=["TORCH_BLAS_PREFER_HIPBLASLT=0"], args=args, daemon=True)

View File

@ -26,7 +26,9 @@ def update_choices():
Choice("exit") Choice("exit")
]) ])
_services_choices = [Choice(service.name, value=service.id) for service in loaded_services.values()] _services_choices = [Choice(f"{service.name} [{'ON' if service.status() else 'OFF'}]", value=service.id) for service
in loaded_services.values()]
_services_choices.append(Choice("go back", value="back")) _services_choices.append(Choice("go back", value="back"))
start_service = questionary.select( start_service = questionary.select(

View File

@ -4,6 +4,7 @@ import questionary
from core.vars import logger, loaded_services from core.vars import logger, loaded_services
from ui import choices from ui import choices
from ui.choices import update_choices
def clear_terminal(): def clear_terminal():
@ -23,11 +24,11 @@ def handle_services(action, service):
elif action == "stop": elif action == "stop":
logger.info(f"Stopping service: {service.name}") logger.info(f"Stopping service: {service.name}")
service.stop() service.stop()
elif action == "update": elif action == "install":
confirmation = choices.are_you_sure.ask() confirmation = choices.are_you_sure.ask()
if confirmation: if confirmation:
logger.info(f"Installing/updating service: {service.name}") logger.info(f"Installing/updating service: {service.name}")
service.update() service.install()
elif action == "uninstall": elif action == "uninstall":
confirmation = choices.are_you_sure.ask() confirmation = choices.are_you_sure.ask()
if confirmation: if confirmation:
@ -42,6 +43,7 @@ def handle_services(action, service):
def run_interactive_cmd_ui(): def run_interactive_cmd_ui():
while True: while True:
clear_terminal() clear_terminal()
update_choices()
choice = choices.start.ask() choice = choices.start.ask()
if choice == "Start service": if choice == "Start service":
@ -54,7 +56,7 @@ def run_interactive_cmd_ui():
elif choice == "Install/update service": elif choice == "Install/update service":
service = choices.install_service.ask() service = choices.install_service.ask()
handle_services("update", service) handle_services("install", service)
elif choice == "Uninstall service": elif choice == "Uninstall service":
service = choices.uninstall_service.ask() service = choices.uninstall_service.ask()