Upload 2 files
Browse files- scripts/model-downloader---.py +369 -0
- scripts/model-downloader.py +111 -146
scripts/model-downloader---.py
ADDED
@@ -0,0 +1,369 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
import argparse
|
4 |
+
import subprocess
|
5 |
+
import gradio as gr
|
6 |
+
from urllib.parse import urlparse
|
7 |
+
from modules import scripts, script_callbacks
|
8 |
+
try:
|
9 |
+
from modules.paths_internal import data_path, models_path, extensions_dir
|
10 |
+
except ImportError:
|
11 |
+
from modules.paths import data_path, models_path
|
12 |
+
extensions_dir = os.path.join(data_path, 'extensions')
|
13 |
+
|
14 |
+
sd_path = os.getcwd()
|
15 |
+
ext = '/extensions'
|
16 |
+
no_prev = None
|
17 |
+
addnet_path = None
|
18 |
+
md_path = scripts.basedir()
|
19 |
+
|
20 |
+
parser = argparse.ArgumentParser()
|
21 |
+
parser.add_argument('--ckpt-dir', type=str, default=os.path.join(models_path, 'Stable-diffusion'))
|
22 |
+
parser.add_argument('--vae-dir', type=str, default=os.path.join(models_path, 'VAE'))
|
23 |
+
parser.add_argument('--embeddings-dir', type=str, default=os.path.join(data_path, 'embeddings'))
|
24 |
+
parser.add_argument('--hypernetwork-dir', type=str, default=os.path.join(models_path, 'hypernetworks'))
|
25 |
+
parser.add_argument('--lora-dir', type=str, default=os.path.join(models_path, 'Lora'))
|
26 |
+
parser.add_argument('--lyco-dir', type=str, default=os.path.join(models_path, 'LyCORIS'))
|
27 |
+
args, _ = parser.parse_known_args()
|
28 |
+
|
29 |
+
if not os.path.exists(os.path.join(sd_path, 'html', 'card-no-preview.png')):
|
30 |
+
try:
|
31 |
+
no_prev = os.path.join(md_path, 'images', 'card-no-prev.png')
|
32 |
+
except:
|
33 |
+
pass
|
34 |
+
else:
|
35 |
+
no_prev = os.path.join(sd_path, 'html', 'card-no-preview.png')
|
36 |
+
if not os.path.exists(os.path.join(sd_path, ext, 'sd-webui-additional-networks')):
|
37 |
+
addnet_path = os.path.join(extensions_dir, 'sd-webui-additional-networks')
|
38 |
+
else:
|
39 |
+
addnet_path = os.path.join(sd_path, ext, 'sd-webui-additional-networks')
|
40 |
+
|
41 |
+
checkpoint_path = args.ckpt_dir
|
42 |
+
vae_path = args.vae_dir
|
43 |
+
embedding_path = args.embeddings_dir
|
44 |
+
hypernetwork_path = args.hypernetwork_dir
|
45 |
+
lora_path = args.lora_dir
|
46 |
+
lycoris_path = args.lyco_dir
|
47 |
+
controlnet_path = os.path.join(extensions_dir, 'sd-webui-controlnet')
|
48 |
+
controlnet_model_path = os.path.join(controlnet_path, 'models')
|
49 |
+
|
50 |
+
print(f'Model Downloader v1.0.8 Pre')
|
51 |
+
print('Checking Directories...')
|
52 |
+
if not os.path.exists(checkpoint_path):
|
53 |
+
os.makedirs(checkpoint_path)
|
54 |
+
print ('Creating Checkpoint Folder')
|
55 |
+
if not os.path.exists(hypernetwork_path):
|
56 |
+
os.makedirs(hypernetwork_path)
|
57 |
+
print ('Creating Hypernetwork Folder')
|
58 |
+
if not os.path.exists(embedding_path):
|
59 |
+
os.makedirs(embedding_path)
|
60 |
+
print ('Creating TextualInversion/Embeddings Folder')
|
61 |
+
if not os.path.exists(vae_path):
|
62 |
+
os.makedirs(vae_path)
|
63 |
+
print ('Creating VAE Folder')
|
64 |
+
if not os.path.exists(lora_path):
|
65 |
+
os.makedirs(lora_path)
|
66 |
+
print ('Creating LoRA Folder')
|
67 |
+
if not os.path.exists(lycoris_path):
|
68 |
+
os.makedirs(lycoris_path)
|
69 |
+
print ('Creating LyCORIS Folder')
|
70 |
+
else:
|
71 |
+
pass
|
72 |
+
print('all Directories already Created.')
|
73 |
+
|
74 |
+
def folder(content_type):
|
75 |
+
if content_type == 'Checkpoint':
|
76 |
+
downloadpath = checkpoint_path
|
77 |
+
elif content_type == 'Hypernetwork':
|
78 |
+
downloadpath = hypernetwork_path
|
79 |
+
elif content_type == 'TextualInversion/Embedding':
|
80 |
+
downloadpath = embedding_path
|
81 |
+
elif content_type == 'VAE':
|
82 |
+
downloadpath = vae_path
|
83 |
+
elif content_type == 'LoRA':
|
84 |
+
downloadpath = lora_path
|
85 |
+
elif content_type == 'LyCORIS(LoCon/LoHA)':
|
86 |
+
downloadpath = lycoris_path
|
87 |
+
elif content_type == 'ControlNet Model':
|
88 |
+
downloadpath = controlnet_model_path
|
89 |
+
else:
|
90 |
+
downloadpath = 'Unset, Please Choose your Content Type'
|
91 |
+
return downloadpath
|
92 |
+
|
93 |
+
def get_filename_from_url(url):
|
94 |
+
if url.find('https://civitai.com/')!=-1:
|
95 |
+
convert = '' + url.replace('download/models', 'v1/model-versions')
|
96 |
+
req = requests.get(convert, stream=True)
|
97 |
+
basename, extension = os.path.splitext(req.json()['files'][0]['name'].replace(' ', '_'))
|
98 |
+
else:
|
99 |
+
parse = urlparse(url).path
|
100 |
+
req = parse[parse.rfind('/') + 1:].replace(' ', '_')
|
101 |
+
basename, extension = os.path.splitext(req)
|
102 |
+
return basename, extension
|
103 |
+
|
104 |
+
def get_image_from_url(url):
|
105 |
+
if url.find('https://civitai.com/')!=-1:
|
106 |
+
convert = '' + url.replace('download/models', 'v1/model-versions')
|
107 |
+
req = requests.get(convert, stream=True)
|
108 |
+
imgurl = req.json()['images'][0]['url']
|
109 |
+
else:
|
110 |
+
imgurl = no_prev
|
111 |
+
return imgurl
|
112 |
+
|
113 |
+
def change_name(changename):
|
114 |
+
if changename:
|
115 |
+
filename = gr.Textbox.update(visible=True)
|
116 |
+
else:
|
117 |
+
filename = gr.Textbox.update(visible=False)
|
118 |
+
return filename
|
119 |
+
|
120 |
+
def custom_download_path(custompath):
|
121 |
+
if custompath:
|
122 |
+
downloadpath = gr.Textbox.update(visible=True)
|
123 |
+
else:
|
124 |
+
downloadpath = gr.Textbox.update(visible=False)
|
125 |
+
return downloadpath
|
126 |
+
|
127 |
+
def get_data_from_url(url, downloadpath):
|
128 |
+
try:
|
129 |
+
imgurl = get_image_from_url(url)
|
130 |
+
basename, extension = get_filename_from_url(url)
|
131 |
+
markdown2 = f'''
|
132 |
+
<font size=2>
|
133 |
+
<center><b>Model Information</b><br></center>
|
134 |
+
<b>URL :</b> {url}<br>
|
135 |
+
<b>Folder Path :</b> {downloadpath}<br>
|
136 |
+
<b>File Name :</b> {basename}{extension}<br>
|
137 |
+
'''
|
138 |
+
except:
|
139 |
+
imgurl = no_prev
|
140 |
+
markdown2 = f'''
|
141 |
+
<font size=2>
|
142 |
+
<center><b>Model Information</b><br></center>
|
143 |
+
<b>URL :</b> {url}<br>
|
144 |
+
<b>Folder Path :</b> {downloadpath}<br>
|
145 |
+
<b>File Name :</b> ???
|
146 |
+
'''
|
147 |
+
filename = gr.Textbox.update(basename)
|
148 |
+
image = gr.Image.update(imgurl)
|
149 |
+
download_btn = gr.Button.update(visible=True, variant='primary')
|
150 |
+
out_text = gr.Textbox.update('Ready', visible=True)
|
151 |
+
info = gr.Markdown.update(markdown2)
|
152 |
+
return filename, image, download_btn, out_text, info
|
153 |
+
|
154 |
+
def start_downloading(downloader_type, download_btn, url, downloadpath, filename, addnet, logging, new_folder, preview):
|
155 |
+
complete1 = f'SUCCESS: Download Completed, Saved to\n'
|
156 |
+
complete2 = f'ERROR: File Already Exist in\n'
|
157 |
+
complete3 = 'ERROR: Something went wrong, please try again later'
|
158 |
+
path, extension = get_filename_from_url(url)
|
159 |
+
imgname = f'{filename}.preview.png'
|
160 |
+
if new_folder:
|
161 |
+
target1 = os.path.join(downloadpath, filename)
|
162 |
+
target2 = os.path.join(addnet_path, 'models', 'lora', filename)
|
163 |
+
else:
|
164 |
+
target1 = os.path.join(downloadpath)
|
165 |
+
target2 = os.path.join(addnet_path, 'models', 'lora')
|
166 |
+
final_target = None
|
167 |
+
if addnet:
|
168 |
+
final_target = target2
|
169 |
+
else:
|
170 |
+
final_target = target1
|
171 |
+
back(download_btn)
|
172 |
+
if not os.path.exists(os.path.join(final_target, f'{filename}{extension}')):
|
173 |
+
try:
|
174 |
+
if downloader_type == 'aria2':
|
175 |
+
command = f'aria2c -c -x 16 -s 16 -k 1M --input-file model.txt -d {final_target}'
|
176 |
+
with open('model.txt', 'w') as w:
|
177 |
+
if not url.find('https://civitai.com/')!=-1:
|
178 |
+
w.write(f'{url}\n out={filename}{extension}')
|
179 |
+
else:
|
180 |
+
if preview:
|
181 |
+
imgurl = get_image_from_url(url)
|
182 |
+
w.write(f'{url}\n out={filename}{extension}\n{imgurl}\n out={imgname}')
|
183 |
+
else:
|
184 |
+
w.write(f'{url}\n out={filename}{extension}')
|
185 |
+
if logging:
|
186 |
+
line = subprocess.getoutput(command)
|
187 |
+
yield line
|
188 |
+
print(line)
|
189 |
+
else:
|
190 |
+
line = os.popen(command)
|
191 |
+
for l in line:
|
192 |
+
l = l.rstrip()
|
193 |
+
yield f'{complete1}{final_target}'
|
194 |
+
print(f'{complete1}{final_target}')
|
195 |
+
elif downloader_type == 'requests':
|
196 |
+
if new_folder:
|
197 |
+
os.makedirs(final_target, exist_ok=True)
|
198 |
+
else:
|
199 |
+
pass
|
200 |
+
download = requests.get(url, allow_redirects=True)
|
201 |
+
if not url.find('https://civitai.com/')!=-1:
|
202 |
+
with open(os.path.join(final_target, f'{filename}{extension}'), 'wb') as f:
|
203 |
+
f.write(download.content)
|
204 |
+
else:
|
205 |
+
if preview:
|
206 |
+
imgurl = get_image_from_url(url)
|
207 |
+
img_download = requests.get(str(imgurl), allow_redirects=True)
|
208 |
+
with open(os.path.join(final_target, f'{filename}{extension}'), 'wb') as f:
|
209 |
+
f.write(download.content)
|
210 |
+
with open(os.path.join(final_target, imgname), 'wb') as img:
|
211 |
+
img.write(img_download.content)
|
212 |
+
else:
|
213 |
+
with open(os.path.join(final_target, f'{filename}{extension}'), 'wb') as f:
|
214 |
+
f.write(download.content)
|
215 |
+
yield f'{complete1}{final_target}'
|
216 |
+
print(f'{complete1}{final_target}')
|
217 |
+
except Exception as e:
|
218 |
+
yield f'{e}\n{complete3}'
|
219 |
+
print(f'{e}\n{complete3}')
|
220 |
+
else:
|
221 |
+
yield f'{complete2}{final_target}'
|
222 |
+
print(f'{complete2}{final_target}')
|
223 |
+
|
224 |
+
def back(download_btn):
|
225 |
+
return gr.Button.update(visible=True, variant='secondary')
|
226 |
+
|
227 |
+
def on_ui_tabs():
|
228 |
+
with gr.Blocks() as downloader:
|
229 |
+
with gr.Row():
|
230 |
+
with gr.Column():
|
231 |
+
downloader_type = gr.Radio(
|
232 |
+
label='Downloader Type',
|
233 |
+
choices=[
|
234 |
+
'aria2',
|
235 |
+
'requests'
|
236 |
+
],
|
237 |
+
value='aria2',
|
238 |
+
type='value'
|
239 |
+
)
|
240 |
+
with gr.Row():
|
241 |
+
content_type = gr.Radio(
|
242 |
+
label='1. Choose Content Type',
|
243 |
+
choices=[
|
244 |
+
'Checkpoint',
|
245 |
+
'Hypernetwork',
|
246 |
+
'TextualInversion/Embedding',
|
247 |
+
'VAE',
|
248 |
+
'LoRA',
|
249 |
+
'LyCORIS(LoCon/LoHA)',
|
250 |
+
'ControlNet Model'
|
251 |
+
]
|
252 |
+
)
|
253 |
+
addnet = None
|
254 |
+
if os.path.exists(addnet_path):
|
255 |
+
addnet = gr.Checkbox(label='save to Additional Networks', value=False, visible=True)
|
256 |
+
print('Model Downloader detects Additional Networks, creating checkbox for AddNet.')
|
257 |
+
else:
|
258 |
+
addnet = gr.Checkbox(value=False, visible=False)
|
259 |
+
with gr.Row():
|
260 |
+
with gr.Column():
|
261 |
+
url = gr.Textbox(
|
262 |
+
label='2. Put Link Download Below',
|
263 |
+
max_lines=1, placeholder='Type/Paste URL Here'
|
264 |
+
)
|
265 |
+
downloadpath = gr.Textbox(
|
266 |
+
value='Unset, Please Choose your Content Type',
|
267 |
+
label='Custom Download Path',
|
268 |
+
placeholder='Paste Folder Path Here',
|
269 |
+
visible=False
|
270 |
+
)
|
271 |
+
filename = gr.Textbox(
|
272 |
+
label='Change Filename',
|
273 |
+
placeholder='Filename',
|
274 |
+
visible=False
|
275 |
+
)
|
276 |
+
with gr.Row():
|
277 |
+
logging = gr.Checkbox(label='turn on log', value=False)
|
278 |
+
changename = gr.Checkbox(label='Change Filename', value=False)
|
279 |
+
custompath = gr.Checkbox(label='Custom Download Path', value=False)
|
280 |
+
preview = gr.Checkbox(label='Download Preview', value=True)
|
281 |
+
new_folder = gr.Checkbox(label='Create New Folder', value=False)
|
282 |
+
with gr.Row():
|
283 |
+
with gr.Column():
|
284 |
+
download_btn = gr.Button(
|
285 |
+
'Start Download',
|
286 |
+
visible=False,
|
287 |
+
variant='secondary'
|
288 |
+
)
|
289 |
+
out_text = gr.Textbox(
|
290 |
+
label='Download Result',
|
291 |
+
placeholder='Result',
|
292 |
+
visible=False,
|
293 |
+
)
|
294 |
+
with gr.Row():
|
295 |
+
with gr.Column():
|
296 |
+
info = gr.Markdown(
|
297 |
+
'''
|
298 |
+
<font size=2>
|
299 |
+
<center><b>Model Information</b><br></center>
|
300 |
+
<b>URL :</b><br>
|
301 |
+
<b>Folder Path :</b><br>
|
302 |
+
<b>File Name :</b>
|
303 |
+
'''
|
304 |
+
)
|
305 |
+
with gr.Column():
|
306 |
+
prev_markdown = gr.Markdown('''<font size=2><b>Preview Model :</b>''')
|
307 |
+
image = gr.Image(value=no_prev, show_label=False)
|
308 |
+
image.style(width=156, height=234)
|
309 |
+
with gr.Row():
|
310 |
+
github = gr.Markdown(
|
311 |
+
'''
|
312 |
+
<center><font size=2>Having Issue? |
|
313 |
+
<a href=https://github.com/Iyashinouta/sd-model-downloader/issues>
|
314 |
+
Report Here</a><br>
|
315 |
+
<center><font size=1>Model Downloader v1.0.8 Pre
|
316 |
+
'''
|
317 |
+
)
|
318 |
+
content_type.change(folder, content_type, downloadpath)
|
319 |
+
changename.change(change_name, changename, filename)
|
320 |
+
custompath.change(custom_download_path, custompath, downloadpath)
|
321 |
+
url.change(
|
322 |
+
get_data_from_url,
|
323 |
+
[
|
324 |
+
url,
|
325 |
+
downloadpath
|
326 |
+
],
|
327 |
+
[
|
328 |
+
filename,
|
329 |
+
image,
|
330 |
+
download_btn,
|
331 |
+
out_text,
|
332 |
+
info
|
333 |
+
]
|
334 |
+
)
|
335 |
+
download_btn.click(
|
336 |
+
start_downloading,
|
337 |
+
[
|
338 |
+
downloader_type,
|
339 |
+
download_btn,
|
340 |
+
url,
|
341 |
+
downloadpath,
|
342 |
+
filename,
|
343 |
+
addnet,
|
344 |
+
logging,
|
345 |
+
new_folder,
|
346 |
+
preview
|
347 |
+
],
|
348 |
+
out_text
|
349 |
+
)
|
350 |
+
url.submit(
|
351 |
+
start_downloading,
|
352 |
+
[
|
353 |
+
downloader_type,
|
354 |
+
download_btn,
|
355 |
+
url,
|
356 |
+
downloadpath,
|
357 |
+
filename,
|
358 |
+
addnet,
|
359 |
+
logging,
|
360 |
+
new_folder,
|
361 |
+
preview
|
362 |
+
],
|
363 |
+
out_text
|
364 |
+
)
|
365 |
+
download_btn.click(back, download_btn, download_btn)
|
366 |
+
url.submit(back, url, download_btn)
|
367 |
+
return (downloader, 'Model Downloader', 'downloader'),
|
368 |
+
|
369 |
+
script_callbacks.on_ui_tabs(on_ui_tabs)
|
scripts/model-downloader.py
CHANGED
@@ -130,24 +130,22 @@ def get_data_from_url(url, downloadpath):
|
|
130 |
basename, extension = get_filename_from_url(url)
|
131 |
markdown2 = f'''
|
132 |
<font size=2>
|
133 |
-
<
|
134 |
-
<b
|
135 |
-
<b
|
136 |
-
<b>File Name :</b> {basename}{extension}<br>
|
137 |
'''
|
138 |
except:
|
139 |
imgurl = no_prev
|
140 |
markdown2 = f'''
|
141 |
<font size=2>
|
142 |
-
<
|
143 |
-
<b
|
144 |
-
<b
|
145 |
-
<b>File Name :</b> ???
|
146 |
'''
|
147 |
filename = gr.Textbox.update(basename)
|
148 |
image = gr.Image.update(imgurl)
|
149 |
download_btn = gr.Button.update(visible=True, variant='primary')
|
150 |
-
out_text = gr.Textbox.update('Ready', visible=True)
|
151 |
info = gr.Markdown.update(markdown2)
|
152 |
return filename, image, download_btn, out_text, info
|
153 |
|
@@ -222,148 +220,115 @@ def start_downloading(downloader_type, download_btn, url, downloadpath, filename
|
|
222 |
print(f'{complete2}{final_target}')
|
223 |
|
224 |
def back(download_btn):
|
225 |
-
return gr.Button.update(visible=True, variant='
|
226 |
|
227 |
def on_ui_tabs():
|
228 |
with gr.Blocks() as downloader:
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
label='1. Choose Content Type',
|
243 |
-
choices=[
|
244 |
-
'Checkpoint',
|
245 |
-
'Hypernetwork',
|
246 |
-
'TextualInversion/Embedding',
|
247 |
-
'VAE',
|
248 |
-
'LoRA',
|
249 |
-
'LyCORIS(LoCon/LoHA)',
|
250 |
-
'ControlNet Model'
|
251 |
-
]
|
252 |
-
)
|
253 |
-
addnet = None
|
254 |
-
if os.path.exists(addnet_path):
|
255 |
-
addnet = gr.Checkbox(label='save to Additional Networks', value=False, visible=True)
|
256 |
-
print('Model Downloader detects Additional Networks, creating checkbox for AddNet.')
|
257 |
-
else:
|
258 |
-
addnet = gr.Checkbox(value=False, visible=False)
|
259 |
-
with gr.Row():
|
260 |
-
with gr.Column():
|
261 |
-
url = gr.Textbox(
|
262 |
-
label='2. Put Link Download Below',
|
263 |
-
max_lines=1, placeholder='Type/Paste URL Here'
|
264 |
-
)
|
265 |
-
downloadpath = gr.Textbox(
|
266 |
-
value='Unset, Please Choose your Content Type',
|
267 |
-
label='Custom Download Path',
|
268 |
-
placeholder='Paste Folder Path Here',
|
269 |
-
visible=False
|
270 |
-
)
|
271 |
-
filename = gr.Textbox(
|
272 |
-
label='Change Filename',
|
273 |
-
placeholder='Filename',
|
274 |
-
visible=False
|
275 |
-
)
|
276 |
-
with gr.Row():
|
277 |
-
logging = gr.Checkbox(label='turn on log', value=False)
|
278 |
-
changename = gr.Checkbox(label='Change Filename', value=False)
|
279 |
-
custompath = gr.Checkbox(label='Custom Download Path', value=False)
|
280 |
-
preview = gr.Checkbox(label='Download Preview', value=True)
|
281 |
-
new_folder = gr.Checkbox(label='Create New Folder', value=False)
|
282 |
-
with gr.Row():
|
283 |
-
with gr.Column():
|
284 |
-
download_btn = gr.Button(
|
285 |
-
'Start Download',
|
286 |
-
visible=False,
|
287 |
-
variant='secondary'
|
288 |
-
)
|
289 |
-
out_text = gr.Textbox(
|
290 |
-
label='Download Result',
|
291 |
-
placeholder='Result',
|
292 |
-
visible=False,
|
293 |
-
)
|
294 |
-
with gr.Row():
|
295 |
-
with gr.Column():
|
296 |
-
info = gr.Markdown(
|
297 |
-
'''
|
298 |
-
<font size=2>
|
299 |
-
<center><b>Model Information</b><br></center>
|
300 |
-
<b>URL :</b><br>
|
301 |
-
<b>Folder Path :</b><br>
|
302 |
-
<b>File Name :</b>
|
303 |
-
'''
|
304 |
-
)
|
305 |
-
with gr.Column():
|
306 |
-
prev_markdown = gr.Markdown('''<font size=2><b>Preview Model :</b>''')
|
307 |
-
image = gr.Image(value=no_prev, show_label=False)
|
308 |
-
image.style(width=156, height=234)
|
309 |
-
with gr.Row():
|
310 |
-
github = gr.Markdown(
|
311 |
-
'''
|
312 |
-
<center><font size=2>Having Issue? |
|
313 |
-
<a href=https://github.com/Iyashinouta/sd-model-downloader/issues>
|
314 |
-
Report Here</a><br>
|
315 |
-
<center><font size=1>Model Downloader v1.0.8 Pre
|
316 |
-
'''
|
317 |
-
)
|
318 |
-
content_type.change(folder, content_type, downloadpath)
|
319 |
-
changename.change(change_name, changename, filename)
|
320 |
-
custompath.change(custom_download_path, custompath, downloadpath)
|
321 |
-
url.change(
|
322 |
-
get_data_from_url,
|
323 |
-
[
|
324 |
-
url,
|
325 |
-
downloadpath
|
326 |
-
],
|
327 |
-
[
|
328 |
-
filename,
|
329 |
-
image,
|
330 |
-
download_btn,
|
331 |
-
out_text,
|
332 |
-
info
|
333 |
-
]
|
334 |
)
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
logging,
|
345 |
-
new_folder,
|
346 |
-
preview
|
347 |
-
],
|
348 |
-
out_text
|
349 |
-
)
|
350 |
-
url.submit(
|
351 |
-
start_downloading,
|
352 |
-
[
|
353 |
-
downloader_type,
|
354 |
-
download_btn,
|
355 |
-
url,
|
356 |
-
downloadpath,
|
357 |
-
filename,
|
358 |
-
addnet,
|
359 |
-
logging,
|
360 |
-
new_folder,
|
361 |
-
preview
|
362 |
-
],
|
363 |
-
out_text
|
364 |
)
|
365 |
-
|
366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
return (downloader, 'Model Downloader', 'downloader'),
|
368 |
|
369 |
script_callbacks.on_ui_tabs(on_ui_tabs)
|
|
|
130 |
basename, extension = get_filename_from_url(url)
|
131 |
markdown2 = f'''
|
132 |
<font size=2>
|
133 |
+
<b>模型链接:</b> {url}<br>
|
134 |
+
<b>模型路径:</b> {downloadpath}<br>
|
135 |
+
<b>模型名称:</b> {basename}{extension}<br>
|
|
|
136 |
'''
|
137 |
except:
|
138 |
imgurl = no_prev
|
139 |
markdown2 = f'''
|
140 |
<font size=2>
|
141 |
+
<b>模型链接:</b> {url}<br>
|
142 |
+
<b>模型路径:</b> {downloadpath}<br>
|
143 |
+
<b>模型名称:</b> ???
|
|
|
144 |
'''
|
145 |
filename = gr.Textbox.update(basename)
|
146 |
image = gr.Image.update(imgurl)
|
147 |
download_btn = gr.Button.update(visible=True, variant='primary')
|
148 |
+
out_text = gr.Textbox.update('Ready\nClick to start downloading', visible=True)
|
149 |
info = gr.Markdown.update(markdown2)
|
150 |
return filename, image, download_btn, out_text, info
|
151 |
|
|
|
220 |
print(f'{complete2}{final_target}')
|
221 |
|
222 |
def back(download_btn):
|
223 |
+
return gr.Button.update(visible=True, variant='primary')
|
224 |
|
225 |
def on_ui_tabs():
|
226 |
with gr.Blocks() as downloader:
|
227 |
+
with gr.Row():
|
228 |
+
with gr.Column(scale=8):
|
229 |
+
content_type = gr.Radio(
|
230 |
+
label='选择模型类型',
|
231 |
+
choices=[
|
232 |
+
'Checkpoint',
|
233 |
+
'Hypernetwork ',
|
234 |
+
'TextualInversion/Embedding',
|
235 |
+
'VAE',
|
236 |
+
'LoRA',
|
237 |
+
'LyCORIS(LoCon/LoHA)',
|
238 |
+
'ControlNet Model'
|
239 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
)
|
241 |
+
with gr.Column(scale=1):
|
242 |
+
downloader_type = gr.Radio(
|
243 |
+
label='选择下载器类型',
|
244 |
+
choices=[
|
245 |
+
'aria2',
|
246 |
+
'requests'
|
247 |
+
],
|
248 |
+
value='aria2',
|
249 |
+
type='value'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
)
|
251 |
+
with gr.Row():
|
252 |
+
with gr.Column():
|
253 |
+
with gr.Row():
|
254 |
+
addnet = gr.Checkbox(label='save to Additional Networks', value=True)
|
255 |
+
new_folder = gr.Checkbox(label='Create New Folder', value=True, visible=False)
|
256 |
+
custompath = gr.Checkbox(label='Custom Download Path', value=False, visible=False)
|
257 |
+
preview = gr.Checkbox(label='Download Preview', value=True, visible=False)
|
258 |
+
logging = gr.Checkbox(label='turn on log', value=False)
|
259 |
+
changename = gr.Checkbox(label='Change Filename', value=False)
|
260 |
+
with gr.Row():
|
261 |
+
with gr.Column():
|
262 |
+
url = gr.Textbox(
|
263 |
+
label='输入模型下载链接',
|
264 |
+
max_lines=1, placeholder='Type/Paste URL Here'
|
265 |
+
)
|
266 |
+
info = gr.Markdown(
|
267 |
+
'''
|
268 |
+
<font size=2>
|
269 |
+
<b>模型链接: Please enter the model link</b><br>
|
270 |
+
<b>模型路径: Please enter the model link</b><br>
|
271 |
+
<b>模型名称: Please enter the model link</b>
|
272 |
+
'''
|
273 |
+
)
|
274 |
+
downloadpath = gr.Textbox(
|
275 |
+
value='Unset, Please Choose your Content Type',
|
276 |
+
label='Custom Download Path',
|
277 |
+
placeholder='Paste Folder Path Here',
|
278 |
+
visible=False
|
279 |
+
)
|
280 |
+
filename = gr.Textbox(
|
281 |
+
label='Change Filename',
|
282 |
+
placeholder='Filename',
|
283 |
+
visible=False
|
284 |
+
)
|
285 |
+
with gr.Row():
|
286 |
+
with gr.Column():
|
287 |
+
download_btn = gr.Button(
|
288 |
+
'Start Download',
|
289 |
+
visible=True,
|
290 |
+
variant='secondary'
|
291 |
+
)
|
292 |
+
out_text = gr.Textbox(
|
293 |
+
label='Download Result',
|
294 |
+
placeholder='Result\n ',
|
295 |
+
visible=True,
|
296 |
+
interactive=False,
|
297 |
+
)
|
298 |
+
with gr.Column():
|
299 |
+
prev_markdown = gr.Markdown('''<font size=2><b>Preview Model :</b>''', visible=False)
|
300 |
+
with gr.Row():
|
301 |
+
image = gr.Image(value=no_prev, show_label=False)
|
302 |
+
image.style(height=332)
|
303 |
+
with gr.Row():
|
304 |
+
github = gr.Markdown(
|
305 |
+
'''
|
306 |
+
<center><font size=2>Having Issue? |
|
307 |
+
<a href=https://github.com/Iyashinouta/sd-model-downloader/issues>
|
308 |
+
Report Here</a><br>
|
309 |
+
<center><font size=1>Model Downloader v1.0.8 Pre
|
310 |
+
'''
|
311 |
+
)
|
312 |
+
content_type.change(folder, content_type, downloadpath)
|
313 |
+
changename.change(change_name, changename, filename)
|
314 |
+
custompath.change(custom_download_path, custompath, downloadpath)
|
315 |
+
url.change(
|
316 |
+
get_data_from_url,
|
317 |
+
[url,downloadpath],
|
318 |
+
[filename,image,download_btn,out_text,info]
|
319 |
+
)
|
320 |
+
download_btn.click(
|
321 |
+
start_downloading,
|
322 |
+
[downloader_type,download_btn,url,downloadpath,filename,addnet,logging,new_folder,preview],
|
323 |
+
out_text
|
324 |
+
)
|
325 |
+
url.submit(
|
326 |
+
start_downloading,
|
327 |
+
[downloader_type,download_btn,url,downloadpath,filename,addnet,logging,new_folder,preview],
|
328 |
+
out_text
|
329 |
+
)
|
330 |
+
download_btn.click(back, download_btn, download_btn)
|
331 |
+
url.submit(back, url, download_btn)
|
332 |
return (downloader, 'Model Downloader', 'downloader'),
|
333 |
|
334 |
script_callbacks.on_ui_tabs(on_ui_tabs)
|