Question - ControlNet - update

#8
by AIClaudioAI - opened

Hi all,

How can I update my Google collab? I guess that I was not using the last control net version:

The default colab of https://github.com/TheLastBen/fast-stable-diffusion is not updated:

#@markdown # ControlNet
from torch.hub import download_url_to_file
from urllib.parse import urlparse
import re
from subprocess import run

Model = "All (21GB)" #@param [ "None", "All (21GB)", "Canny", "Depth", "Lineart", "MLSD", "Normal", "OpenPose", "Scribble", "Seg", "ip2p", "Shuffle", "Inpaint", "Softedge", "Lineart_Anime", "Tile", "T2iadapter_Models"]

v2_Model = "All" #@param [ "None", "All", "Canny", "Depth", "HED", "OpenPose", "Scribble"]

#@markdown - Download/update ControlNet extension and its models

def download(url, model_dir):

filename = os.path.basename(urlparse(url).path)
pth = os.path.abspath(os.path.join(model_dir, filename))
if not os.path.exists(pth):
    print('Downloading: '+os.path.basename(url))
    download_url_to_file(url, pth, hash_prefix=None, progress=True)
else:
  print(f"The model {filename} already exists")

Canny='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth'
Depth='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth'
Lineart='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth'
MLSD='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd.pth'
Normal='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae.pth'
OpenPose='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth'
Scribble='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble.pth'
Seg='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg.pth'
ip2p='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p.pth'
Shuffle='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle.pth'
Inpaint='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint.pth'
Softedge='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge.pth'
Lineart_Anime='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime.pth'
Tile='https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth'

with capture.capture_output() as cap:
%cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/extensions
if not os.path.exists("sd-webui-controlnet"):
!git clone https://github.com/Mikubill/sd-w$blasphemy-controlnet.git
%cd /content
else:
%cd sd-w$blasphemy-controlnet
!git reset --hard
!git pull
%cd /content

mdldir='/content/gdrive/'+mainpth+'/sd/stable-diffusion-w'+blasphemy+'/extensions/sd-w'+blasphemy+'-controlnet/models'
for filename in os.listdir(mdldir):
if "_sd14v1" in filename:
renamed = re.sub("_sd14v1", "-fp16", filename)
os.rename(os.path.join(mdldir, filename), os.path.join(mdldir, renamed))

!wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models.txt
!wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_v2.txt

with open("CN_models.txt", 'r') as f:
mdllnk = f.read().splitlines()
with open("CN_models_v2.txt", 'r') as d:
mdllnk_v2 = d.read().splitlines()

!rm CN_models.txt CN_models_v2.txt

with capture.capture_output() as cap:
cfgnames=[os.path.basename(url).split('.')[0]+'.yaml' for url in mdllnk_v2]
%cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blasphemy/extensions/sd-w$blasphemy-controlnet/models
for name in cfgnames:
run(['cp', 'cldm_v21.yaml', name])
%cd /content

if Model == "All (21GB)":
for lnk in mdllnk:
download(lnk, mdldir)
clear_output()

elif Model == "T2iadapter_Models":
mdllnk=list(filter(lambda x: 't2i' in x, mdllnk))
for lnk in mdllnk:
download(lnk, mdldir)
clear_output()

elif Model == "None":
pass
clear_output()

else:
download(globals()[Model], mdldir)
clear_output()

Canny='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_canny.safetensors'
Depth='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_depth.safetensors'
HED='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_hed.safetensors'
OpenPose='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_openposev2.safetensors'
Scribble='https://huggingface.co/thibaud/controlnet-sd21/resolve/main/control_v11p_sd21_scribble.safetensors'

if v2_Model == "All":
for lnk_v2 in mdllnk_v2:
download(lnk_v2, mdldir)
clear_output()
inf('\u2714 Done','success', '50px')

elif v2_Model == "None":
pass
clear_output()
inf('\u2714 Done','success', '50px')

else:
download(globals()[v2_Model], mdldir)
clear_output()
inf('\u2714 Done','success', '50px')

#@markdown ---

Sign up or log in to comment