Mightys commited on
Commit
0404a36
·
verified ·
1 Parent(s): 0759e69

Update Swarmui_Kaggle/install_swarmui.py

Browse files
Files changed (1) hide show
  1. Swarmui_Kaggle/install_swarmui.py +174 -173
Swarmui_Kaggle/install_swarmui.py CHANGED
@@ -1,174 +1,175 @@
1
- #!/usr/bin/env python3
2
- """
3
- install_swarmui.py
4
- Instala SwarmUI en Kaggle con ComfyUI backend, extensiones, modelos y configuraciones.
5
- """
6
-
7
- import os
8
- import subprocess
9
- from pathlib import Path
10
-
11
- WORK_DIR = Path("/kaggle/working").resolve()
12
- SWARM_DIR = WORK_DIR / "SwarmUI"
13
- COMFY_DIR = SWARM_DIR / "dlbackend" / "ComfyUI"
14
-
15
- def _run(cmd: str, cwd: Path | None = None) -> None:
16
- """Ejecuta un comando shell."""
17
- print(f"+ {cmd}")
18
- subprocess.run(cmd, shell=True, check=False, cwd=cwd)
19
-
20
- def wget(url: str, output: str | None = None, quiet: bool = False, show_progress: bool = False) -> None:
21
- """Descarga con wget."""
22
- cmd = "wget"
23
- if quiet:
24
- cmd += " -q"
25
- if show_progress:
26
- cmd += " --show-progress"
27
- if output:
28
- cmd += f" -O {output}"
29
- cmd += f" {url}"
30
- _run(cmd)
31
-
32
- def aria2c(url: str, output: str, cwd: Path | None = None) -> None:
33
- """Descarga con aria2c."""
34
- cmd = (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M '
35
- f'"{url}" -o {output}')
36
- _run(cmd, cwd=cwd)
37
-
38
- def clone(repo: str, cwd: Path | None = None) -> None:
39
- """Clona un repositorio git."""
40
- _run(f"git clone {repo}", cwd=cwd)
41
-
42
- def main() -> None:
43
- os.chdir(WORK_DIR)
44
-
45
- # 1. Descargas iniciales y clonar SwarmUI
46
- wget("https://huggingface.co/datasets/Mightys/SwarmuiColab/resolve/main/scripts/download_magic.py")
47
-
48
- if not SWARM_DIR.exists():
49
- clone("https://github.com/mcmonkeyprojects/SwarmUI")
50
-
51
- (SWARM_DIR / "Models").mkdir(parents=True, exist_ok=True)
52
- (SWARM_DIR / "dlbackend").mkdir(parents=True, exist_ok=True)
53
-
54
- _run("pip install aria2 gdown")
55
-
56
- # 2. Configuración de SwarmUI (Data)
57
- data_dir = SWARM_DIR / "Data"
58
- data_dir.mkdir(parents=True, exist_ok=True)
59
- os.chdir(data_dir)
60
-
61
- wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Swarmui_Kaggle/Settings.fds",
62
- quiet=True, show_progress=True)
63
- wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Swarmui_Kaggle/Backends.fds",
64
- quiet=True, show_progress=True)
65
- wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Swarmui_Kaggle/Users.ldb",
66
- quiet=True, show_progress=True)
67
-
68
- # Autocompletions
69
- auto_dir = data_dir / "Autocompletions"
70
- auto_dir.mkdir(parents=True, exist_ok=True)
71
- os.chdir(auto_dir)
72
- wget("https://huggingface.co/datasets/Mightys/SwarmuiColab/resolve/main/Data/Autocompletions/danbooru_e621_merged.csv",
73
- quiet=True, show_progress=True)
74
-
75
- # 3. Instalar .NET
76
- os.chdir(WORK_DIR)
77
- wget("https://dot.net/v1/dotnet-install.sh", output="dotnet-install.sh")
78
- _run("chmod +x dotnet-install.sh")
79
- _run("./dotnet-install.sh --channel 8.0")
80
-
81
- # 4. Instalar Cloudflare tunnel
82
- wget("https://github.com/cloudflare/cloudflared/releases/download/2024.8.2/cloudflared-linux-amd64.deb",
83
- quiet=True, show_progress=True)
84
- _run("dpkg -i cloudflared-linux-amd64.deb")
85
-
86
- # 5. Clonar ComfyUI
87
- os.chdir(SWARM_DIR / "dlbackend")
88
- if not COMFY_DIR.exists():
89
- clone("https://github.com/comfyanonymous/ComfyUI.git")
90
- else:
91
- _run("git pull", cwd=COMFY_DIR)
92
-
93
- # 6. Dependencias de ComfyUI
94
- os.chdir(COMFY_DIR)
95
- _run("uv pip install -r requirements.txt --no-progress")
96
- _run("uv pip install torch==2.9.1 torchvision==0.24.1 torchaudio xformers==0.0.33.post2 triton==3.5.1 "
97
- "--index-url https://download.pytorch.org/whl/cu128 --no-progress")
98
- _run("uv pip install ultralytics==8.3.216 onnxruntime gdown pickleshare insightface clip rembg numpy==2.3.0 "
99
- "--no-progress")
100
-
101
- # 7. Extensiones de SwarmUI
102
- ext_dir = SWARM_DIR / "src" / "Extensions"
103
- ext_dir.mkdir(parents=True, exist_ok=True)
104
- os.chdir(ext_dir)
105
- clone("https://github.com/jtreminio/SwarmUI-PromptBuilderExtension.git")
106
- clone("https://github.com/yoinked-h/MaHiRon-SwarmUI.git")
107
-
108
- # 8. SageAttention
109
- os.chdir(WORK_DIR)
110
- wheel = "sageattention-2.1.2-cp312-cp312-linux_x86_64.whl"
111
- wget(f"https://huggingface.co/datasets/WhiteAiZ/T4_SageAttention2_For_Google_Colab/resolve/main/python%203.12/{wheel}")
112
- _run(f"uv pip install {wheel}")
113
-
114
- # 9. Wildcards
115
- wild_dir = SWARM_DIR / "Data" / "Wildcards"
116
- wild_dir.mkdir(parents=True, exist_ok=True)
117
- os.chdir(wild_dir)
118
- aria2c("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Wildcards/artist_tags_danbooru5000.txt",
119
- "5000-booru-artist.txt")
120
-
121
- # 10. Modelos YOLO (segmentación/adetailers)
122
- yolo_dir = SWARM_DIR / "Models" / "yolov8"
123
- yolo_dir.mkdir(parents=True, exist_ok=True)
124
- os.chdir(yolo_dir)
125
-
126
- yolo_models = [
127
- ("https://huggingface.co/Anzhc/Anzhcs_YOLOs/resolve/main/Anzhc%20Eyes%20-seg-hd.pt", "Anzhc_Eyes-seg-hd.pt"),
128
- ("https://huggingface.co/Anzhc/Anzhcs_YOLOs/resolve/main/Anzhc%20Face%20seg%20640%20v3%20y11n.pt", "Anzhc_Face_seg_v3_y11n.pt"),
129
- ("https://huggingface.co/Anzhc/Anzhcs_YOLOs/resolve/main/Anzhc%20Breasts%20Seg%20v1%201024n.pt", "Anzhc_Breasts_Seg_v1_1024n.pt"),
130
- ("https://huggingface.co/Anzhc/Anzhcs_YOLOs/resolve/main/Anzhc%20HeadHair%20seg%20y8n.pt", "Anzhc_HeadHair_seg_y8n.pt"),
131
- ("https://huggingface.co/Nudimmud/adetailers/resolve/main/assdetailer-seg.pt", "assdetailer.pt"),
132
- ("https://huggingface.co/Bingsu/adetailer/resolve/main/face_yolov8n.pt", "face_yolov8n.pt"),
133
- ("https://huggingface.co/Bingsu/adetailer/resolve/main/face_yolov8m.pt", "face_yolov8m.pt"),
134
- ("https://huggingface.co/Bingsu/adetailer/resolve/main/hand_yolov8n.pt", "hand_yolov8n.pt"),
135
- ("https://huggingface.co/Bingsu/adetailer/resolve/main/hand_yolov8m.pt", "hand_yolov8m.pt"),
136
- ]
137
-
138
- for url, out in yolo_models:
139
- aria2c(url, out)
140
-
141
- # 11. VAE
142
- vae_dir = SWARM_DIR / "Models" / "VAE"
143
- vae_dir.mkdir(parents=True, exist_ok=True)
144
- os.chdir(vae_dir)
145
- # Nota: %download es una magic de IPython, aquí usamos wget directamente
146
- wget("https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl_vae.safetensors",
147
- quiet=True, show_progress=True)
148
-
149
- # 12. Gradio tunnel
150
- gradio_script = SWARM_DIR / "gradio-tunnel.py"
151
- if not gradio_script.exists():
152
- wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/scripts/gradio-tunnel.py",
153
- output=str(gradio_script))
154
-
155
- # 13. Parche de memoria (libmimalloc)
156
- print("🛠️ Instalando parche de memoria (libmimalloc.so.2.1)...")
157
- mimalloc_path = WORK_DIR / "libmimalloc.so.2.1"
158
- if not mimalloc_path.exists():
159
- wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/libmimalloc.so.2.1",
160
- output=str(mimalloc_path))
161
- print("✅ Parche descargado.")
162
- else:
163
- print("✅ Parche listo.")
164
-
165
- _run("pip install -q requests")
166
-
167
- # Limpiar y mensaje final
168
- os.system("clear" if os.name != "nt" else "cls")
169
- print("\n" + "=" * 50)
170
- print("🎉 Instalación completada")
171
- print("=" * 50)
172
-
173
- if __name__ == "__main__":
 
174
  main()
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ install_swarmui.py
4
+ Instala SwarmUI en Kaggle con ComfyUI backend, extensiones, modelos y configuraciones.
5
+ """
6
+
7
+ import os
8
+ import subprocess
9
+ from pathlib import Path
10
+
11
+ WORK_DIR = Path("/kaggle/working").resolve()
12
+ SWARM_DIR = WORK_DIR / "SwarmUI"
13
+ COMFY_DIR = SWARM_DIR / "dlbackend" / "ComfyUI"
14
+
15
+ def _run(cmd: str, cwd: Path | None = None) -> None:
16
+ """Ejecuta un comando shell."""
17
+ print(f"+ {cmd}")
18
+ subprocess.run(cmd, shell=True, check=False, cwd=cwd)
19
+
20
+ def wget(url: str, output: str | None = None, quiet: bool = False, show_progress: bool = False) -> None:
21
+ """Descarga con wget."""
22
+ cmd = "wget"
23
+ if quiet:
24
+ cmd += " -q"
25
+ if show_progress:
26
+ cmd += " --show-progress"
27
+ if output:
28
+ cmd += f" -O {output}"
29
+ cmd += f" {url}"
30
+ _run(cmd)
31
+
32
+ def aria2c(url: str, output: str, cwd: Path | None = None) -> None:
33
+ """Descarga con aria2c."""
34
+ cmd = (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M '
35
+ f'"{url}" -o {output}')
36
+ _run(cmd, cwd=cwd)
37
+
38
+ def clone(repo: str, cwd: Path | None = None) -> None:
39
+ """Clona un repositorio git."""
40
+ _run(f"git clone {repo}", cwd=cwd)
41
+
42
+ def main() -> None:
43
+ os.chdir(WORK_DIR)
44
+
45
+ # 1. Descargas iniciales y clonar SwarmUI
46
+ wget("https://huggingface.co/datasets/Mightys/SwarmuiColab/resolve/main/scripts/download_magic.py")
47
+
48
+ if not SWARM_DIR.exists():
49
+ clone("https://github.com/mcmonkeyprojects/SwarmUI")
50
+
51
+ (SWARM_DIR / "Models").mkdir(parents=True, exist_ok=True)
52
+ (SWARM_DIR / "dlbackend").mkdir(parents=True, exist_ok=True)
53
+
54
+ _run("pip install aria2 gdown")
55
+
56
+ # 2. Configuración de SwarmUI (Data)
57
+ data_dir = SWARM_DIR / "Data"
58
+ data_dir.mkdir(parents=True, exist_ok=True)
59
+ os.chdir(data_dir)
60
+
61
+ wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Swarmui_Kaggle/Settings.fds",
62
+ quiet=True, show_progress=True)
63
+ wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Swarmui_Kaggle/Backends.fds",
64
+ quiet=True, show_progress=True)
65
+ wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Swarmui_Kaggle/Users.ldb",
66
+ quiet=True, show_progress=True)
67
+
68
+ # Autocompletions
69
+ auto_dir = data_dir / "Autocompletions"
70
+ auto_dir.mkdir(parents=True, exist_ok=True)
71
+ os.chdir(auto_dir)
72
+ wget("https://huggingface.co/datasets/Mightys/SwarmuiColab/resolve/main/Data/Autocompletions/danbooru_e621_merged.csv",
73
+ quiet=True, show_progress=True)
74
+
75
+ # 3. Instalar .NET
76
+ os.chdir(WORK_DIR)
77
+ wget("https://dot.net/v1/dotnet-install.sh", output="dotnet-install.sh")
78
+ _run("chmod +x dotnet-install.sh")
79
+ _run("./dotnet-install.sh --channel 8.0")
80
+
81
+ # 4. Instalar Cloudflare tunnel
82
+ wget("https://github.com/cloudflare/cloudflared/releases/download/2024.8.2/cloudflared-linux-amd64.deb",
83
+ quiet=True, show_progress=True)
84
+ _run("dpkg -i cloudflared-linux-amd64.deb")
85
+
86
+ # 5. Clonar ComfyUI
87
+ os.chdir(SWARM_DIR / "dlbackend")
88
+ if not COMFY_DIR.exists():
89
+ clone("https://github.com/comfyanonymous/ComfyUI.git")
90
+ else:
91
+ _run("git pull", cwd=COMFY_DIR)
92
+
93
+ # 6. Dependencias de ComfyUI
94
+ os.chdir(COMFY_DIR)
95
+ _run("uv pip install -r requirements.txt --no-progress")
96
+ _run("uv pip install torch==2.9.1 torchvision==0.24.1 torchaudio xformers==0.0.33.post2 triton==3.5.1 "
97
+ "--index-url https://download.pytorch.org/whl/cu128 --no-progress")
98
+ _run("uv pip install ultralytics==8.3.216 onnxruntime gdown pickleshare insightface clip rembg numpy==2.3.0 "
99
+ "--no-progress")
100
+
101
+ # 7. Extensiones de SwarmUI
102
+ ext_dir = SWARM_DIR / "src" / "Extensions"
103
+ ext_dir.mkdir(parents=True, exist_ok=True)
104
+ os.chdir(ext_dir)
105
+ clone("https://github.com/jtreminio/SwarmUI-PromptBuilderExtension.git")
106
+ clone("https://github.com/yoinked-h/MaHiRon-SwarmUI.git")
107
+ clone("https://github.com/mcmonkeyprojects/sd-dynamic-thresholding")
108
+
109
+ # 8. SageAttention
110
+ os.chdir(WORK_DIR)
111
+ wheel = "sageattention-2.1.2-cp312-cp312-linux_x86_64.whl"
112
+ wget(f"https://huggingface.co/datasets/WhiteAiZ/T4_SageAttention2_For_Google_Colab/resolve/main/python%203.12/{wheel}")
113
+ _run(f"uv pip install {wheel}")
114
+
115
+ # 9. Wildcards
116
+ wild_dir = SWARM_DIR / "Data" / "Wildcards"
117
+ wild_dir.mkdir(parents=True, exist_ok=True)
118
+ os.chdir(wild_dir)
119
+ aria2c("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/Wildcards/artist_tags_danbooru5000.txt",
120
+ "5000-booru-artist.txt")
121
+
122
+ # 10. Modelos YOLO (segmentación/adetailers)
123
+ yolo_dir = SWARM_DIR / "Models" / "yolov8"
124
+ yolo_dir.mkdir(parents=True, exist_ok=True)
125
+ os.chdir(yolo_dir)
126
+
127
+ yolo_models = [
128
+ ("https://huggingface.co/Anzhc/Anzhcs_YOLOs/resolve/main/Anzhc%20Eyes%20-seg-hd.pt", "Anzhc_Eyes-seg-hd.pt"),
129
+ ("https://huggingface.co/Anzhc/Anzhcs_YOLOs/resolve/main/Anzhc%20Face%20seg%20640%20v3%20y11n.pt", "Anzhc_Face_seg_v3_y11n.pt"),
130
+ ("https://huggingface.co/Anzhc/Anzhcs_YOLOs/resolve/main/Anzhc%20Breasts%20Seg%20v1%201024n.pt", "Anzhc_Breasts_Seg_v1_1024n.pt"),
131
+ ("https://huggingface.co/Anzhc/Anzhcs_YOLOs/resolve/main/Anzhc%20HeadHair%20seg%20y8n.pt", "Anzhc_HeadHair_seg_y8n.pt"),
132
+ ("https://huggingface.co/Nudimmud/adetailers/resolve/main/assdetailer-seg.pt", "assdetailer.pt"),
133
+ ("https://huggingface.co/Bingsu/adetailer/resolve/main/face_yolov8n.pt", "face_yolov8n.pt"),
134
+ ("https://huggingface.co/Bingsu/adetailer/resolve/main/face_yolov8m.pt", "face_yolov8m.pt"),
135
+ ("https://huggingface.co/Bingsu/adetailer/resolve/main/hand_yolov8n.pt", "hand_yolov8n.pt"),
136
+ ("https://huggingface.co/Bingsu/adetailer/resolve/main/hand_yolov8m.pt", "hand_yolov8m.pt"),
137
+ ]
138
+
139
+ for url, out in yolo_models:
140
+ aria2c(url, out)
141
+
142
+ # 11. VAE
143
+ vae_dir = SWARM_DIR / "Models" / "VAE"
144
+ vae_dir.mkdir(parents=True, exist_ok=True)
145
+ os.chdir(vae_dir)
146
+ # Nota: %download es una magic de IPython, aquí usamos wget directamente
147
+ wget("https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl_vae.safetensors",
148
+ quiet=True, show_progress=True)
149
+
150
+ # 12. Gradio tunnel
151
+ gradio_script = SWARM_DIR / "gradio-tunnel.py"
152
+ if not gradio_script.exists():
153
+ wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/scripts/gradio-tunnel.py",
154
+ output=str(gradio_script))
155
+
156
+ # 13. Parche de memoria (libmimalloc)
157
+ print("🛠️ Instalando parche de memoria (libmimalloc.so.2.1)...")
158
+ mimalloc_path = WORK_DIR / "libmimalloc.so.2.1"
159
+ if not mimalloc_path.exists():
160
+ wget("https://huggingface.co/datasets/Mightys/Notebook_Scripts/resolve/main/libmimalloc.so.2.1",
161
+ output=str(mimalloc_path))
162
+ print("✅ Parche descargado.")
163
+ else:
164
+ print("✅ Parche listo.")
165
+
166
+ _run("pip install -q requests")
167
+
168
+ # Limpiar y mensaje final
169
+ os.system("clear" if os.name != "nt" else "cls")
170
+ print("\n" + "=" * 50)
171
+ print("🎉 Instalación completada")
172
+ print("=" * 50)
173
+
174
+ if __name__ == "__main__":
175
  main()