| |
| """ |
| install_swarmui_lightning.py |
| Instala SwarmUI en Lightning.ai con ComfyUI backend, extensiones y dependencias. |
| """ |
|
|
| import os |
| import subprocess |
| from pathlib import Path |
|
|
| BASE_DIR = Path("/teamspace/studios/this_studio").resolve() |
| SWARM_DIR = BASE_DIR / "SwarmUI" |
| COMFY_DIR = SWARM_DIR / "dlbackend" / "ComfyUI" |
| NODES_DIR = COMFY_DIR / "custom_nodes" |
|
|
| def _run(cmd: str, cwd: Path | None = None) -> None: |
| """Ejecuta un comando shell.""" |
| print(f"+ {cmd}") |
| subprocess.run(cmd, shell=True, check=False, cwd=cwd) |
|
|
| def wget(url: str, output: str | None = None, quiet: bool = False) -> None: |
| """Descarga con wget.""" |
| cmd = "wget" |
| if quiet: |
| cmd += " -q" |
| if output: |
| cmd += f" -O {output}" |
| cmd += f" {url}" |
| _run(cmd) |
|
|
| def clone(repo: str, cwd: Path | None = None) -> None: |
| """Clona un repositorio git.""" |
| _run(f"git clone {repo}", cwd=cwd) |
|
|
| def main() -> None: |
| |
| _run("sudo apt-get update") |
| _run("sudo apt-get install -y dotnet-sdk-8.0") |
| _run("sudo apt install aria2 -q") |
| _run("sudo apt install ffmpeg -y") |
|
|
| |
| lightning_dir = BASE_DIR / ".lightning_studio" |
| lightning_dir.mkdir(parents=True, exist_ok=True) |
| on_start = lightning_dir / "on_start.sh" |
| if on_start.exists(): |
| on_start.unlink() |
| wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Swarmui_Lightning/on_start.sh", |
| output=str(on_start)) |
|
|
| os.chdir(BASE_DIR) |
|
|
| |
| if not SWARM_DIR.exists(): |
| clone("https://github.com/mcmonkeyprojects/SwarmUI") |
|
|
| wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Swarmui_Lightning/gestor_swarm.py", |
| quiet=True) |
| wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/scripts/download_magic.py", |
| quiet=True) |
| wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/libmimalloc.so.2.1", |
| quiet=True) |
| wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Swarmui_Lightning/symb.py", |
| quiet=True) |
|
|
| |
| _run("sudo apt install git python3-pip -y") |
| (SWARM_DIR / "dlbackend").mkdir(parents=True, exist_ok=True) |
| |
| os.chdir(SWARM_DIR / "dlbackend") |
| if not COMFY_DIR.exists(): |
| clone("https://github.com/comfyanonymous/ComfyUI.git") |
|
|
| |
| os.chdir(COMFY_DIR) |
| _run("uv pip install torch==2.9.1 torchvision==0.24.1 xformers==0.0.33.post2 triton==3.5.1 " |
| "--index-url https://download.pytorch.org/whl/cu128 --no-progress") |
| _run("uv pip install rembg ultralytics==8.3.216 onnxruntime gdown pickleshare insightface clip numpy==2.3.0 " |
| "--no-progress") |
| _run("uv pip install -r requirements.txt --no-progress") |
|
|
| |
| wheel = "sageattention-2.1.2-cp312-cp312-linux_x86_64.whl" |
| wget("https://huggingface.co/datasets/WhiteAiZ/T4_SageAttention2_For_Google_Colab/resolve/main/python%203.12/" + wheel) |
| _run(f"uv pip install {wheel}") |
|
|
| |
| NODES_DIR.mkdir(parents=True, exist_ok=True) |
| os.chdir(NODES_DIR) |
| |
| clone("https://github.com/Comfy-Org/ComfyUI-Manager.git") |
| clone("https://github.com/crystian/ComfyUI-Crystools.git") |
| clone("https://github.com/city96/ComfyUI-GGUF.git") |
| clone("https://github.com/rgthree/rgthree-comfy.git") |
|
|
| |
| nodes_reqs = [ |
| "ComfyUI-Manager", |
| "ComfyUI-Crystools", |
| "ComfyUI-GGUF", |
| "rgthree-comfy", |
| ] |
| |
| for node in nodes_reqs: |
| node_path = NODES_DIR / node |
| if (node_path / "requirements.txt").exists(): |
| os.chdir(node_path) |
| _run("uv pip install -r requirements.txt --no-progress") |
|
|
| |
| _run("rm -rf /teamspace/studios/this_studio/.cache") |
| (SWARM_DIR / "Models").mkdir(parents=True, exist_ok=True) |
| |
| os.chdir(BASE_DIR) |
| |
| symb_path = BASE_DIR / "symb.py" |
| if symb_path.exists(): |
| _run(f"python {symb_path}") |
|
|
| |
| os.system("clear" if os.name != "nt" else "cls") |
| print("\n" + "=" * 50) |
| print("馃帀 Instalaci贸n completada") |
| print("=" * 50) |
|
|
| if __name__ == "__main__": |
| main() |