File size: 4,444 Bytes
4bddb8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python3
"""
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:
    # 1. Sistema: .NET, aria2, ffmpeg
    _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")

    # 2. Descargar on_start.sh
    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)

    # 3. Clonar SwarmUI y descargas auxiliares
    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)

    # 4. Preparar directorios y clonar ComfyUI
    _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")

    # 5. Dependencias de ComfyUI
    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")

    # 6. SageAttention
    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}")

    # 7. Custom nodes de ComfyUI
    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")

    # 8. Instalar requirements de cada nodo
    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")

    # 9. Limpieza y enlaces simbólicos
    _run("rm -rf /teamspace/studios/this_studio/.cache")
    (SWARM_DIR / "Models").mkdir(parents=True, exist_ok=True)
    
    os.chdir(BASE_DIR)
    # Ejecutar symb.py si existe
    symb_path = BASE_DIR / "symb.py"
    if symb_path.exists():
        _run(f"python {symb_path}")

    # Mensaje final
    os.system("clear" if os.name != "nt" else "cls")
    print("\n" + "=" * 50)
    print("🎉 Instalación completada")
    print("=" * 50)

if __name__ == "__main__":
    main()