webui / app2.py
salomonsky's picture
Update app2.py
8176758
import os
import subprocess
import pathlib
import gc
def Gitclone(URI:str, ClonePath:str = "") -> int:
if ClonePath == "":
while True:
i = subprocess.run(["git", "clone", URI])
if i.returncode == 0:
del i
gc.collect()
return 0
else:
del i
else:
while True:
i = subprocess.run(["git", "clone", URI, ClonePath])
if i.returncode == 0:
del i
gc.collect()
return 0
else:
del i
import os
from sys import executable as pyexecutable
import subprocess
import pathlib
import gc
def Gitclone(URI:str,ClonePath:str = "") -> int :
if(ClonePath == "") :
while True:
i=subprocess.run([r"git",r"clone",URI])
if(i.returncode == 0 ):
del i
gc.collect()
return 0
else :
del i
else:
while True:
i=subprocess.run([r"git",r"clone",URI,ClonePath])
if(i.returncode == 0 ):
del i
gc.collect()
return 0
else :
del i
def DownLoad(URI:str,DownloadPath:str,DownLoadFileName:str ) -> int:
while (True):
i=subprocess.run([r"aria2c",r"-c",r"-x" ,r"16", r"-s",r"16", r"-k" ,r"1M" ,r"-m",r"0",r"--enable-mmap=false",r"--console-log-level=error",r"-d",DownloadPath,r"-o",DownLoadFileName,URI]);
if(i.returncode == 0 ):
del i
gc.collect()
return 0
else :
del i
user_home = pathlib.Path("/kaggle/working/").resolve()
os.chdir(str(user_home))
def clone_repository(repo_url, target_dir):
if not os.path.exists(target_dir):
subprocess.run(["git", "clone", repo_url, target_dir])
else:
print(f"El directorio {target_dir} ya existe. Omitiendo la clonación.")
Gitclone(r"https://github.com/AUTOMATIC1111/stable-diffusion-webui.git",str(user_home / r"webui" / r"stable-diffusion-webui"))
os.chdir(str(user_home / r"webui" / r"stable-diffusion-webui"))
os.system("git reset --hard 89f9faa63388756314e8a1d96cf86bf5e0663045")
print("installing extensions")
Gitclone(r"https://huggingface.co/embed/negative",str(user_home / r"webui" / r"stable-diffusion-webui" / r"embeddings" / r"negative"))
Gitclone(r"https://huggingface.co/embed/lora",str(user_home / r"webui" / r"stable-diffusion-webui" / r"models" / r"Lora" / r"positive"))
DownLoad(r"https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth",str(user_home / r"webui" / r"stable-diffusion-webui" / r"models" / r"ESRGAN") ,r"4x-UltraSharp.pth")
while True:
if(subprocess.run([r"wget",r"https://raw.githubusercontent.com/camenduru/stable-diffusion-webui-scripts/main/run_n_times.py",r"-O",str(user_home / r"webui" / r"stable-diffusion-webui" / r"scripts" / r"run_n_times.py")]).returncode == 0):
break
Gitclone(r"https://github.com/deforum-art/deforum-for-automatic1111-webui",str(user_home / r"webui" / r"stable-diffusion-webui" / r"extensions" / r"deforum-for-automatic1111-webui" ))
Gitclone(r"https://github.com/camenduru/stable-diffusion-webui-huggingface",str(user_home / r"webui" / r"stable-diffusion-webui" / r"extensions" / r"stable-diffusion-webui-huggingface"))
Gitclone(r"https://github.com/camenduru/sd-civitai-browser",str(user_home / r"webui" / r"stable-diffusion-webui" / r"extensions" / r"sd-civitai-browser"))
Gitclone(r"https://github.com/kohya-ss/sd-webui-additional-networks",str(user_home / r"webui" / r"stable-diffusion-webui" / r"extensions" / r"sd-webui-additional-networks"))
Gitclone(r"https://github.com/Mikubill/sd-webui-controlnet",str(user_home / r"webui" / r"stable-diffusion-webui" / r"extensions" / r"sd-webui-controlnet"))
Gitclone(r"https://github.com/fkunn1326/openpose-editor",str(user_home / r"webui" / r"stable-diffusion-webui" / r"extensions" / r"openpose-editor"))
Gitclone(r"https://github.com/jexom/sd-webui-depth-lib",str(user_home / r"webui" / r"stable-diffusion-webui" / r"extensions" / r"sd-webui-depth-lib"))
Gitclone(r"https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git" , str(user_home / r"webui" / r"stable-diffusion-webui" / r"extensions" / r"a1111-sd-webui-tagcomplete"))
Gitclone(r"https://github.com/camenduru/sd-webui-tunnels",str(user_home / r"webui" / r"stable-diffusion-webui" / r"extensions" / r"sd-webui-tunnels"))
os.chdir(user_home / r"webui" / r"stable-diffusion-webui")
print("extensions dolwnload done .\ndownloading ControlNet models")
dList =[r"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors",
r"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors",
r"https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_zoedepth_sd15v1.pth"]
for i in range(0,len(dList)): DownLoad(dList[i],str(user_home / r"webui" / "stable-diffusion-webui" / "extensions" / "sd-webui-controlnet" / "models"),pathlib.Path(dList[i]).name)
del dList
print("ControlNet models download done.\ndownloading model")
DownLoad(r"https://huggingface.co/dreamlike-art/dreamlike-photoreal-2.0/resolve/main/dreamlike-photoreal-2.0.safetensors",str(user_home / r"webui" / r"stable-diffusion-webui" / r"models" / r"Stable-diffusion"),r"dreamlike-photoreal-2.0.safetensors")
DownLoad(r"https://huggingface.co/dreamlike-art/dreamlike-anime-1.0/resolve/main/dreamlike-anime-1.0.safetensors",str(user_home / r"webui" / r"stable-diffusion-webui" / r"models" / r"Stable-diffusion"),r"dreamlike-anime-1.0.safetensors")
DownLoad(r"https://civitai.com/api/download/models/39885",str(user_home / r"webui" / r"stable-diffusion-webui" / r"extensions" / r"sd-webui-additional-networks" / r"models"/ r"lora"),r"Better_light.safetensors")
DownLoad(r"https://civitai.com/api/download/models/21065",str(user_home / r"webui" / r"stable-diffusion-webui" / r"extensions" / r"sd-webui-additional-networks" / r"models"/ r"lora"),r"LAS.safetensors")
DownLoad(r"https://civitai.com/api/download/models/39164",str(user_home / r"webui" / r"stable-diffusion-webui" / r"extensions" / r"sd-webui-additional-networks" / r"models"/ r"lora"),r"backlighting.safetensors")
print("Done\nStarting Webui...")
os.chdir(user_home / r"webui" / r"stable-diffusion-webui")
while True:
ret=subprocess.run([r"python3" ,r"launch.py",r"--precision",r"full",r"--no-half",r"--no-half-vae",r"--enable-insecure-extension-access",r"--medvram",r"--share",r"--enable-console-prompts",r"--ui-settings-file="+str(pathlib.Path(__file__).parent /r"config.json")])
if(ret.returncode == 0 ):
del ret
gc.collect()
else :
del ret