Spaces:
Running
Running
stlaurentjr
commited on
Commit
•
8ca52ce
1
Parent(s):
7a3349a
Update scripts/mainrunpodA1111.py
Browse files- scripts/mainrunpodA1111.py +272 -71
scripts/mainrunpodA1111.py
CHANGED
@@ -148,9 +148,31 @@ def mdl(Original_Model_Version, Path_to_MODEL, MODEL_LINK):
|
|
148 |
|
149 |
src=getsrc(MODEL_LINK)
|
150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
if not os.path.exists('/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/SDv1-5.ckpt'):
|
152 |
call('ln -s /workspace/auto-models/* /workspace/sd/stable-diffusion-webui/models/Stable-diffusion', shell=True)
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
if Path_to_MODEL !='':
|
155 |
if os.path.exists(str(Path_to_MODEL)):
|
156 |
print('[1;32mUsing the custom model')
|
@@ -261,97 +283,120 @@ def loradwn(LoRA_LINK):
|
|
261 |
else:
|
262 |
print('[1;31mWrong link, check that the link is valid')
|
263 |
|
264 |
-
|
265 |
-
|
266 |
def CNet(ControlNet_Model, ControlNet_XL_Model):
|
267 |
-
|
268 |
def download(url, model_dir):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
|
270 |
-
|
271 |
-
|
272 |
-
if not os.path.exists(pth):
|
273 |
-
print('Downloading: '+os.path.basename(url))
|
274 |
-
download_url_to_file(url, pth, hash_prefix=None, progress=True)
|
275 |
-
else:
|
276 |
-
print(f"[1;32mThe model {filename} already exists[0m")
|
277 |
-
|
278 |
-
wrngv1=False
|
279 |
-
os.chdir('/workspace/sd/stable-diffusion-webui/extensions')
|
280 |
if not os.path.exists("sd-webui-controlnet"):
|
281 |
-
|
282 |
-
|
|
|
|
|
283 |
else:
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
|
289 |
-
mdldir="/workspace/sd/stable-diffusion-webui/extensions/sd-webui-controlnet/models"
|
290 |
for filename in os.listdir(mdldir):
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
|
295 |
-
call(
|
296 |
-
|
297 |
-
|
298 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
mdllnk = f.read().splitlines()
|
300 |
-
with open("CN_models_XL.txt",
|
301 |
mdllnk_XL = d.read().splitlines()
|
302 |
-
call(
|
303 |
-
|
304 |
-
os.chdir('/workspace')
|
305 |
|
306 |
-
|
307 |
-
for lnk in mdllnk:
|
308 |
-
download(lnk, mdldir)
|
309 |
-
clear_output()
|
310 |
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
download(lnk, mdldir)
|
316 |
-
clear_output()
|
317 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
|
319 |
-
elif ControlNet_Model.isdigit() and int(ControlNet_Model)-1<14 and int(ControlNet_Model)>0:
|
320 |
-
download(mdllnk[int(ControlNet_Model)-1], mdldir)
|
321 |
-
clear_output()
|
322 |
-
|
323 |
elif ControlNet_Model == "none":
|
324 |
-
|
325 |
-
|
326 |
|
327 |
else:
|
328 |
-
|
329 |
-
|
330 |
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
done()
|
338 |
|
339 |
-
elif ControlNet_XL_Model.isdigit() and int(ControlNet_XL_Model)-1<5:
|
340 |
-
download(mdllnk_XL[int(ControlNet_XL_Model)-1], mdldir)
|
341 |
-
if not wrngv1:
|
342 |
-
clear_output()
|
343 |
-
done()
|
344 |
-
|
345 |
elif ControlNet_XL_Model == "none":
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
|
351 |
else:
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
|
356 |
def sd(User, Password, model):
|
357 |
|
@@ -398,8 +443,8 @@ def sd(User, Password, model):
|
|
398 |
mdlpth="--ckpt "+model
|
399 |
else:
|
400 |
mdlpth="--ckpt-dir "+model
|
401 |
-
|
402 |
-
configf="--disable-console-progressbars --no-half-vae --disable-safe-unpickle --api --no-download-sd-model --opt-sdp-attention --enable-insecure-extension-access --skip-version-check --listen --port 3000 "+auth+" "+mdlpth
|
403 |
|
404 |
return configf
|
405 |
|
@@ -488,7 +533,163 @@ def get_name(url, gdrive):
|
|
488 |
content_disposition = six.moves.urllib_parse.unquote(res.headers["Content-Disposition"])
|
489 |
filenm = re.search('attachment; filename="(.*?)"', content_disposition).groups()[0]
|
490 |
return filenm
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
491 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
492 |
|
493 |
|
494 |
|
|
|
148 |
|
149 |
src=getsrc(MODEL_LINK)
|
150 |
|
151 |
+
if not os.path.exists("/workspace/sd/stable-diffusion-webui/models/VAE"):
|
152 |
+
call("mkdir -p /workspace/sd/stable-diffusion-webui/models/VAE", shell=True)
|
153 |
+
|
154 |
+
# Получаем список файлов в директории /workspace/auto-VAE
|
155 |
+
files = os.listdir("/workspace/auto-VAE")
|
156 |
+
|
157 |
+
for file in files:
|
158 |
+
source_path = os.path.join("/workspace/auto-VAE", file)
|
159 |
+
target_path = os.path.join(
|
160 |
+
"/workspace/sd/stable-diffusion-webui/models/VAE", file
|
161 |
+
)
|
162 |
+
# Проверяем, существует ли уже символическая ссылка
|
163 |
+
if not os.path.exists(target_path):
|
164 |
+
call(f"ln -s {source_path} {target_path}", shell=True)
|
165 |
+
|
166 |
if not os.path.exists('/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/SDv1-5.ckpt'):
|
167 |
call('ln -s /workspace/auto-models/* /workspace/sd/stable-diffusion-webui/models/Stable-diffusion', shell=True)
|
168 |
+
|
169 |
+
if not os.path.exists("/workspace/sd/stable-diffusion-webui/models/Lora"):
|
170 |
+
call("mkdir -p /workspace/sd/stable-diffusion-webui/models/Lora", shell=True)
|
171 |
+
call(
|
172 |
+
"ln -s /workspace/auto-lora/* /workspace/sd/stable-diffusion-webui/models/Lora",
|
173 |
+
shell=True,
|
174 |
+
)
|
175 |
+
|
176 |
if Path_to_MODEL !='':
|
177 |
if os.path.exists(str(Path_to_MODEL)):
|
178 |
print('[1;32mUsing the custom model')
|
|
|
283 |
else:
|
284 |
print('[1;31mWrong link, check that the link is valid')
|
285 |
|
|
|
|
|
286 |
def CNet(ControlNet_Model, ControlNet_XL_Model):
|
|
|
287 |
def download(url, model_dir):
|
288 |
+
try:
|
289 |
+
filename = os.path.basename(urlparse(url).path)
|
290 |
+
pth = os.path.abspath(os.path.join(model_dir, filename))
|
291 |
+
if not os.path.exists(pth):
|
292 |
+
print("Downloading: " + os.path.basename(url))
|
293 |
+
download_url_to_file(url, pth, hash_prefix=None, progress=True)
|
294 |
+
else:
|
295 |
+
print(f"[1;32mThe model {filename} already exists[0m")
|
296 |
+
except Exception as e:
|
297 |
+
print(f"Ошибка при скачивании {url}: {e}")
|
298 |
|
299 |
+
wrngv1 = False
|
300 |
+
os.chdir("/workspace/sd/stable-diffusion-webui/extensions")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
if not os.path.exists("sd-webui-controlnet"):
|
302 |
+
call(
|
303 |
+
"git clone https://github.com/Mikubill/sd-webui-controlnet.git", shell=True
|
304 |
+
)
|
305 |
+
os.chdir("/workspace")
|
306 |
else:
|
307 |
+
os.chdir("sd-webui-controlnet")
|
308 |
+
call(
|
309 |
+
"git reset --hard",
|
310 |
+
shell=True,
|
311 |
+
stdout=open("/dev/null", "w"),
|
312 |
+
stderr=open("/dev/null", "w"),
|
313 |
+
)
|
314 |
+
call(
|
315 |
+
"git pull",
|
316 |
+
shell=True,
|
317 |
+
stdout=open("/dev/null", "w"),
|
318 |
+
stderr=open("/dev/null", "w"),
|
319 |
+
)
|
320 |
+
os.chdir("/workspace")
|
321 |
+
|
322 |
+
mdldir = (
|
323 |
+
"/workspace/sd/stable-diffusion-webui/extensions/sd-webui-controlnet/models"
|
324 |
+
)
|
325 |
+
call(
|
326 |
+
"ln -s /workspace/auto-controlnet-models/* /workspace/sd/stable-diffusion-webui/extensions/sd-webui-controlnet/models",
|
327 |
+
shell=True,
|
328 |
+
)
|
329 |
|
|
|
330 |
for filename in os.listdir(mdldir):
|
331 |
+
if "_sd14v1" in filename:
|
332 |
+
renamed = re.sub("_sd14v1", "-fp16", filename)
|
333 |
+
os.rename(os.path.join(mdldir, filename), os.path.join(mdldir, renamed))
|
334 |
|
335 |
+
call(
|
336 |
+
"wget -q -O CN_models.txt https://huggingface.co/spaces/stlaurentjr/RNPD/raw/main/config/CN_models.txt",
|
337 |
+
shell=True,
|
338 |
+
)
|
339 |
+
call(
|
340 |
+
"wget -q -O CN_models_XL.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_XL.txt",
|
341 |
+
shell=True,
|
342 |
+
)
|
343 |
+
|
344 |
+
with open("CN_models.txt", "r") as f:
|
345 |
mdllnk = f.read().splitlines()
|
346 |
+
with open("CN_models_XL.txt", "r") as d:
|
347 |
mdllnk_XL = d.read().splitlines()
|
348 |
+
call("rm CN_models.txt CN_models_XL.txt", shell=True)
|
|
|
|
|
349 |
|
350 |
+
os.chdir("/workspace")
|
|
|
|
|
|
|
351 |
|
352 |
+
if ControlNet_Model == "All" or ControlNet_Model == "all":
|
353 |
+
for lnk in mdllnk:
|
354 |
+
download(lnk, mdldir)
|
355 |
+
clear_output()
|
|
|
|
|
356 |
|
357 |
+
elif ControlNet_Model == "17":
|
358 |
+
mdllnk = list(filter(lambda x: "t2i" in x, mdllnk))
|
359 |
+
for lnk in mdllnk:
|
360 |
+
download(lnk, mdldir)
|
361 |
+
clear_output()
|
362 |
+
|
363 |
+
elif (
|
364 |
+
ControlNet_Model.isdigit()
|
365 |
+
and int(ControlNet_Model) - 1 < 16
|
366 |
+
and int(ControlNet_Model) > 0
|
367 |
+
):
|
368 |
+
download(mdllnk[int(ControlNet_Model) - 1], mdldir)
|
369 |
+
clear_output()
|
370 |
|
|
|
|
|
|
|
|
|
371 |
elif ControlNet_Model == "none":
|
372 |
+
pass
|
373 |
+
clear_output()
|
374 |
|
375 |
else:
|
376 |
+
print("[1;31mWrong ControlNet V1 choice, try again")
|
377 |
+
wrngv1 = True
|
378 |
|
379 |
+
if ControlNet_XL_Model == "All" or ControlNet_XL_Model == "all":
|
380 |
+
for lnk_XL in mdllnk_XL:
|
381 |
+
download(lnk_XL, mdldir)
|
382 |
+
if not wrngv1:
|
383 |
+
clear_output()
|
384 |
+
done()
|
385 |
|
386 |
+
elif ControlNet_XL_Model.isdigit() and int(ControlNet_XL_Model) - 1 < 5:
|
387 |
+
download(mdllnk_XL[int(ControlNet_XL_Model) - 1], mdldir)
|
388 |
+
if not wrngv1:
|
389 |
+
clear_output()
|
390 |
+
done()
|
|
|
391 |
|
|
|
|
|
|
|
|
|
|
|
|
|
392 |
elif ControlNet_XL_Model == "none":
|
393 |
+
pass
|
394 |
+
if not wrngv1:
|
395 |
+
clear_output()
|
396 |
+
done()
|
397 |
|
398 |
else:
|
399 |
+
print("[1;31mWrong ControlNet XL choice, try again")
|
|
|
|
|
400 |
|
401 |
def sd(User, Password, model):
|
402 |
|
|
|
443 |
mdlpth="--ckpt "+model
|
444 |
else:
|
445 |
mdlpth="--ckpt-dir "+model
|
446 |
+
vae_path = "--vae-path /workspace/sd/stable-diffusion-webui/models/VAE/vae-ft-mse-840000-ema-pruned.safetensors"
|
447 |
+
configf="--disable-console-progressbars --no-half-vae --disable-safe-unpickle --api --no-download-sd-model --opt-sdp-attention --enable-insecure-extension-access --skip-version-check --listen --port 3000 "+auth+" "+mdlpth+" "+vae_path
|
448 |
|
449 |
return configf
|
450 |
|
|
|
533 |
content_disposition = six.moves.urllib_parse.unquote(res.headers["Content-Disposition"])
|
534 |
filenm = re.search('attachment; filename="(.*?)"', content_disposition).groups()[0]
|
535 |
return filenm
|
536 |
+
def download_and_install_config():
|
537 |
+
target_directory = "/workspace/sd/stable-diffusion-webui/"
|
538 |
+
config_url = (
|
539 |
+
"https://huggingface.co/spaces/stlaurentjr/RNPD/raw/main/config/config.json"
|
540 |
+
)
|
541 |
+
config_file_path = os.path.join(target_directory, "config.json")
|
542 |
+
|
543 |
+
# Check if the config file already exists
|
544 |
+
if not os.path.exists(config_file_path):
|
545 |
+
# Change the directory
|
546 |
+
os.chdir(target_directory)
|
547 |
+
# Download the file using curl command
|
548 |
+
call(f"curl -o config.json {config_url}", shell=True)
|
549 |
+
print(f"Config file downloaded successfully.")
|
550 |
+
else:
|
551 |
+
print("Config file already exists, download skipped.")
|
552 |
+
|
553 |
+
|
554 |
+
def InstallDeforum():
|
555 |
+
# Переход в директорию расширений
|
556 |
+
os.chdir("/workspace/sd/stable-diffusion-webui/extensions")
|
557 |
|
558 |
+
# Проверка наличия директории с расширением
|
559 |
+
if not os.path.exists("deforum-for-automatic1111-webui"):
|
560 |
+
# Клонирование репозитория, если он не существует
|
561 |
+
call(
|
562 |
+
"git clone https://github.com/deforum-art/sd-webui-deforum.git", shell=True
|
563 |
+
)
|
564 |
+
# Возврат в корневую директорию
|
565 |
+
os.chdir("/workspace")
|
566 |
+
else:
|
567 |
+
# Если директория существует, переходим в нее
|
568 |
+
# os.chdir('deforum-for-automatic1111-webui')
|
569 |
+
# Сброс изменений и обновление репозитория
|
570 |
+
# call('git reset --hard', shell=True, stdout=open(os.devnull, 'w'), stderr=open(os.devnull, 'w'))
|
571 |
+
# call('git pull', shell=True, stdout=open(os.devnull, 'w'), stderr=open(os.devnull, 'w'))
|
572 |
+
# Возврат в корневую директорию
|
573 |
+
os.chdir("/workspace")
|
574 |
+
|
575 |
+
def InstallReActor():
|
576 |
+
# Переход в директорию расширений
|
577 |
+
os.chdir("/workspace/sd/stable-diffusion-webui/extensions")
|
578 |
+
# Проверка наличия директории с расширением
|
579 |
+
if not os.path.exists("sd-webui-reactor"):
|
580 |
+
# Установка библиотек
|
581 |
+
from subprocess import call, DEVNULL
|
582 |
+
call(
|
583 |
+
'pip install "onnxruntime-gpu>=1.16.1"',
|
584 |
+
shell=True
|
585 |
+
)
|
586 |
+
# Клонирование репозитория, если он не существует
|
587 |
+
call(
|
588 |
+
"git clone https://github.com/Gourieff/sd-webui-reactor.git",
|
589 |
+
shell=True,
|
590 |
+
)
|
591 |
+
# Создание папки под модели
|
592 |
+
call(
|
593 |
+
"mkdir /workspace/sd/stable-diffusion-webui/models/insightface",
|
594 |
+
shell=True
|
595 |
+
)
|
596 |
+
os.chdir("/workspace/sd/stable-diffusion-webui/models/insightface")
|
597 |
+
# Скачивание модели для reActor
|
598 |
+
call(
|
599 |
+
"wget https://github.com/facefusion/facefusion-assets/releases/download/models/inswapper_128.onnx",
|
600 |
+
shell=True,
|
601 |
+
stdout=DEVNULL,
|
602 |
+
stderr=DEVNULL
|
603 |
+
)
|
604 |
+
# Вовзрат в корневую директорию
|
605 |
+
clear_output()
|
606 |
+
os.chdir("/workspace")
|
607 |
+
else:
|
608 |
+
#Возврат в корневую директорию
|
609 |
+
os.chdir("/workspace")
|
610 |
+
|
611 |
+
def InstallAnimateDiff():
|
612 |
+
# Переход в директорию расширений
|
613 |
+
os.chdir("/workspace/sd/stable-diffusion-webui/extensions")
|
614 |
+
|
615 |
+
# Проверка наличия директории с расширением
|
616 |
+
if not os.path.exists("sd-webui-animatediff"):
|
617 |
+
from subprocess import call, DEVNULL
|
618 |
+
# Клонирование репозитория, если он не существует
|
619 |
+
call(
|
620 |
+
"git clone https://github.com/continue-revolution/sd-webui-animatediff.git",
|
621 |
+
shell=True,
|
622 |
+
)
|
623 |
+
# Переход в папку с моделями
|
624 |
+
os.chdir(
|
625 |
+
"/workspace/sd/stable-diffusion-webui/extensions/sd-webui-animatediff/model"
|
626 |
+
)
|
627 |
+
# Скачивание моделей для animatediff
|
628 |
+
call(
|
629 |
+
"wget https://huggingface.co/guoyww/animatediff/resolve/refs%2Fpr%2F3/mm_sd_v15_v2.ckpt",
|
630 |
+
shell=True,
|
631 |
+
stdout=DEVNULL,
|
632 |
+
stderr=DEVNULL
|
633 |
+
)
|
634 |
+
# call(
|
635 |
+
# "wget https://huggingface.co/manshoety/AD_Stabilized_Motion/resolve/main/mm-Stabilized_high.pth",
|
636 |
+
# shell=True,
|
637 |
+
# stdout=DEVNULL,
|
638 |
+
# stderr=DEVNULL
|
639 |
+
# )
|
640 |
+
# Вовзрат в корневую директорию
|
641 |
+
clear_output()
|
642 |
+
os.chdir("/workspace")
|
643 |
+
else:
|
644 |
+
# Возврат в корневую директорию
|
645 |
+
os.chdir("/workspace")
|
646 |
+
|
647 |
+
def InstallWildCards():
|
648 |
+
# Путь к целевой директории
|
649 |
+
target_dir = "/workspace/sd/stable-diffusion-webui/extensions/stable-diffusion-webui-wildcards/wildcards/"
|
650 |
+
|
651 |
+
# Перемещаемся в директорию расширений
|
652 |
+
os.chdir("/workspace/sd/stable-diffusion-webui/extensions")
|
653 |
+
|
654 |
+
if not os.path.exists("stable-diffusion-webui-wildcards"):
|
655 |
+
# Клонирование репозитория, если он ещё не существует
|
656 |
+
call(
|
657 |
+
"git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-wildcards.git",
|
658 |
+
shell=True,
|
659 |
+
)
|
660 |
+
|
661 |
+
# Перемещаемся в клонированный репозиторий
|
662 |
+
os.chdir("stable-diffusion-webui-wildcards")
|
663 |
+
|
664 |
+
# Скачиваем файл по ID
|
665 |
+
gdown.download(
|
666 |
+
id="1sY9Yv29cCYZuxBvszkmLVgw--aRdwT1P", output="wildcards.zip", quiet=False
|
667 |
+
)
|
668 |
+
|
669 |
+
# Создаем целевую директорию, если она ещё не существует
|
670 |
+
os.makedirs(target_dir, exist_ok=True)
|
671 |
+
|
672 |
+
# Распаковываем архив
|
673 |
+
with zipfile.ZipFile("wildcards.zip", "r") as zip_ref:
|
674 |
+
zip_ref.extractall(target_dir)
|
675 |
+
else:
|
676 |
+
# Если репозиторий уже существует, обновляем его
|
677 |
+
os.chdir("stable-diffusion-webui-wildcards")
|
678 |
+
call(
|
679 |
+
"git reset --hard",
|
680 |
+
shell=True,
|
681 |
+
stdout=open(os.devnull, "w"),
|
682 |
+
stderr=open(os.devnull, "w"),
|
683 |
+
)
|
684 |
+
call(
|
685 |
+
"git pull",
|
686 |
+
shell=True,
|
687 |
+
stdout=open(os.devnull, "w"),
|
688 |
+
stderr=open(os.devnull, "w"),
|
689 |
+
)
|
690 |
+
|
691 |
+
# Возвращаемся в исходную рабочую директорию
|
692 |
+
os.chdir("/workspace")
|
693 |
|
694 |
|
695 |
|