Delete sd-model-downloader
Browse files
sd-model-downloader/README.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
| 1 |
-
# sd-model-downloader
|
| 2 |
-
SD Web UI Extension to Download Model from URL
|
| 3 |
-
|
| 4 |
-
# This Extension Work on AUTO1111 SD Webui
|
| 5 |
-
|
| 6 |
-
To install it, clone the repo into the `extensions` directory and run terminal:<br>
|
| 7 |
-
`git clone https://github.com/Iyashinouta/sd-model-downloader /content/stable-diffusion-webui/extensions/sd-model-downloader`
|
| 8 |
-
|
| 9 |
-
or Install from SD Webui:<br>
|
| 10 |
-
install from URL, and Paste Link https://github.com/Iyashinouta/sd-model-downloader
|
| 11 |
-
|
| 12 |
-
# Instructions
|
| 13 |
-
|
| 14 |
-
<details><summary>tap to see image</summary>
|
| 15 |
-
|
| 16 |
-

|
| 17 |
-
|
| 18 |
-
</details>
|
| 19 |
-
|
| 20 |
-
# Update fix/features
|
| 21 |
-
|
| 22 |
-
<details><summary>
|
| 23 |
-
See Releases for more details
|
| 24 |
-
</summary>
|
| 25 |
-
|
| 26 |
-
- June 14, 2023<br>
|
| 27 |
-
- bug fix = fix `NoneType` variables from <a href=https://github.com/Iyashinouta/sd-model-downloader/issues/8#issue-1751439968>YKefasu<br>
|
| 28 |
-
- rollback features = Filename features finally back again<br>
|
| 29 |
-
- May 30, 2023<br>
|
| 30 |
-
- bug fix : path fix<br>
|
| 31 |
-
- bug fix : downloading `card-no-preview.png` if not exist
|
| 32 |
-
- May 28, 2023<br>
|
| 33 |
-
- adding features : save to <a href=https://github.com/kohya-ss/sd-webui-additional-networks>AddNet Extension</a><br>
|
| 34 |
-
- optimizing fix : more stable, though in latest version on webui<br>
|
| 35 |
-
- May 26, 2023<br>
|
| 36 |
-
- optimizing fix : fix performance when reading information<br>
|
| 37 |
-
- May 22, 2023<br>
|
| 38 |
-
- bug fix : getting error while downloading Huggingface<br>
|
| 39 |
-
|
| 40 |
-
- May 21, 2023<br>
|
| 41 |
-
- adding feature : show image preview model and save to thumbnail<br>
|
| 42 |
-
- fix : re-organize ui<br>
|
| 43 |
-
|
| 44 |
-
- May 12, 2023<br>
|
| 45 |
-
- adding features : submit url/filename<br>
|
| 46 |
-
- bug fix : path fix<br>
|
| 47 |
-
|
| 48 |
-
</details>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sd-model-downloader/images/card-no-prev.png
DELETED
|
Binary file (84.4 kB)
|
|
|
sd-model-downloader/images/instructions.png
DELETED
Git LFS Details
|
sd-model-downloader/install.py
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import launch
|
| 3 |
-
import platform
|
| 4 |
-
import subprocess
|
| 5 |
-
|
| 6 |
-
def checking():
|
| 7 |
-
try:
|
| 8 |
-
subprocess.run("aria2c", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 9 |
-
return True
|
| 10 |
-
except FileNotFoundError:
|
| 11 |
-
return False
|
| 12 |
-
|
| 13 |
-
if platform.system() == "Linux":
|
| 14 |
-
if not checking():
|
| 15 |
-
launch.run("apt update && apt -y install -qq aria2", "Installing requirements for Model Downloader")
|
| 16 |
-
else:
|
| 17 |
-
pass
|
| 18 |
-
elif platform.system() == "Darwin":
|
| 19 |
-
if not checking():
|
| 20 |
-
launch.run("brew install aria2", "Installing requirements for Model Downloader")
|
| 21 |
-
else:
|
| 22 |
-
pass
|
| 23 |
-
elif platform.system() == "Windows":
|
| 24 |
-
if not checking():
|
| 25 |
-
print("Model Downloader required aria2c, see tutorial https://www.youtube.com/watch?v=JnWQST4ay_E")
|
| 26 |
-
else:
|
| 27 |
-
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sd-model-downloader/model-downloader.py
DELETED
|
@@ -1,257 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import requests
|
| 3 |
-
import argparse
|
| 4 |
-
import subprocess
|
| 5 |
-
import gradio as gr
|
| 6 |
-
from install import checking
|
| 7 |
-
from urllib.parse import urlparse
|
| 8 |
-
from modules import scripts, script_callbacks
|
| 9 |
-
try:
|
| 10 |
-
from modules.paths_internal import data_path, models_path, extensions_dir
|
| 11 |
-
except ImportError:
|
| 12 |
-
from modules.paths import data_path, models_path
|
| 13 |
-
extensions_dir = os.path.join(data_path, 'extensions')
|
| 14 |
-
|
| 15 |
-
sd_path = os.getcwd()
|
| 16 |
-
ext = '/extensions'
|
| 17 |
-
no_prev = None
|
| 18 |
-
addnet_path = None
|
| 19 |
-
md_path = scripts.basedir()
|
| 20 |
-
|
| 21 |
-
parser = argparse.ArgumentParser()
|
| 22 |
-
parser.add_argument('--ckpt-dir', type=str, default=os.path.join(models_path, 'Stable-diffusion'))
|
| 23 |
-
parser.add_argument('--vae-dir', type=str, default=os.path.join(models_path, 'VAE'))
|
| 24 |
-
parser.add_argument('--embeddings-dir', type=str, default=os.path.join(data_path, 'embeddings'))
|
| 25 |
-
parser.add_argument('--hypernetwork-dir', type=str, default=os.path.join(models_path, 'hypernetworks'))
|
| 26 |
-
parser.add_argument('--lora-dir', type=str, default=os.path.join(models_path, 'Lora'))
|
| 27 |
-
parser.add_argument('--lyco-dir', type=str, default=os.path.join(models_path, 'LyCORIS'))
|
| 28 |
-
args, _ = parser.parse_known_args()
|
| 29 |
-
|
| 30 |
-
if not os.path.exists(os.path.join(sd_path, 'html', 'card-no-preview.png')):
|
| 31 |
-
try:
|
| 32 |
-
no_prev = os.path.join(md_path, 'images', 'card-no-prev.png')
|
| 33 |
-
except:
|
| 34 |
-
pass
|
| 35 |
-
else:
|
| 36 |
-
no_prev = os.path.join(sd_path, 'html', 'card-no-preview.png')
|
| 37 |
-
if not os.path.exists(os.path.join(sd_path, ext, 'sd-webui-additional-networks')):
|
| 38 |
-
addnet_path = os.path.join(extensions_dir, 'sd-webui-additional-networks')
|
| 39 |
-
else:
|
| 40 |
-
addnet_path = os.path.join(sd_path, ext, 'sd-webui-additional-networks')
|
| 41 |
-
|
| 42 |
-
checkpoint_path = args.ckpt_dir
|
| 43 |
-
vae_path = args.vae_dir
|
| 44 |
-
embedding_path = args.embeddings_dir
|
| 45 |
-
hypernetwork_path = args.hypernetwork_dir
|
| 46 |
-
lora_path = args.lora_dir
|
| 47 |
-
lycoris_path = args.lyco_dir
|
| 48 |
-
controlnet_path = os.path.join(extensions_dir, 'sd-webui-controlnet')
|
| 49 |
-
controlnet_model_path = os.path.join(controlnet_path, 'models')
|
| 50 |
-
|
| 51 |
-
print(f'Model Downloader v1.0.6 fixed')
|
| 52 |
-
print('Checking Directories...')
|
| 53 |
-
if not os.path.exists(checkpoint_path):
|
| 54 |
-
os.makedirs(checkpoint_path)
|
| 55 |
-
print ('Creating Checkpoint Folder')
|
| 56 |
-
if not os.path.exists(hypernetwork_path):
|
| 57 |
-
os.makedirs(hypernetwork_path)
|
| 58 |
-
print ('Creating Hypernetwork Folder')
|
| 59 |
-
if not os.path.exists(embedding_path):
|
| 60 |
-
os.makedirs(embedding_path)
|
| 61 |
-
print ('Creating TextualInversion/Embeddings Folder')
|
| 62 |
-
if not os.path.exists(vae_path):
|
| 63 |
-
os.makedirs(vae_path)
|
| 64 |
-
print ('Creating VAE Folder')
|
| 65 |
-
if not os.path.exists(lora_path):
|
| 66 |
-
os.makedirs(lora_path)
|
| 67 |
-
print ('Creating LoRA Folder')
|
| 68 |
-
if not os.path.exists(lycoris_path):
|
| 69 |
-
os.makedirs(lycoris_path)
|
| 70 |
-
print ('Creating LyCORIS Folder')
|
| 71 |
-
else:
|
| 72 |
-
pass
|
| 73 |
-
print('all Directories already Created.')
|
| 74 |
-
|
| 75 |
-
def folder(content_type):
|
| 76 |
-
if content_type == 'Checkpoint':
|
| 77 |
-
downloadpath = checkpoint_path
|
| 78 |
-
elif content_type == 'Hypernetwork':
|
| 79 |
-
downloadpath = hypernetwork_path
|
| 80 |
-
elif content_type == 'TextualInversion/Embedding':
|
| 81 |
-
downloadpath = embedding_path
|
| 82 |
-
elif content_type == 'VAE':
|
| 83 |
-
downloadpath = vae_path
|
| 84 |
-
elif content_type == 'LoRA':
|
| 85 |
-
downloadpath = lora_path
|
| 86 |
-
elif content_type == 'LyCORIS(LoCon/LoHA)':
|
| 87 |
-
downloadpath = lycoris_path
|
| 88 |
-
elif content_type == 'ControlNet Model':
|
| 89 |
-
downloadpath = controlnet_model_path
|
| 90 |
-
else:
|
| 91 |
-
downloadpath = 'Unset, Please Choose your Content Type'
|
| 92 |
-
return downloadpath
|
| 93 |
-
|
| 94 |
-
def get_filename_from_url(url):
|
| 95 |
-
if url.find('https://civitai.com/')!=-1:
|
| 96 |
-
convert = '' + url.replace('download/models', 'v1/model-versions')
|
| 97 |
-
req = requests.get(convert, stream=True)
|
| 98 |
-
basename, extension = os.path.splitext(req.json()['files'][0]['name'].replace(' ', '_'))
|
| 99 |
-
else:
|
| 100 |
-
parse = urlparse(url).path
|
| 101 |
-
req = parse[parse.rfind('/') + 1:].replace(' ', '_')
|
| 102 |
-
basename, extension = os.path.splitext(req)
|
| 103 |
-
return basename, extension
|
| 104 |
-
|
| 105 |
-
def get_image_from_url(url):
|
| 106 |
-
if url.find('https://civitai.com/')!=-1:
|
| 107 |
-
convert = '' + url.replace('download/models', 'v1/model-versions')
|
| 108 |
-
req = requests.get(convert, stream=True)
|
| 109 |
-
imgurl = req.json()['images'][0]['url']
|
| 110 |
-
else:
|
| 111 |
-
imgurl = no_prev
|
| 112 |
-
return imgurl
|
| 113 |
-
|
| 114 |
-
def change_name(changename):
|
| 115 |
-
if changename:
|
| 116 |
-
filename = gr.Textbox.update(visible=True)
|
| 117 |
-
else:
|
| 118 |
-
filename = gr.Textbox.update(visible=False)
|
| 119 |
-
return filename
|
| 120 |
-
|
| 121 |
-
def get_data_from_url(url, downloadpath):
|
| 122 |
-
try:
|
| 123 |
-
imgurl = get_image_from_url(url)
|
| 124 |
-
basename, extension = get_filename_from_url(url)
|
| 125 |
-
markdown2 = f'''
|
| 126 |
-
<font size=2>
|
| 127 |
-
<b>Modle File Name :</b> {basename}{extension}<br>
|
| 128 |
-
'''
|
| 129 |
-
except:
|
| 130 |
-
imgurl = no_prev
|
| 131 |
-
markdown2 = f'''
|
| 132 |
-
<font size=2>
|
| 133 |
-
<b>Modle File Name :</b> ???
|
| 134 |
-
'''
|
| 135 |
-
filename = gr.Textbox.update(basename)
|
| 136 |
-
image = gr.Image.update(imgurl)
|
| 137 |
-
download_btn = gr.Button.update(visible=True, variant='primary')
|
| 138 |
-
out_text = gr.Textbox.update('Ready', visible=True)
|
| 139 |
-
info = gr.Markdown.update(markdown2)
|
| 140 |
-
return filename, image, download_btn, out_text, info
|
| 141 |
-
|
| 142 |
-
def start_downloading(download_btn, url, downloadpath, filename, addnet, logging):
|
| 143 |
-
complete1 = f'SUCCESS: Download Completed, Saved to\n'
|
| 144 |
-
complete2 = f'ERROR: File Already Exist in\n'
|
| 145 |
-
complete3 = 'ERROR: Something went wrong, please try again later'
|
| 146 |
-
path, extension = get_filename_from_url(url)
|
| 147 |
-
imgname = f'{filename}.preview.png'
|
| 148 |
-
if url.find('https://civitai.com/')!=-1:
|
| 149 |
-
target1 = f'{downloadpath}/{filename}'
|
| 150 |
-
target2 = f'{addnet_path}/models/lora/{filename}'
|
| 151 |
-
else:
|
| 152 |
-
target1 = f'{downloadpath}'
|
| 153 |
-
target2 = f'{addnet_path}/models/lora'
|
| 154 |
-
final_target = None
|
| 155 |
-
if addnet:
|
| 156 |
-
final_target = target2
|
| 157 |
-
else:
|
| 158 |
-
final_target = target1
|
| 159 |
-
with open('model.txt', 'w') as w:
|
| 160 |
-
if not url.find('https://civitai.com/')!=-1:
|
| 161 |
-
w.write(f'{url}\n out={filename}{extension}')
|
| 162 |
-
else:
|
| 163 |
-
imgurl = get_image_from_url(url)
|
| 164 |
-
w.write(f'{url}\n out={filename}{extension}\n{imgurl}\n out={imgname}')
|
| 165 |
-
command = f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M --input-file model.txt -d {final_target}'
|
| 166 |
-
back(download_btn)
|
| 167 |
-
if not os.path.exists(os.path.join(final_target, filename)):
|
| 168 |
-
try:
|
| 169 |
-
if logging:
|
| 170 |
-
command.replace(f' --console-log-level=error', '')
|
| 171 |
-
line = subprocess.getoutput(command)
|
| 172 |
-
yield line
|
| 173 |
-
print(line)
|
| 174 |
-
else:
|
| 175 |
-
line = os.popen(command)
|
| 176 |
-
for l in line:
|
| 177 |
-
l = l.rstrip()
|
| 178 |
-
yield f'{complete1}{final_target}'
|
| 179 |
-
print(f'{complete1}{final_target}')
|
| 180 |
-
except Exception:
|
| 181 |
-
yield f'{Exception}\n{complete3}'
|
| 182 |
-
print(f'{Exception}\n{complete3}')
|
| 183 |
-
else:
|
| 184 |
-
yield f'{complete2}{final_target}'
|
| 185 |
-
print(f'{complete2}{final_target}')
|
| 186 |
-
|
| 187 |
-
def back(download_btn):
|
| 188 |
-
return gr.Button.update(visible=True, variant='secondary')
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
def on_ui_tabs():
|
| 192 |
-
with gr.Blocks() as downloader:
|
| 193 |
-
with gr.Row():
|
| 194 |
-
content_type = gr.Radio(
|
| 195 |
-
label='1. Choose Content type',
|
| 196 |
-
choices=[
|
| 197 |
-
'Checkpoint',
|
| 198 |
-
'Hypernetwork',
|
| 199 |
-
'TextualInversion/Embedding',
|
| 200 |
-
'VAE',
|
| 201 |
-
'LoRA',
|
| 202 |
-
'LyCORIS(LoCon/LoHA)',
|
| 203 |
-
'ControlNet Model'
|
| 204 |
-
]
|
| 205 |
-
)
|
| 206 |
-
with gr.Row():
|
| 207 |
-
with gr.Column():
|
| 208 |
-
with gr.Row():
|
| 209 |
-
downloadpath = gr.Textbox(visible=False)
|
| 210 |
-
addnet = gr.Checkbox(label='save to Additional Networks', value=False, visible=True)
|
| 211 |
-
logging = gr.Checkbox(label='turn on log', value=False)
|
| 212 |
-
changename = gr.Checkbox(label='Change Filename', value=False)
|
| 213 |
-
url = gr.Textbox(
|
| 214 |
-
label='2. Put Link Download Below',
|
| 215 |
-
max_lines=1, placeholder='Type/Paste URL Here'
|
| 216 |
-
)
|
| 217 |
-
filename = gr.Textbox(
|
| 218 |
-
label='Change Filename',
|
| 219 |
-
placeholder='Filename',
|
| 220 |
-
visible=False
|
| 221 |
-
)
|
| 222 |
-
download_btn = gr.Button(
|
| 223 |
-
'Start Download',
|
| 224 |
-
variant='secondary'
|
| 225 |
-
)
|
| 226 |
-
out_text = gr.Textbox(
|
| 227 |
-
label='Download Result',
|
| 228 |
-
placeholder='Result'
|
| 229 |
-
)
|
| 230 |
-
with gr.Column():
|
| 231 |
-
info = gr.Markdown(
|
| 232 |
-
'''
|
| 233 |
-
<font size=2>
|
| 234 |
-
<b>Modle File Name : </b>
|
| 235 |
-
'''
|
| 236 |
-
)
|
| 237 |
-
with gr.Row():
|
| 238 |
-
image = gr.Image(value=no_prev, show_label=False)
|
| 239 |
-
image.style(height=305)
|
| 240 |
-
with gr.Row():
|
| 241 |
-
github = gr.Markdown(
|
| 242 |
-
'''
|
| 243 |
-
<center><font size=2>Having Issue? |
|
| 244 |
-
<a href=https://github.com/Iyashinouta/sd-model-downloader/issues>Report Here</a><br>
|
| 245 |
-
<center><font size=1>Model Downloader v1.0.6 fixed
|
| 246 |
-
'''
|
| 247 |
-
)
|
| 248 |
-
content_type.change(folder, content_type, downloadpath)
|
| 249 |
-
changename.change(change_name, changename, filename)
|
| 250 |
-
url.change(get_data_from_url, [url, downloadpath], [filename, image, download_btn, out_text, info])
|
| 251 |
-
download_btn.click(start_downloading, [download_btn, url, downloadpath, filename, addnet, logging], out_text)
|
| 252 |
-
url.submit(start_downloading, [download_btn, url, downloadpath, filename, addnet, logging], out_text)
|
| 253 |
-
download_btn.click(back, download_btn, download_btn)
|
| 254 |
-
url.submit(back, url, download_btn)
|
| 255 |
-
return (downloader, 'Model Downloader', 'downloader'),
|
| 256 |
-
|
| 257 |
-
script_callbacks.on_ui_tabs(on_ui_tabs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sd-model-downloader/scripts/model-downloader.py
DELETED
|
@@ -1,257 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import requests
|
| 3 |
-
import argparse
|
| 4 |
-
import subprocess
|
| 5 |
-
import gradio as gr
|
| 6 |
-
from install import checking
|
| 7 |
-
from urllib.parse import urlparse
|
| 8 |
-
from modules import scripts, script_callbacks
|
| 9 |
-
try:
|
| 10 |
-
from modules.paths_internal import data_path, models_path, extensions_dir
|
| 11 |
-
except ImportError:
|
| 12 |
-
from modules.paths import data_path, models_path
|
| 13 |
-
extensions_dir = os.path.join(data_path, 'extensions')
|
| 14 |
-
|
| 15 |
-
sd_path = os.getcwd()
|
| 16 |
-
ext = '/extensions'
|
| 17 |
-
no_prev = None
|
| 18 |
-
addnet_path = None
|
| 19 |
-
md_path = scripts.basedir()
|
| 20 |
-
|
| 21 |
-
parser = argparse.ArgumentParser()
|
| 22 |
-
parser.add_argument('--ckpt-dir', type=str, default=os.path.join(models_path, 'Stable-diffusion'))
|
| 23 |
-
parser.add_argument('--vae-dir', type=str, default=os.path.join(models_path, 'VAE'))
|
| 24 |
-
parser.add_argument('--embeddings-dir', type=str, default=os.path.join(data_path, 'embeddings'))
|
| 25 |
-
parser.add_argument('--hypernetwork-dir', type=str, default=os.path.join(models_path, 'hypernetworks'))
|
| 26 |
-
parser.add_argument('--lora-dir', type=str, default=os.path.join(models_path, 'Lora'))
|
| 27 |
-
parser.add_argument('--lyco-dir', type=str, default=os.path.join(models_path, 'LyCORIS'))
|
| 28 |
-
args, _ = parser.parse_known_args()
|
| 29 |
-
|
| 30 |
-
if not os.path.exists(os.path.join(sd_path, 'html', 'card-no-preview.png')):
|
| 31 |
-
try:
|
| 32 |
-
no_prev = os.path.join(md_path, 'images', 'card-no-prev.png')
|
| 33 |
-
except:
|
| 34 |
-
pass
|
| 35 |
-
else:
|
| 36 |
-
no_prev = os.path.join(sd_path, 'html', 'card-no-preview.png')
|
| 37 |
-
if not os.path.exists(os.path.join(sd_path, ext, 'sd-webui-additional-networks')):
|
| 38 |
-
addnet_path = os.path.join(extensions_dir, 'sd-webui-additional-networks')
|
| 39 |
-
else:
|
| 40 |
-
addnet_path = os.path.join(sd_path, ext, 'sd-webui-additional-networks')
|
| 41 |
-
|
| 42 |
-
checkpoint_path = args.ckpt_dir
|
| 43 |
-
vae_path = args.vae_dir
|
| 44 |
-
embedding_path = args.embeddings_dir
|
| 45 |
-
hypernetwork_path = args.hypernetwork_dir
|
| 46 |
-
lora_path = args.lora_dir
|
| 47 |
-
lycoris_path = args.lyco_dir
|
| 48 |
-
controlnet_path = os.path.join(extensions_dir, 'sd-webui-controlnet')
|
| 49 |
-
controlnet_model_path = os.path.join(controlnet_path, 'models')
|
| 50 |
-
|
| 51 |
-
print(f'Model Downloader v1.0.6 fixed')
|
| 52 |
-
print('Checking Directories...')
|
| 53 |
-
if not os.path.exists(checkpoint_path):
|
| 54 |
-
os.makedirs(checkpoint_path)
|
| 55 |
-
print ('Creating Checkpoint Folder')
|
| 56 |
-
if not os.path.exists(hypernetwork_path):
|
| 57 |
-
os.makedirs(hypernetwork_path)
|
| 58 |
-
print ('Creating Hypernetwork Folder')
|
| 59 |
-
if not os.path.exists(embedding_path):
|
| 60 |
-
os.makedirs(embedding_path)
|
| 61 |
-
print ('Creating TextualInversion/Embeddings Folder')
|
| 62 |
-
if not os.path.exists(vae_path):
|
| 63 |
-
os.makedirs(vae_path)
|
| 64 |
-
print ('Creating VAE Folder')
|
| 65 |
-
if not os.path.exists(lora_path):
|
| 66 |
-
os.makedirs(lora_path)
|
| 67 |
-
print ('Creating LoRA Folder')
|
| 68 |
-
if not os.path.exists(lycoris_path):
|
| 69 |
-
os.makedirs(lycoris_path)
|
| 70 |
-
print ('Creating LyCORIS Folder')
|
| 71 |
-
else:
|
| 72 |
-
pass
|
| 73 |
-
print('all Directories already Created.')
|
| 74 |
-
|
| 75 |
-
def folder(content_type):
|
| 76 |
-
if content_type == 'Checkpoint':
|
| 77 |
-
downloadpath = checkpoint_path
|
| 78 |
-
elif content_type == 'Hypernetwork':
|
| 79 |
-
downloadpath = hypernetwork_path
|
| 80 |
-
elif content_type == 'TextualInversion/Embedding':
|
| 81 |
-
downloadpath = embedding_path
|
| 82 |
-
elif content_type == 'VAE':
|
| 83 |
-
downloadpath = vae_path
|
| 84 |
-
elif content_type == 'LoRA':
|
| 85 |
-
downloadpath = lora_path
|
| 86 |
-
elif content_type == 'LyCORIS(LoCon/LoHA)':
|
| 87 |
-
downloadpath = lycoris_path
|
| 88 |
-
elif content_type == 'ControlNet Model':
|
| 89 |
-
downloadpath = controlnet_model_path
|
| 90 |
-
else:
|
| 91 |
-
downloadpath = 'Unset, Please Choose your Content Type'
|
| 92 |
-
return downloadpath
|
| 93 |
-
|
| 94 |
-
def get_filename_from_url(url):
|
| 95 |
-
if url.find('https://civitai.com/')!=-1:
|
| 96 |
-
convert = '' + url.replace('download/models', 'v1/model-versions')
|
| 97 |
-
req = requests.get(convert, stream=True)
|
| 98 |
-
basename, extension = os.path.splitext(req.json()['files'][0]['name'].replace(' ', '_'))
|
| 99 |
-
else:
|
| 100 |
-
parse = urlparse(url).path
|
| 101 |
-
req = parse[parse.rfind('/') + 1:].replace(' ', '_')
|
| 102 |
-
basename, extension = os.path.splitext(req)
|
| 103 |
-
return basename, extension
|
| 104 |
-
|
| 105 |
-
def get_image_from_url(url):
|
| 106 |
-
if url.find('https://civitai.com/')!=-1:
|
| 107 |
-
convert = '' + url.replace('download/models', 'v1/model-versions')
|
| 108 |
-
req = requests.get(convert, stream=True)
|
| 109 |
-
imgurl = req.json()['images'][0]['url']
|
| 110 |
-
else:
|
| 111 |
-
imgurl = no_prev
|
| 112 |
-
return imgurl
|
| 113 |
-
|
| 114 |
-
def change_name(changename):
|
| 115 |
-
if changename:
|
| 116 |
-
filename = gr.Textbox.update(visible=True)
|
| 117 |
-
else:
|
| 118 |
-
filename = gr.Textbox.update(visible=False)
|
| 119 |
-
return filename
|
| 120 |
-
|
| 121 |
-
def get_data_from_url(url, downloadpath):
|
| 122 |
-
try:
|
| 123 |
-
imgurl = get_image_from_url(url)
|
| 124 |
-
basename, extension = get_filename_from_url(url)
|
| 125 |
-
markdown2 = f'''
|
| 126 |
-
<font size=2>
|
| 127 |
-
<b>Modle File Name :</b> {basename}{extension}<br>
|
| 128 |
-
'''
|
| 129 |
-
except:
|
| 130 |
-
imgurl = no_prev
|
| 131 |
-
markdown2 = f'''
|
| 132 |
-
<font size=2>
|
| 133 |
-
<b>Modle File Name :</b> ???
|
| 134 |
-
'''
|
| 135 |
-
filename = gr.Textbox.update(basename)
|
| 136 |
-
image = gr.Image.update(imgurl)
|
| 137 |
-
download_btn = gr.Button.update(visible=True, variant='primary')
|
| 138 |
-
out_text = gr.Textbox.update('Ready', visible=True)
|
| 139 |
-
info = gr.Markdown.update(markdown2)
|
| 140 |
-
return filename, image, download_btn, out_text, info
|
| 141 |
-
|
| 142 |
-
def start_downloading(download_btn, url, downloadpath, filename, addnet, logging):
|
| 143 |
-
complete1 = f'SUCCESS: Download Completed, Saved to\n'
|
| 144 |
-
complete2 = f'ERROR: File Already Exist in\n'
|
| 145 |
-
complete3 = 'ERROR: Something went wrong, please try again later'
|
| 146 |
-
path, extension = get_filename_from_url(url)
|
| 147 |
-
imgname = f'{filename}.preview.png'
|
| 148 |
-
if url.find('https://civitai.com/')!=-1:
|
| 149 |
-
target1 = f'{downloadpath}/{filename}'
|
| 150 |
-
target2 = f'{addnet_path}/models/lora/{filename}'
|
| 151 |
-
else:
|
| 152 |
-
target1 = f'{downloadpath}'
|
| 153 |
-
target2 = f'{addnet_path}/models/lora'
|
| 154 |
-
final_target = None
|
| 155 |
-
if addnet:
|
| 156 |
-
final_target = target2
|
| 157 |
-
else:
|
| 158 |
-
final_target = target1
|
| 159 |
-
with open('model.txt', 'w') as w:
|
| 160 |
-
if not url.find('https://civitai.com/')!=-1:
|
| 161 |
-
w.write(f'{url}\n out={filename}{extension}')
|
| 162 |
-
else:
|
| 163 |
-
imgurl = get_image_from_url(url)
|
| 164 |
-
w.write(f'{url}\n out={filename}{extension}\n{imgurl}\n out={imgname}')
|
| 165 |
-
command = f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M --input-file model.txt -d {final_target}'
|
| 166 |
-
back(download_btn)
|
| 167 |
-
if not os.path.exists(os.path.join(final_target, filename)):
|
| 168 |
-
try:
|
| 169 |
-
if logging:
|
| 170 |
-
command.replace(f' --console-log-level=error', '')
|
| 171 |
-
line = subprocess.getoutput(command)
|
| 172 |
-
yield line
|
| 173 |
-
print(line)
|
| 174 |
-
else:
|
| 175 |
-
line = os.popen(command)
|
| 176 |
-
for l in line:
|
| 177 |
-
l = l.rstrip()
|
| 178 |
-
yield f'{complete1}{final_target}'
|
| 179 |
-
print(f'{complete1}{final_target}')
|
| 180 |
-
except Exception:
|
| 181 |
-
yield f'{Exception}\n{complete3}'
|
| 182 |
-
print(f'{Exception}\n{complete3}')
|
| 183 |
-
else:
|
| 184 |
-
yield f'{complete2}{final_target}'
|
| 185 |
-
print(f'{complete2}{final_target}')
|
| 186 |
-
|
| 187 |
-
def back(download_btn):
|
| 188 |
-
return gr.Button.update(visible=True, variant='secondary')
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
def on_ui_tabs():
|
| 192 |
-
with gr.Blocks() as downloader:
|
| 193 |
-
with gr.Row():
|
| 194 |
-
content_type = gr.Radio(
|
| 195 |
-
label='1. Choose Content type',
|
| 196 |
-
choices=[
|
| 197 |
-
'Checkpoint',
|
| 198 |
-
'Hypernetwork',
|
| 199 |
-
'TextualInversion/Embedding',
|
| 200 |
-
'VAE',
|
| 201 |
-
'LoRA',
|
| 202 |
-
'LyCORIS(LoCon/LoHA)',
|
| 203 |
-
'ControlNet Model'
|
| 204 |
-
]
|
| 205 |
-
)
|
| 206 |
-
with gr.Row():
|
| 207 |
-
with gr.Column():
|
| 208 |
-
with gr.Row():
|
| 209 |
-
downloadpath = gr.Textbox(visible=False)
|
| 210 |
-
addnet = gr.Checkbox(label='save to Additional Networks', value=False, visible=True)
|
| 211 |
-
logging = gr.Checkbox(label='turn on log', value=False)
|
| 212 |
-
changename = gr.Checkbox(label='Change Filename', value=False)
|
| 213 |
-
url = gr.Textbox(
|
| 214 |
-
label='2. Put Link Download Below',
|
| 215 |
-
max_lines=1, placeholder='Type/Paste URL Here'
|
| 216 |
-
)
|
| 217 |
-
filename = gr.Textbox(
|
| 218 |
-
label='Change Filename',
|
| 219 |
-
placeholder='Filename',
|
| 220 |
-
visible=False
|
| 221 |
-
)
|
| 222 |
-
download_btn = gr.Button(
|
| 223 |
-
'Start Download',
|
| 224 |
-
variant='secondary'
|
| 225 |
-
)
|
| 226 |
-
out_text = gr.Textbox(
|
| 227 |
-
label='Download Result',
|
| 228 |
-
placeholder='Result'
|
| 229 |
-
)
|
| 230 |
-
with gr.Column():
|
| 231 |
-
info = gr.Markdown(
|
| 232 |
-
'''
|
| 233 |
-
<font size=2>
|
| 234 |
-
<b>Modle File Name : </b>
|
| 235 |
-
'''
|
| 236 |
-
)
|
| 237 |
-
with gr.Row():
|
| 238 |
-
image = gr.Image(value=no_prev, show_label=False)
|
| 239 |
-
image.style(height=305)
|
| 240 |
-
with gr.Row():
|
| 241 |
-
github = gr.Markdown(
|
| 242 |
-
'''
|
| 243 |
-
<center><font size=2>Having Issue? |
|
| 244 |
-
<a href=https://github.com/Iyashinouta/sd-model-downloader/issues>Report Here</a><br>
|
| 245 |
-
<center><font size=1>Model Downloader v1.0.6 fixed
|
| 246 |
-
'''
|
| 247 |
-
)
|
| 248 |
-
content_type.change(folder, content_type, downloadpath)
|
| 249 |
-
changename.change(change_name, changename, filename)
|
| 250 |
-
url.change(get_data_from_url, [url, downloadpath], [filename, image, download_btn, out_text, info])
|
| 251 |
-
download_btn.click(start_downloading, [download_btn, url, downloadpath, filename, addnet, logging], out_text)
|
| 252 |
-
url.submit(start_downloading, [download_btn, url, downloadpath, filename, addnet, logging], out_text)
|
| 253 |
-
download_btn.click(back, download_btn, download_btn)
|
| 254 |
-
url.submit(back, url, download_btn)
|
| 255 |
-
return (downloader, 'Model Downloader', 'downloader'),
|
| 256 |
-
|
| 257 |
-
script_callbacks.on_ui_tabs(on_ui_tabs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|