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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from IPython.display import display, Image, clear_output
|
| 2 |
+
from IPython import get_ipython
|
| 3 |
+
from ipywidgets import widgets
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
import subprocess
|
| 6 |
+
import argparse
|
| 7 |
+
import shlex
|
| 8 |
+
import json
|
| 9 |
+
import sys
|
| 10 |
+
import os
|
| 11 |
+
import re
|
| 12 |
+
|
| 13 |
+
SyS = get_ipython().system
|
| 14 |
+
CD = os.chdir
|
| 15 |
+
iRON = os.environ
|
| 16 |
+
|
| 17 |
+
# [ĐÃ SỬA] Thêm tham số -b v0.3.75 vào dòng ComfyUI
|
| 18 |
+
REPO = {
|
| 19 |
+
'A1111': 'https://github.com/gutris1/A1111',
|
| 20 |
+
'Forge': 'https://github.com/lllyasviel/stable-diffusion-webui-forge Forge',
|
| 21 |
+
'ReForge': '-b main-old https://github.com/Panchovix/stable-diffusion-webui-reForge ReForge',
|
| 22 |
+
'Forge-Classic': 'https://github.com/Haoming02/sd-webui-forge-classic Forge-Classic',
|
| 23 |
+
'Forge-Neo': '-b neo https://github.com/Haoming02/sd-webui-forge-classic Forge-Neo',
|
| 24 |
+
'ComfyUI': '-b v0.3.75 https://github.com/comfyanonymous/ComfyUI ComfyUI',
|
| 25 |
+
'SwarmUI': 'https://github.com/mcmonkeyprojects/SwarmUI'
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
WEBUI_LIST = ['A1111', 'Forge', 'ReForge', 'Forge-Classic', 'Forge-Neo', 'ComfyUI', 'SwarmUI']
|
| 29 |
+
|
| 30 |
+
def getENV():
|
| 31 |
+
env = {
|
| 32 |
+
'Colab': ('/content', '/content', 'COLAB_JUPYTER_TOKEN'),
|
| 33 |
+
'Kaggle': ('/kaggle', '/kaggle/working', 'KAGGLE_DATA_PROXY_TOKEN')
|
| 34 |
+
}
|
| 35 |
+
for name, (base, home, var) in env.items():
|
| 36 |
+
if var in iRON:
|
| 37 |
+
return name, base, home
|
| 38 |
+
return None, None, None
|
| 39 |
+
|
| 40 |
+
def getArgs():
|
| 41 |
+
parser = argparse.ArgumentParser(description='WebUI Installer Script for Kaggle and Google Colab')
|
| 42 |
+
parser.add_argument('--webui', required=True, help='available webui: A1111, Forge, ReForge, Forge-Classic, Forge-Neo, ComfyUI, SwarmUI')
|
| 43 |
+
parser.add_argument('--civitai_key', required=True, help='your CivitAI API key')
|
| 44 |
+
parser.add_argument('--hf_read_token', default=None, help='your Huggingface READ Token (optional)')
|
| 45 |
+
|
| 46 |
+
args, unknown = parser.parse_known_args()
|
| 47 |
+
|
| 48 |
+
arg1 = args.webui.lower()
|
| 49 |
+
arg2 = args.civitai_key.strip()
|
| 50 |
+
arg3 = args.hf_read_token.strip() if args.hf_read_token else ''
|
| 51 |
+
|
| 52 |
+
if not any(arg1 == option.lower() for option in WEBUI_LIST):
|
| 53 |
+
print(f'{ERROR}: invalid webui option: "{args.webui}"')
|
| 54 |
+
print(f'Available webui options: {", ".join(WEBUI_LIST)}')
|
| 55 |
+
return None, None, None
|
| 56 |
+
|
| 57 |
+
if not arg2:
|
| 58 |
+
print(f'{ERROR}: CivitAI API key is missing.')
|
| 59 |
+
return None, None, None
|
| 60 |
+
if re.search(r'\s+', arg2):
|
| 61 |
+
print(f'{ERROR}: CivitAI API key contains spaces "{arg2}" - not allowed.')
|
| 62 |
+
return None, None, None
|
| 63 |
+
if len(arg2) < 32:
|
| 64 |
+
print(f'{ERROR}: CivitAI API key must be at least 32 characters long.')
|
| 65 |
+
return None, None, None
|
| 66 |
+
|
| 67 |
+
if not arg3: arg3 = ''
|
| 68 |
+
if re.search(r'\s+', arg3): arg3 = ''
|
| 69 |
+
|
| 70 |
+
selected_ui = next(option for option in WEBUI_LIST if arg1 == option.lower())
|
| 71 |
+
return selected_ui, arg2, arg3
|
| 72 |
+
|
| 73 |
+
def getPython():
|
| 74 |
+
hao = webui in ['Forge-Classic', 'Forge-Neo']
|
| 75 |
+
v = '3.11' if hao else '3.10'
|
| 76 |
+
BIN = str(PY / 'bin')
|
| 77 |
+
PKG = str(PY / f'lib/python{v}/site-packages')
|
| 78 |
+
|
| 79 |
+
tar = {
|
| 80 |
+
**dict.fromkeys(['ComfyUI', 'SwarmUI'], 'https://huggingface.co/gutris1/webui/resolve/main/env/KC-ComfyUI-SwarmUI-Python310-Torch260-cu124.tar.lz4'),
|
| 81 |
+
'Forge-Classic': 'https://huggingface.co/gutris1/webui/resolve/main/env/KC-FC-Python311-Torch260-cu124.tar.lz4',
|
| 82 |
+
'Forge-Neo': 'https://huggingface.co/gutris1/webui/resolve/main/env/KC-FN-Python311-Torch280-cu126.tar.lz4',
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
url = tar.get(webui, 'https://huggingface.co/gutris1/webui/resolve/main/env/KC-Python310-Torch260-cu124.tar.lz4')
|
| 86 |
+
|
| 87 |
+
fn = Path(url).name
|
| 88 |
+
|
| 89 |
+
CD(Path(ENVBASE).parent)
|
| 90 |
+
print(f"\n{ARROW} installing Python Portable {'3.11.13' if hao else '3.10.15'}")
|
| 91 |
+
|
| 92 |
+
SyS('sudo apt-get -qq -y install aria2 pv lz4 > /dev/null 2>&1')
|
| 93 |
+
|
| 94 |
+
aria = f'aria2c --console-log-level=error --stderr=true -c -x16 -s16 -k1M -j5 {url} -o {fn}'
|
| 95 |
+
p = subprocess.Popen(shlex.split(aria), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 96 |
+
p.wait()
|
| 97 |
+
|
| 98 |
+
SyS(f'pv {fn} | lz4 -d | tar -xf -')
|
| 99 |
+
Path(f'/{fn}').unlink()
|
| 100 |
+
|
| 101 |
+
sys.path.insert(0, PKG)
|
| 102 |
+
if BIN not in iRON['PATH']:
|
| 103 |
+
iRON['PATH'] = BIN + ':' + iRON['PATH']
|
| 104 |
+
if PKG not in iRON['PYTHONPATH']:
|
| 105 |
+
iRON['PYTHONPATH'] = PKG + ':' + iRON['PYTHONPATH']
|
| 106 |
+
|
| 107 |
+
if ENVNAME == 'Kaggle':
|
| 108 |
+
for cmd in [
|
| 109 |
+
'pip install ipywidgets jupyterlab_widgets --upgrade',
|
| 110 |
+
'rm -f /usr/lib/python3.10/sitecustomize.py'
|
| 111 |
+
]:
|
| 112 |
+
SyS(f'{cmd} > /dev/null 2>&1')
|
| 113 |
+
|
| 114 |
+
def marking(p, n, u):
|
| 115 |
+
t = p / n
|
| 116 |
+
v = {'ui': u, 'launch_args': '', 'tunnel': ''}
|
| 117 |
+
|
| 118 |
+
if not t.exists(): t.write_text(json.dumps(v, indent=4))
|
| 119 |
+
|
| 120 |
+
d = json.loads(t.read_text())
|
| 121 |
+
d.update(v)
|
| 122 |
+
t.write_text(json.dumps(d, indent=4))
|
| 123 |
+
|
| 124 |
+
def key_inject(C, H):
|
| 125 |
+
p = Path(nenen)
|
| 126 |
+
v = p.read_text()
|
| 127 |
+
v = v.replace("TOKET = ''", f"TOKET = '{C}'")
|
| 128 |
+
v = v.replace("TOBRUT = ''", f"TOBRUT = '{H}'")
|
| 129 |
+
p.write_text(v)
|
| 130 |
+
|
| 131 |
+
def install_tunnel():
|
| 132 |
+
SyS(f'wget -qO {USR}/cl https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64')
|
| 133 |
+
SyS(f'chmod +x {USR}/cl')
|
| 134 |
+
|
| 135 |
+
bins = {
|
| 136 |
+
'zrok': {
|
| 137 |
+
'bin': USR / 'zrok',
|
| 138 |
+
'url': 'https://github.com/openziti/zrok/releases/download/v1.0.6/zrok_1.0.6_linux_amd64.tar.gz'
|
| 139 |
+
},
|
| 140 |
+
'ngrok': {
|
| 141 |
+
'bin': USR / 'ngrok',
|
| 142 |
+
'url': 'https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz'
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
for n, b in bins.items():
|
| 147 |
+
if b['bin'].exists(): b['bin'].unlink()
|
| 148 |
+
|
| 149 |
+
url = b['url']
|
| 150 |
+
name = Path(url).name
|
| 151 |
+
|
| 152 |
+
SyS(f'wget -qO {name} {url}')
|
| 153 |
+
SyS(f'tar -xzf {name} -C {USR}')
|
| 154 |
+
SyS(f'rm -f {name}')
|
| 155 |
+
|
| 156 |
+
def sym_link(U, M):
|
| 157 |
+
configs = {
|
| 158 |
+
'A1111': {
|
| 159 |
+
'sym': [
|
| 160 |
+
f"rm -rf {M / 'Stable-diffusion/tmp_ckpt'} {M / 'Lora/tmp_lora'} {M / 'ControlNet'} {TMP}/*"
|
| 161 |
+
],
|
| 162 |
+
'links': [
|
| 163 |
+
(TMP / 'ckpt', M / 'Stable-diffusion/tmp_ckpt'),
|
| 164 |
+
(TMP / 'lora', M / 'Lora/tmp_lora'),
|
| 165 |
+
(TMP / 'controlnet', M / 'ControlNet')
|
| 166 |
+
]
|
| 167 |
+
},
|
| 168 |
+
|
| 169 |
+
'Forge': {
|
| 170 |
+
'sym': [
|
| 171 |
+
f"rm -rf {M / 'Stable-diffusion/tmp_ckpt'} {M / 'Lora/tmp_lora'} {M / 'ControlNet'}",
|
| 172 |
+
f"rm -rf {M / 'svd'} {M / 'z123'} {M / 'clip'} {M / 'clip_vision'} {M / 'diffusers'}",
|
| 173 |
+
f"rm -rf {M / 'diffusion_models'} {M / 'text_encoder'} {M / 'unet'} {TMP}/*"
|
| 174 |
+
],
|
| 175 |
+
'links': [
|
| 176 |
+
(TMP / 'ckpt', M / 'Stable-diffusion/tmp_ckpt'),
|
| 177 |
+
(TMP / 'lora', M / 'Lora/tmp_lora'),
|
| 178 |
+
(TMP / 'controlnet', M / 'ControlNet'),
|
| 179 |
+
(TMP / 'z123', M / 'z123'),
|
| 180 |
+
(TMP / 'svd', M / 'svd'),
|
| 181 |
+
(TMP / 'clip', M / 'clip'),
|
| 182 |
+
(TMP / 'clip_vision', M / 'clip_vision'),
|
| 183 |
+
(TMP / 'diffusers', M / 'diffusers'),
|
| 184 |
+
(TMP / 'diffusion_models', M / 'diffusion_models'),
|
| 185 |
+
(TMP / 'text_encoders', M / 'text_encoder'),
|
| 186 |
+
(TMP / 'unet', M / 'unet')
|
| 187 |
+
]
|
| 188 |
+
},
|
| 189 |
+
|
| 190 |
+
'ReForge': {
|
| 191 |
+
'sym': [
|
| 192 |
+
f"rm -rf {M / 'Stable-diffusion/tmp_ckpt'} {M / 'Lora/tmp_lora'} {M / 'ControlNet'}",
|
| 193 |
+
f"rm -rf {M / 'svd'} {M / 'z123'} {TMP}/*"
|
| 194 |
+
],
|
| 195 |
+
'links': [
|
| 196 |
+
(TMP / 'ckpt', M / 'Stable-diffusion/tmp_ckpt'),
|
| 197 |
+
(TMP / 'lora', M / 'Lora/tmp_lora'),
|
| 198 |
+
(TMP / 'controlnet', M / 'ControlNet'),
|
| 199 |
+
(TMP / 'z123', M / 'z123'),
|
| 200 |
+
(TMP / 'svd', M / 'svd')
|
| 201 |
+
]
|
| 202 |
+
},
|
| 203 |
+
|
| 204 |
+
'Forge-Classic': {
|
| 205 |
+
'sym': [
|
| 206 |
+
f"rm -rf {M / 'Stable-diffusion/tmp_ckpt'} {M / 'Lora/tmp_lora'} {M / 'ControlNet'}"
|
| 207 |
+
],
|
| 208 |
+
'links': [
|
| 209 |
+
(TMP / 'ckpt', M / 'Stable-diffusion/tmp_ckpt'),
|
| 210 |
+
(TMP / 'lora', M / 'Lora/tmp_lora'),
|
| 211 |
+
(TMP / 'controlnet', M / 'ControlNet')
|
| 212 |
+
]
|
| 213 |
+
},
|
| 214 |
+
|
| 215 |
+
'Forge-Neo': {
|
| 216 |
+
'sym': [
|
| 217 |
+
f"rm -rf {M / 'Stable-diffusion/tmp_ckpt'} {M / 'Lora/tmp_lora'} {M / 'ControlNet'}"
|
| 218 |
+
],
|
| 219 |
+
'links': [
|
| 220 |
+
(TMP / 'ckpt', M / 'Stable-diffusion/tmp_ckpt'),
|
| 221 |
+
(TMP / 'lora', M / 'Lora/tmp_lora'),
|
| 222 |
+
(TMP / 'controlnet', M / 'ControlNet')
|
| 223 |
+
]
|
| 224 |
+
},
|
| 225 |
+
|
| 226 |
+
'ComfyUI': {
|
| 227 |
+
'sym': [
|
| 228 |
+
f"rm -rf {M / 'checkpoints/tmp_ckpt'} {M / 'loras/tmp_lora'} {M / 'controlnet'}",
|
| 229 |
+
f"rm -rf {M / 'clip'} {M / 'clip_vision'} {M / 'diffusers'} {M / 'diffusion_models'}",
|
| 230 |
+
f"rm -rf {M / 'text_encoders'} {M / 'unet'} {TMP}/*"
|
| 231 |
+
],
|
| 232 |
+
'links': [
|
| 233 |
+
(TMP / 'ckpt', M / 'checkpoints/tmp_ckpt'),
|
| 234 |
+
(TMP / 'lora', M / 'loras/tmp_lora'),
|
| 235 |
+
(TMP / 'controlnet', M / 'controlnet'),
|
| 236 |
+
(TMP / 'clip', M / 'clip'),
|
| 237 |
+
(TMP / 'clip_vision', M / 'clip_vision'),
|
| 238 |
+
(TMP / 'diffusers', M / 'diffusers'),
|
| 239 |
+
(TMP / 'diffusion_models', M / 'diffusion_models'),
|
| 240 |
+
(TMP / 'text_encoders', M / 'text_encoders'),
|
| 241 |
+
(TMP / 'unet', M / 'unet')
|
| 242 |
+
]
|
| 243 |
+
},
|
| 244 |
+
|
| 245 |
+
'SwarmUI': {
|
| 246 |
+
'sym': [
|
| 247 |
+
f"rm -rf {M / 'Stable-Diffusion/tmp_ckpt'} {M / 'Lora/tmp_lora'} {M / 'controlnet'}",
|
| 248 |
+
f"rm -rf {M / 'clip'} {M / 'unet'} {TMP}/*"
|
| 249 |
+
],
|
| 250 |
+
'links': [
|
| 251 |
+
(TMP / 'ckpt', M / 'Stable-Diffusion/tmp_ckpt'),
|
| 252 |
+
(TMP / 'lora', M / 'Lora/tmp_lora'),
|
| 253 |
+
(TMP / 'controlnet', M / 'controlnet'),
|
| 254 |
+
(TMP / 'clip', M / 'clip'),
|
| 255 |
+
(TMP / 'unet', M / 'unet')
|
| 256 |
+
]
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
cfg = configs.get(U)
|
| 261 |
+
[SyS(f'{cmd}') for cmd in cfg['sym']]
|
| 262 |
+
if U not in ['ComfyUI', 'SwarmUI']: [(M / d).mkdir(parents=True, exist_ok=True) for d in ['Lora', 'ESRGAN']]
|
| 263 |
+
[SyS(f'ln -s {src} {tg}') for src, tg in cfg['links']]
|
| 264 |
+
|
| 265 |
+
def webui_req(U, W, M):
|
| 266 |
+
CD(W)
|
| 267 |
+
|
| 268 |
+
if U != 'SwarmUI':
|
| 269 |
+
pull(f'https://github.com/gutris1/segsmaker {U.lower()} {W}')
|
| 270 |
+
else:
|
| 271 |
+
M.mkdir(parents=True, exist_ok=True)
|
| 272 |
+
for sub in ['Stable-Diffusion', 'Lora', 'Embeddings', 'VAE', 'upscale_models']:
|
| 273 |
+
(M / sub).mkdir(parents=True, exist_ok=True)
|
| 274 |
+
|
| 275 |
+
download(f'https://dot.net/v1/dotnet-install.sh {W}')
|
| 276 |
+
dotnet = W / 'dotnet-install.sh'
|
| 277 |
+
dotnet.chmod(0o755)
|
| 278 |
+
SyS('bash ./dotnet-install.sh --channel 8.0')
|
| 279 |
+
|
| 280 |
+
sym_link(U, M)
|
| 281 |
+
install_tunnel()
|
| 282 |
+
|
| 283 |
+
scripts = [
|
| 284 |
+
f'https://github.com/gutris1/segsmaker/raw/main/script/controlnet.py {W}/asd',
|
| 285 |
+
f'https://github.com/gutris1/segsmaker/raw/main/script/KC/segsmaker.py {W}'
|
| 286 |
+
]
|
| 287 |
+
|
| 288 |
+
u = M / 'upscale_models' if U in ['ComfyUI', 'SwarmUI'] else M / 'ESRGAN'
|
| 289 |
+
|
| 290 |
+
upscalers = [
|
| 291 |
+
f'https://huggingface.co/gutris1/webui/resolve/main/misc/4x-UltraSharp.pth {u}',
|
| 292 |
+
f'https://huggingface.co/gutris1/webui/resolve/main/misc/4x-AnimeSharp.pth {u}',
|
| 293 |
+
f'https://huggingface.co/gutris1/webui/resolve/main/misc/4x_NMKD-Superscale-SP_178000_G.pth {u}',
|
| 294 |
+
f'https://huggingface.co/uwg/upscaler/resolve/main/ESRGAN/8x_NMKD-Superscale_150000_G.pth {u}',
|
| 295 |
+
f'https://huggingface.co/gutris1/webui/resolve/main/misc/4x_RealisticRescaler_100000_G.pth {u}',
|
| 296 |
+
f'https://huggingface.co/gutris1/webui/resolve/main/misc/8x_RealESRGAN.pth {u}',
|
| 297 |
+
f'https://huggingface.co/gutris1/webui/resolve/main/misc/4x_foolhardy_Remacri.pth {u}',
|
| 298 |
+
f'https://huggingface.co/subby2006/NMKD-YandereNeoXL/resolve/main/4x_NMKD-YandereNeoXL_200k.pth {u}',
|
| 299 |
+
f'https://huggingface.co/subby2006/NMKD-UltraYandere/resolve/main/4x_NMKD-UltraYandere_300k.pth {u}'
|
| 300 |
+
]
|
| 301 |
+
|
| 302 |
+
line = scripts + upscalers
|
| 303 |
+
for item in line: download(item)
|
| 304 |
+
|
| 305 |
+
if U not in ['SwarmUI', 'ComfyUI']:
|
| 306 |
+
e = 'jpg' if U in ['Forge-Classic', 'Forge-Neo'] else 'png'
|
| 307 |
+
SyS(f'rm -f {W}/html/card-no-preview.{e}')
|
| 308 |
+
|
| 309 |
+
for ass in [
|
| 310 |
+
f'https://huggingface.co/gutris1/webui/resolve/main/misc/card-no-preview.png {W}/html card-no-preview.{e}',
|
| 311 |
+
f'https://github.com/gutris1/segsmaker/raw/main/config/NoCrypt_miku.json {W}/tmp/gradio_themes',
|
| 312 |
+
f'https://github.com/gutris1/segsmaker/raw/main/config/user.css {W} user.css'
|
| 313 |
+
]: download(ass)
|
| 314 |
+
|
| 315 |
+
if U not in ['Forge', 'Forge-Neo']: download(f'https://github.com/gutris1/segsmaker/raw/main/config/config.json {W} config.json')
|
| 316 |
+
|
| 317 |
+
def webui_extension(U, W, M):
|
| 318 |
+
EXT = W / 'custom_nodes' if U == 'ComfyUI' else W / 'extensions'
|
| 319 |
+
CD(EXT)
|
| 320 |
+
|
| 321 |
+
if U == 'ComfyUI':
|
| 322 |
+
say('<br><b>【{red} Installing Custom Nodes{d} 】{red}</b>')
|
| 323 |
+
clone(str(W / 'asd/custom_nodes.txt'))
|
| 324 |
+
print()
|
| 325 |
+
|
| 326 |
+
for faces in [
|
| 327 |
+
f'https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth {M}/facerestore_models',
|
| 328 |
+
f'https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/GFPGANv1.4.pth {M}/facerestore_models'
|
| 329 |
+
]: download(faces)
|
| 330 |
+
|
| 331 |
+
else:
|
| 332 |
+
say('<br><b>【{red} Installing Extensions{d} 】{red}</b>')
|
| 333 |
+
clone(str(W / 'asd/extension.txt'))
|
| 334 |
+
if ENVNAME == 'Kaggle': clone('https://github.com/gutris1/sd-image-encryption')
|
| 335 |
+
|
| 336 |
+
def webui_installation(U, W):
|
| 337 |
+
M = W / 'Models' if U == 'SwarmUI' else W / 'models'
|
| 338 |
+
E = M / 'Embeddings' if U == 'SwarmUI' else (M / 'embeddings' if U in ['Forge-Classic', 'Forge-Neo', 'ComfyUI'] else W / 'embeddings')
|
| 339 |
+
V = M / 'vae' if U == 'ComfyUI' else M / 'VAE'
|
| 340 |
+
|
| 341 |
+
webui_req(U, W, M)
|
| 342 |
+
|
| 343 |
+
extras = [
|
| 344 |
+
f'https://huggingface.co/gutris1/webui/resolve/main/misc/embeddingsXL.zip {W}',
|
| 345 |
+
f'https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl.vae.safetensors {V} sdxl_vae.safetensors'
|
| 346 |
+
]
|
| 347 |
+
|
| 348 |
+
for i in extras: download(i)
|
| 349 |
+
SyS(f"unzip -qo {W / 'embeddingsXL.zip'} -d {E} && rm {W / 'embeddingsXL.zip'}")
|
| 350 |
+
|
| 351 |
+
if U != 'SwarmUI': webui_extension(U, W, M)
|
| 352 |
+
|
| 353 |
+
def webui_selection(ui):
|
| 354 |
+
with output:
|
| 355 |
+
output.clear_output(wait=True)
|
| 356 |
+
|
| 357 |
+
if ui in REPO: (WEBUI, repo) = (HOME / ui, REPO[ui])
|
| 358 |
+
say(f'<b>【{{red}} Installing {WEBUI.name}{{d}} 】{{red}}</b>')
|
| 359 |
+
clone(repo)
|
| 360 |
+
|
| 361 |
+
webui_installation(ui, WEBUI)
|
| 362 |
+
|
| 363 |
+
with loading:
|
| 364 |
+
loading.clear_output(wait=True)
|
| 365 |
+
say('<br><b>【{red} Done{d} 】{red}</b>')
|
| 366 |
+
tempe()
|
| 367 |
+
CD(HOME)
|
| 368 |
+
|
| 369 |
+
def webui_installer():
|
| 370 |
+
branchs = {
|
| 371 |
+
'A1111': 'master',
|
| 372 |
+
# 'ComfyUI': 'master', # [ĐÃ SỬA] Xóa/Ẩn dòng này để không tự update lên master
|
| 373 |
+
'SwarmUI': 'master',
|
| 374 |
+
'Forge': 'main',
|
| 375 |
+
'ReForge': 'main',
|
| 376 |
+
'Forge-Classic': 'classic',
|
| 377 |
+
'Forge-Neo': 'neo',
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
CD(HOME)
|
| 381 |
+
ui = (json.load(MARKED.open('r')) if MARKED.exists() else {}).get('ui')
|
| 382 |
+
WEBUI = HOME / ui if ui else None
|
| 383 |
+
|
| 384 |
+
if WEBUI is not None and WEBUI.exists():
|
| 385 |
+
git_dir = WEBUI / '.git'
|
| 386 |
+
if git_dir.exists():
|
| 387 |
+
CD(WEBUI)
|
| 388 |
+
with output:
|
| 389 |
+
output.clear_output(wait=True)
|
| 390 |
+
if ui in branchs: SyS(f'git pull origin {branchs[ui]}')
|
| 391 |
+
with loading: loading.clear_output()
|
| 392 |
+
else:
|
| 393 |
+
try:
|
| 394 |
+
webui_selection(webui)
|
| 395 |
+
except KeyboardInterrupt:
|
| 396 |
+
with loading: loading.clear_output()
|
| 397 |
+
with output: print('\nCanceled.')
|
| 398 |
+
except Exception as e:
|
| 399 |
+
with loading: loading.clear_output()
|
| 400 |
+
with output: print(f'\n{ERROR}: {e}')
|
| 401 |
+
|
| 402 |
+
def notebook_scripts():
|
| 403 |
+
z = [
|
| 404 |
+
(STR / '00-startup.py', f'wget -qO {STR}/00-startup.py https://github.com/gutris1/segsmaker/raw/main/script/KC/00-startup.py'),
|
| 405 |
+
(nenen, f'wget -qO {nenen} https://github.com/gutris1/segsmaker/raw/main/script/nenen88.py'),
|
| 406 |
+
(melon, f'wget -qO {melon} https://github.com/gutris1/segsmaker/raw/main/script/melon00.py'),
|
| 407 |
+
(STR / 'cupang.py', f'wget -qO {STR}/cupang.py https://github.com/gutris1/segsmaker/raw/main/script/cupang.py'),
|
| 408 |
+
(MRK, f'wget -qO {MRK} https://github.com/gutris1/segsmaker/raw/main/script/marking.py')
|
| 409 |
+
]
|
| 410 |
+
|
| 411 |
+
[SyS(y) for x, y in z if not Path(x).exists()]
|
| 412 |
+
|
| 413 |
+
j = {'ENVNAME': ENVNAME, 'HOMEPATH': HOME, 'TEMPPATH': TMP, 'BASEPATH': Path(ENVBASE)}
|
| 414 |
+
text = '\n'.join(f"{k} = '{v}'" for k, v in j.items())
|
| 415 |
+
Path(KANDANG).write_text(text)
|
| 416 |
+
|
| 417 |
+
key_inject(civitai_key, hf_read_token)
|
| 418 |
+
marking(SRC, MARKED, webui)
|
| 419 |
+
sys.path.append(str(STR))
|
| 420 |
+
|
| 421 |
+
for scripts in [nenen, melon, KANDANG, MRK]: get_ipython().run_line_magic('run', str(scripts))
|
| 422 |
+
|
| 423 |
+
ENVNAME, ENVBASE, ENVHOME = getENV()
|
| 424 |
+
|
| 425 |
+
if not ENVNAME:
|
| 426 |
+
print('You are not in Kaggle or Google Colab.\nExiting.')
|
| 427 |
+
sys.exit()
|
| 428 |
+
|
| 429 |
+
RESET = '\033[0m'
|
| 430 |
+
RED = '\033[31m'
|
| 431 |
+
PURPLE = '\033[38;5;135m'
|
| 432 |
+
ORANGE = '\033[38;5;208m'
|
| 433 |
+
ARROW = f'{ORANGE}▶{RESET}'
|
| 434 |
+
ERROR = f'{PURPLE}[{RESET}{RED}ERROR{RESET}{PURPLE}]{RESET}'
|
| 435 |
+
IMG = 'https://github.com/gutris1/segsmaker/raw/main/script/loading.png'
|
| 436 |
+
|
| 437 |
+
HOME = Path(ENVHOME)
|
| 438 |
+
TMP = Path(ENVBASE) / 'temp'
|
| 439 |
+
|
| 440 |
+
PY = Path('/GUTRIS1')
|
| 441 |
+
SRC = HOME / 'gutris1'
|
| 442 |
+
MRK = SRC / 'marking.py'
|
| 443 |
+
KEY = SRC / 'api-key.json'
|
| 444 |
+
MARKED = SRC / 'marking.json'
|
| 445 |
+
|
| 446 |
+
USR = Path('/usr/bin')
|
| 447 |
+
STR = Path('/root/.ipython/profile_default/startup')
|
| 448 |
+
nenen = STR / 'nenen88.py'
|
| 449 |
+
melon = STR / 'melon00.py'
|
| 450 |
+
KANDANG = STR / 'KANDANG.py'
|
| 451 |
+
|
| 452 |
+
TMP.mkdir(parents=True, exist_ok=True)
|
| 453 |
+
SRC.mkdir(parents=True, exist_ok=True)
|
| 454 |
+
|
| 455 |
+
output = widgets.Output()
|
| 456 |
+
loading = widgets.Output()
|
| 457 |
+
|
| 458 |
+
webui, civitai_key, hf_read_token = getArgs()
|
| 459 |
+
if civitai_key is None: sys.exit()
|
| 460 |
+
|
| 461 |
+
display(output, loading)
|
| 462 |
+
with loading: display(Image(url=IMG))
|
| 463 |
+
with output: PY.exists() or getPython()
|
| 464 |
+
notebook_scripts()
|
| 465 |
+
|
| 466 |
+
from nenen88 import clone, say, download, tempe, pull
|
| 467 |
+
webui_installer()
|