Mightys commited on
Commit
4bddb8b
·
verified ·
1 Parent(s): c3cacc3

Upload install_swarmui_lightning.py

Browse files
Swarmui_Lightning/install_swarmui_lightning.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ install_swarmui_lightning.py
4
+ Instala SwarmUI en Lightning.ai con ComfyUI backend, extensiones y dependencias.
5
+ """
6
+
7
+ import os
8
+ import subprocess
9
+ from pathlib import Path
10
+
11
+ BASE_DIR = Path("/teamspace/studios/this_studio").resolve()
12
+ SWARM_DIR = BASE_DIR / "SwarmUI"
13
+ COMFY_DIR = SWARM_DIR / "dlbackend" / "ComfyUI"
14
+ NODES_DIR = COMFY_DIR / "custom_nodes"
15
+
16
+ def _run(cmd: str, cwd: Path | None = None) -> None:
17
+ """Ejecuta un comando shell."""
18
+ print(f"+ {cmd}")
19
+ subprocess.run(cmd, shell=True, check=False, cwd=cwd)
20
+
21
+ def wget(url: str, output: str | None = None, quiet: bool = False) -> None:
22
+ """Descarga con wget."""
23
+ cmd = "wget"
24
+ if quiet:
25
+ cmd += " -q"
26
+ if output:
27
+ cmd += f" -O {output}"
28
+ cmd += f" {url}"
29
+ _run(cmd)
30
+
31
+ def clone(repo: str, cwd: Path | None = None) -> None:
32
+ """Clona un repositorio git."""
33
+ _run(f"git clone {repo}", cwd=cwd)
34
+
35
+ def main() -> None:
36
+ # 1. Sistema: .NET, aria2, ffmpeg
37
+ _run("sudo apt-get update")
38
+ _run("sudo apt-get install -y dotnet-sdk-8.0")
39
+ _run("sudo apt install aria2 -q")
40
+ _run("sudo apt install ffmpeg -y")
41
+
42
+ # 2. Descargar on_start.sh
43
+ lightning_dir = BASE_DIR / ".lightning_studio"
44
+ lightning_dir.mkdir(parents=True, exist_ok=True)
45
+ on_start = lightning_dir / "on_start.sh"
46
+ if on_start.exists():
47
+ on_start.unlink()
48
+ wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Swarmui_Lightning/on_start.sh",
49
+ output=str(on_start))
50
+
51
+ os.chdir(BASE_DIR)
52
+
53
+ # 3. Clonar SwarmUI y descargas auxiliares
54
+ if not SWARM_DIR.exists():
55
+ clone("https://github.com/mcmonkeyprojects/SwarmUI")
56
+
57
+ wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Swarmui_Lightning/gestor_swarm.py",
58
+ quiet=True)
59
+ wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/scripts/download_magic.py",
60
+ quiet=True)
61
+ wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/libmimalloc.so.2.1",
62
+ quiet=True)
63
+ wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Swarmui_Lightning/symb.py",
64
+ quiet=True)
65
+
66
+ # 4. Preparar directorios y clonar ComfyUI
67
+ _run("sudo apt install git python3-pip -y")
68
+ (SWARM_DIR / "dlbackend").mkdir(parents=True, exist_ok=True)
69
+
70
+ os.chdir(SWARM_DIR / "dlbackend")
71
+ if not COMFY_DIR.exists():
72
+ clone("https://github.com/comfyanonymous/ComfyUI.git")
73
+
74
+ # 5. Dependencias de ComfyUI
75
+ os.chdir(COMFY_DIR)
76
+ _run("uv pip install torch==2.9.1 torchvision==0.24.1 xformers==0.0.33.post2 triton==3.5.1 "
77
+ "--index-url https://download.pytorch.org/whl/cu128 --no-progress")
78
+ _run("uv pip install rembg ultralytics==8.3.216 onnxruntime gdown pickleshare insightface clip numpy==2.3.0 "
79
+ "--no-progress")
80
+ _run("uv pip install -r requirements.txt --no-progress")
81
+
82
+ # 6. SageAttention
83
+ wheel = "sageattention-2.1.2-cp312-cp312-linux_x86_64.whl"
84
+ wget("https://huggingface.co/datasets/WhiteAiZ/T4_SageAttention2_For_Google_Colab/resolve/main/python%203.12/" + wheel)
85
+ _run(f"uv pip install {wheel}")
86
+
87
+ # 7. Custom nodes de ComfyUI
88
+ NODES_DIR.mkdir(parents=True, exist_ok=True)
89
+ os.chdir(NODES_DIR)
90
+
91
+ clone("https://github.com/Comfy-Org/ComfyUI-Manager.git")
92
+ clone("https://github.com/crystian/ComfyUI-Crystools.git")
93
+ clone("https://github.com/city96/ComfyUI-GGUF.git")
94
+ clone("https://github.com/rgthree/rgthree-comfy.git")
95
+
96
+ # 8. Instalar requirements de cada nodo
97
+ nodes_reqs = [
98
+ "ComfyUI-Manager",
99
+ "ComfyUI-Crystools",
100
+ "ComfyUI-GGUF",
101
+ "rgthree-comfy",
102
+ ]
103
+
104
+ for node in nodes_reqs:
105
+ node_path = NODES_DIR / node
106
+ if (node_path / "requirements.txt").exists():
107
+ os.chdir(node_path)
108
+ _run("uv pip install -r requirements.txt --no-progress")
109
+
110
+ # 9. Limpieza y enlaces simbólicos
111
+ _run("rm -rf /teamspace/studios/this_studio/.cache")
112
+ (SWARM_DIR / "Models").mkdir(parents=True, exist_ok=True)
113
+
114
+ os.chdir(BASE_DIR)
115
+ # Ejecutar symb.py si existe
116
+ symb_path = BASE_DIR / "symb.py"
117
+ if symb_path.exists():
118
+ _run(f"python {symb_path}")
119
+
120
+ # Mensaje final
121
+ os.system("clear" if os.name != "nt" else "cls")
122
+ print("\n" + "=" * 50)
123
+ print("🎉 Instalación completada")
124
+ print("=" * 50)
125
+
126
+ if __name__ == "__main__":
127
+ main()