TheLastBen commited on
Commit
9ab2841
1 Parent(s): d77b555

Update Scripts/mainpaperspaceA1111_311.py

Browse files
Files changed (1) hide show
  1. Scripts/mainpaperspaceA1111_311.py +471 -0
Scripts/mainpaperspaceA1111_311.py CHANGED
@@ -0,0 +1,471 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from IPython.display import clear_output
3
+ from subprocess import call, getoutput, run
4
+ import time
5
+ import sys
6
+ import fileinput
7
+ import ipywidgets as widgets
8
+ from torch.hub import download_url_to_file
9
+ from urllib.parse import urlparse, parse_qs, unquote
10
+ import re
11
+ import requests
12
+ import six
13
+
14
+ from urllib.request import urlopen, Request
15
+ import tempfile
16
+ from tqdm import tqdm
17
+
18
+
19
+
20
+ def Deps(force_reinstall):
21
+
22
+ if not force_reinstall and os.path.exists('/usr/local/lib/python3.11/dist-packages/gradio'):
23
+ ntbk()
24
+ os.environ['TORCH_HOME'] = '/notebooks/cache/torch'
25
+ os.environ['PYTHONWARNINGS'] = 'ignore'
26
+ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
27
+ print('Modules and notebooks updated, dependencies already installed')
28
+
29
+ else:
30
+ call("pip install --root-user-action=ignore --no-deps -q accelerate==0.12.0", shell=True, stdout=open('/dev/null', 'w'))
31
+ ntbk()
32
+ if not os.path.exists('/models'):
33
+ call('mkdir /models', shell=True)
34
+ if not os.path.exists('/notebooks/models'):
35
+ call('ln -s /models /notebooks', shell=True)
36
+ if os.path.exists('/deps'):
37
+ call("rm -r /deps", shell=True)
38
+ call('mkdir /deps', shell=True)
39
+ if not os.path.exists('cache'):
40
+ call('mkdir cache', shell=True)
41
+ os.chdir('/deps')
42
+ call('wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/aptdeps.txt', shell=True)
43
+ call('dpkg -i *.deb', shell=True, stdout=open('/dev/null', 'w'))
44
+ depsinst("https://huggingface.co/TheLastBen/dependencies/resolve/main/ppsdeps_311.tar.zst", "/deps/ppsdeps_311.tar.zst")
45
+ call('tar -C / --zstd -xf ppsdeps_311.tar.zst', shell=True, stdout=open('/dev/null', 'w'))
46
+ os.chdir('/notebooks')
47
+ call("git clone --depth 1 -q --branch main https://github.com/TheLastBen/diffusers /diffusers", shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
48
+ os.environ['TORCH_HOME'] = '/notebooks/cache/torch'
49
+ os.environ['PYTHONWARNINGS'] = 'ignore'
50
+ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
51
+ call("sed -i 's@text = _formatwarnmsg(msg)@text =\"\"@g' /usr/lib/python3.11/warnings.py", shell=True)
52
+ if not os.path.exists('/notebooks/diffusers'):
53
+ call('ln -s /diffusers /notebooks', shell=True)
54
+ call("rm -r /deps", shell=True)
55
+ os.chdir('/notebooks')
56
+ clear_output()
57
+
58
+ done()
59
+
60
+
61
+
62
+ def depsinst(url, dst):
63
+ file_size = None
64
+ req = Request(url, headers={"User-Agent": "torch.hub"})
65
+ u = urlopen(req)
66
+ meta = u.info()
67
+ if hasattr(meta, 'getheaders'):
68
+ content_length = meta.getheaders("Content-Length")
69
+ else:
70
+ content_length = meta.get_all("Content-Length")
71
+ if content_length is not None and len(content_length) > 0:
72
+ file_size = int(content_length[0])
73
+
74
+ with tqdm(total=file_size, disable=False, mininterval=0.5,
75
+ bar_format='Installing dependencies |{bar:20}| {percentage:3.0f}%') as pbar:
76
+ with open(dst, "wb") as f:
77
+ while True:
78
+ buffer = u.read(8192)
79
+ if len(buffer) == 0:
80
+ break
81
+ f.write(buffer)
82
+ pbar.update(len(buffer))
83
+ f.close()
84
+
85
+
86
+
87
+ def dwn(url, dst, msg):
88
+ file_size = None
89
+ req = Request(url, headers={"User-Agent": "torch.hub"})
90
+ u = urlopen(req)
91
+ meta = u.info()
92
+ if hasattr(meta, 'getheaders'):
93
+ content_length = meta.getheaders("Content-Length")
94
+ else:
95
+ content_length = meta.get_all("Content-Length")
96
+ if content_length is not None and len(content_length) > 0:
97
+ file_size = int(content_length[0])
98
+
99
+ with tqdm(total=file_size, disable=False, mininterval=0.5,
100
+ bar_format=msg+' |{bar:20}| {percentage:3.0f}%') as pbar:
101
+ with open(dst, "wb") as f:
102
+ while True:
103
+ buffer = u.read(8192)
104
+ if len(buffer) == 0:
105
+ break
106
+ f.write(buffer)
107
+ pbar.update(len(buffer))
108
+ f.close()
109
+
110
+
111
+
112
+ def ntbk():
113
+
114
+ os.chdir('/notebooks')
115
+ if not os.path.exists('Latest_Notebooks'):
116
+ call('mkdir Latest_Notebooks', shell=True)
117
+ else:
118
+ call('rm -r Latest_Notebooks', shell=True)
119
+ call('mkdir Latest_Notebooks', shell=True)
120
+ os.chdir('/notebooks/Latest_Notebooks')
121
+ call('wget -q -i https://huggingface.co/datasets/TheLastBen/PPS/raw/main/Notebooks.txt', shell=True)
122
+ call('rm Notebooks.txt', shell=True)
123
+ os.chdir('/notebooks')
124
+
125
+
126
+
127
+ def repo():
128
+
129
+ print('Installing/Updating the repo...')
130
+ os.chdir('/notebooks')
131
+ if not os.path.exists('/notebooks/sd/stablediffusiond'): #reset later
132
+ call('wget -q -O sd_mrep.tar.zst https://huggingface.co/TheLastBen/dependencies/resolve/main/sd_mrep.tar.zst', shell=True)
133
+ call('tar --zstd -xf sd_mrep.tar.zst', shell=True)
134
+ call('rm sd_mrep.tar.zst', shell=True)
135
+
136
+ os.chdir('/notebooks/sd')
137
+ if not os.path.exists('stable-diffusion-webui'):
138
+ call('git clone -q --depth 1 --branch master https://github.com/AUTOMATIC1111/stable-diffusion-webui', shell=True)
139
+
140
+ os.chdir('/notebooks/sd/stable-diffusion-webui/')
141
+ call('git reset --hard', shell=True, stdout=open('/dev/null', 'w'))
142
+ print('')
143
+ call('git checkout master', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
144
+ call('git pull', shell=True, stdout=open('/dev/null', 'w'))
145
+ os.makedirs('/notebooks/sd/stable-diffusion-webui/repositories', exist_ok=True)
146
+ call('git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui-assets /notebooks/sd/stable-diffusion-webui/repositories/stable-diffusion-webui-assets', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
147
+ os.chdir('/notebooks')
148
+ clear_output()
149
+ done()
150
+
151
+
152
+
153
+
154
+
155
+ def mdls(Original_Model_Version, Path_to_MODEL, MODEL_LINK, Temporary_Storage):
156
+
157
+ import gdown
158
+
159
+
160
+ src=getsrc(MODEL_LINK)
161
+
162
+
163
+ call('ln -s /datasets/stable-diffusion-classic/SDv1.5.ckpt /notebooks/sd/stable-diffusion-webui/models/Stable-diffusion', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
164
+ call('ln -s /datasets/stable-diffusion-v2-1-base-diffusers/stable-diffusion-2-1-base/v2-1_512-nonema-pruned.safetensors /notebooks/sd/stable-diffusion-webui/models/Stable-diffusion', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
165
+ call('ln -s /datasets/stable-diffusion-v2-1/stable-diffusion-2-1/v2-1_768-nonema-pruned.safetensors /notebooks/sd/stable-diffusion-webui/models/Stable-diffusion', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
166
+ call('ln -s /datasets/stable-diffusion-xl/sd_xl_base_1.0.safetensors /notebooks/sd/stable-diffusion-webui/models/Stable-diffusion', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
167
+
168
+ if Path_to_MODEL !='':
169
+ if os.path.exists(str(Path_to_MODEL)):
170
+ print('Using the custom model.')
171
+ model=Path_to_MODEL
172
+ else:
173
+ print('Wrong path, check that the path to the model is correct')
174
+
175
+ elif MODEL_LINK !="":
176
+
177
+ if src=='civitai':
178
+ modelname=get_name(MODEL_LINK, False)
179
+ if Temporary_Storage:
180
+ model=f'/models/{modelname}'
181
+ else:
182
+ model=f'/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/{modelname}'
183
+ if not os.path.exists(model):
184
+ dwn(MODEL_LINK, model, 'Downloading the custom model')
185
+ clear_output()
186
+ else:
187
+ print('Model already exists')
188
+ elif src=='gdrive':
189
+ modelname=get_name(MODEL_LINK, True)
190
+ if Temporary_Storage:
191
+ model=f'/models/{modelname}'
192
+ else:
193
+ model=f'/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/{modelname}'
194
+ if not os.path.exists(model):
195
+ gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)
196
+ clear_output()
197
+ else:
198
+ print('Model already exists')
199
+ else:
200
+ modelname=os.path.basename(MODEL_LINK)
201
+ if Temporary_Storage:
202
+ model=f'/models/{modelname}'
203
+ else:
204
+ model=f'/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/{modelname}'
205
+ if not os.path.exists(model):
206
+ gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)
207
+ clear_output()
208
+ else:
209
+ print('Model already exists')
210
+
211
+ if os.path.exists(model) and os.path.getsize(model) > 1810671599:
212
+ print('Model downloaded, using the custom model.')
213
+ else:
214
+ call('rm '+model, shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
215
+ print('Wrong link, check that the link is valid')
216
+
217
+ else:
218
+ if Original_Model_Version == "v1.5":
219
+ model="/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/SDv1.5.ckpt"
220
+ print('Using the original V1.5 model')
221
+ elif Original_Model_Version == "v2-512":
222
+ model="/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/v2-1_512-nonema-pruned.safetensors"
223
+ print('Using the original V2-512 model')
224
+ elif Original_Model_Version == "v2-768":
225
+ model="/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/v2-1_768-nonema-pruned.safetensors"
226
+ print('Using the original V2-768 model')
227
+ elif Original_Model_Version == "SDXL":
228
+ model="/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/sd_xl_base_1.0.safetensors"
229
+ print('Using the original SDXL model')
230
+ else:
231
+ model="/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion"
232
+ print('Wrong model version, try again')
233
+ try:
234
+ model
235
+ except:
236
+ model="/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion"
237
+
238
+ return model
239
+
240
+
241
+
242
+
243
+ def loradwn(LoRA_LINK):
244
+
245
+ import gdown
246
+
247
+ if LoRA_LINK=='':
248
+ print('Nothing to do')
249
+ else:
250
+ os.makedirs('/notebooks/sd/stable-diffusion-webui/models/Lora', exist_ok=True)
251
+
252
+ src=getsrc(LoRA_LINK)
253
+
254
+ if src=='civitai':
255
+ modelname=get_name(LoRA_LINK, False)
256
+ loramodel=f'/notebooks/sd/stable-diffusion-webui/models/Lora/{modelname}'
257
+ if not os.path.exists(loramodel):
258
+ dwn(LoRA_LINK, loramodel, 'Downloading the LoRA model')
259
+ clear_output()
260
+ else:
261
+ print('Model already exists')
262
+ elif src=='gdrive':
263
+ modelname=get_name(LoRA_LINK, True)
264
+ loramodel=f'/notebooks/sd/stable-diffusion-webui/models/Lora/{modelname}'
265
+ if not os.path.exists(loramodel):
266
+ gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)
267
+ clear_output()
268
+ else:
269
+ print('Model already exists')
270
+ else:
271
+ modelname=os.path.basename(LoRA_LINK)
272
+ loramodel=f'/notebooks/sd/stable-diffusion-webui/models/Lora/{modelname}'
273
+ if not os.path.exists(loramodel):
274
+ gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)
275
+ clear_output()
276
+ else:
277
+ print('Model already exists')
278
+
279
+ if os.path.exists(loramodel) :
280
+ print('LoRA downloaded')
281
+ else:
282
+ print('Wrong link, check that the link is valid')
283
+
284
+
285
+
286
+ def CN(ControlNet_Model, ControlNet_XL_Model):
287
+
288
+ def download(url, model_dir):
289
+
290
+ filename = os.path.basename(urlparse(url).path)
291
+ pth = os.path.abspath(os.path.join(model_dir, filename))
292
+ if not os.path.exists(pth):
293
+ print('Downloading: '+os.path.basename(url))
294
+ download_url_to_file(url, pth, hash_prefix=None, progress=True)
295
+ else:
296
+ print(f"The model {filename} already exists")
297
+
298
+ wrngv1=False
299
+ os.chdir('/notebooks/sd/stable-diffusion-webui/extensions')
300
+ if not os.path.exists("sd-webui-controlnet"):
301
+ call('git clone https://github.com/Mikubill/sd-webui-controlnet.git', shell=True)
302
+ os.chdir('/notebooks')
303
+ else:
304
+ os.chdir('sd-webui-controlnet')
305
+ call('git reset --hard', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
306
+ call('git pull', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
307
+ os.chdir('/notebooks')
308
+
309
+ mdldir="/notebooks/sd/stable-diffusion-webui/extensions/sd-webui-controlnet/models"
310
+ for filename in os.listdir(mdldir):
311
+ if "_sd14v1" in filename:
312
+ renamed = re.sub("_sd14v1", "-fp16", filename)
313
+ os.rename(os.path.join(mdldir, filename), os.path.join(mdldir, renamed))
314
+
315
+ call('wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models.txt', shell=True)
316
+ call('wget -q -O CN_models_XL.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_XL.txt', shell=True)
317
+
318
+ with open("CN_models.txt", 'r') as f:
319
+ mdllnk = f.read().splitlines()
320
+ with open("CN_models_XL.txt", 'r') as d:
321
+ mdllnk_XL = d.read().splitlines()
322
+ call('rm CN_models.txt CN_models_XL.txt', shell=True)
323
+
324
+ os.chdir('/notebooks')
325
+
326
+ if ControlNet_Model == "All" or ControlNet_Model == "all" :
327
+ for lnk in mdllnk:
328
+ download(lnk, mdldir)
329
+ clear_output()
330
+
331
+
332
+ elif ControlNet_Model == "15":
333
+ mdllnk=list(filter(lambda x: 't2i' in x, mdllnk))
334
+ for lnk in mdllnk:
335
+ download(lnk, mdldir)
336
+ clear_output()
337
+
338
+
339
+ elif ControlNet_Model.isdigit() and int(ControlNet_Model)-1<14 and int(ControlNet_Model)>0:
340
+ download(mdllnk[int(ControlNet_Model)-1], mdldir)
341
+ clear_output()
342
+
343
+ elif ControlNet_Model == "none":
344
+ pass
345
+ clear_output()
346
+
347
+ else:
348
+ print('Wrong ControlNet V1 choice, try again')
349
+ wrngv1=True
350
+
351
+
352
+ if ControlNet_XL_Model == "All" or ControlNet_XL_Model == "all" :
353
+ for lnk_XL in mdllnk_XL:
354
+ download(lnk_XL, mdldir)
355
+ if not wrngv1:
356
+ clear_output()
357
+ done()
358
+
359
+ elif ControlNet_XL_Model.isdigit() and int(ControlNet_XL_Model)-1<5:
360
+ download(mdllnk_XL[int(ControlNet_XL_Model)-1], mdldir)
361
+ if not wrngv1:
362
+ clear_output()
363
+ done()
364
+
365
+ elif ControlNet_XL_Model == "none":
366
+ pass
367
+ if not wrngv1:
368
+ clear_output()
369
+ done()
370
+
371
+ else:
372
+ print('Wrong ControlNet XL choice, try again')
373
+
374
+
375
+
376
+ def sdui(User, Password, model):
377
+
378
+ auth=f"--gradio-auth {User}:{Password}"
379
+ if User =="" or Password=="":
380
+ auth=""
381
+
382
+ call('wget -q -O /notebooks/sd/stable-diffusion-webui/modules/styles.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/styles.py', shell=True)
383
+ call('wget -q -O /usr/local/lib/python3.11/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py', shell=True)
384
+
385
+ localurl="tensorboard-"+os.environ.get('PAPERSPACE_FQDN')
386
+
387
+ for line in fileinput.input('/usr/local/lib/python3.11/dist-packages/gradio/blocks.py', inplace=True):
388
+ if line.strip().startswith('self.server_name ='):
389
+ line = f' self.server_name = "{localurl}"\n'
390
+ if line.strip().startswith('self.protocol = "https"'):
391
+ line = ' self.protocol = "https"\n'
392
+ if line.strip().startswith('if self.local_url.startswith("https") or self.is_colab'):
393
+ line = ''
394
+ if line.strip().startswith('else "http"'):
395
+ line = ''
396
+ sys.stdout.write(line)
397
+
398
+
399
+ os.chdir('/notebooks/sd/stable-diffusion-webui/modules')
400
+
401
+ call("sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\"/notebooks/sd/stablediffusion\"]@' /notebooks/sd/stable-diffusion-webui/modules/paths.py", shell=True)
402
+ call("sed -i 's@\.\.\/@src/@g' /notebooks/sd/stable-diffusion-webui/modules/paths.py", shell=True)
403
+ call("sed -i 's@src\/generative-models@generative-models@g' /notebooks/sd/stable-diffusion-webui/modules/paths.py", shell=True)
404
+
405
+ os.chdir('/notebooks/sd/stable-diffusion-webui')
406
+ clear_output()
407
+
408
+ if model=="":
409
+ mdlpth=""
410
+ else:
411
+ if os.path.isfile(model):
412
+ mdlpth="--ckpt "+model
413
+ else:
414
+ mdlpth="--ckpt-dir "+model
415
+
416
+
417
+ configf="--disable-console-progressbars --no-gradio-queue --no-hashing --no-half-vae --disable-safe-unpickle --api --no-download-sd-model --xformers --enable-insecure-extension-access --port 6006 --listen --skip-version-check --ckpt-dir /models "+auth+" "+mdlpth
418
+
419
+ return configf
420
+
421
+
422
+
423
+ def getsrc(url):
424
+ parsed_url = urlparse(url)
425
+ if parsed_url.netloc == 'civitai.com':
426
+ src='civitai'
427
+ elif parsed_url.netloc == 'drive.google.com':
428
+ src='gdrive'
429
+ elif parsed_url.netloc == 'huggingface.co':
430
+ src='huggingface'
431
+ else:
432
+ src='others'
433
+ return src
434
+
435
+
436
+
437
+ def get_name(url, gdrive):
438
+
439
+ from gdown.download import get_url_from_gdrive_confirmation
440
+
441
+ if not gdrive:
442
+ response = requests.get(url, allow_redirects=False)
443
+ if "Location" in response.headers:
444
+ redirected_url = response.headers["Location"]
445
+ quer = parse_qs(urlparse(redirected_url).query)
446
+ if "response-content-disposition" in quer:
447
+ disp_val = quer["response-content-disposition"][0].split(";")
448
+ for vals in disp_val:
449
+ if vals.strip().startswith("filename="):
450
+ filenm=unquote(vals.split("=", 1)[1].strip())
451
+ return filenm.replace("\"","")
452
+ else:
453
+ headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"}
454
+ lnk="https://drive.google.com/uc?id={id}&export=download".format(id=url[url.find("/d/")+3:url.find("/view")])
455
+ res = requests.session().get(lnk, headers=headers, stream=True, verify=True)
456
+ res = requests.session().get(get_url_from_gdrive_confirmation(res.text), headers=headers, stream=True, verify=True)
457
+ content_disposition = six.moves.urllib_parse.unquote(res.headers["Content-Disposition"])
458
+ filenm = re.search(r"filename\*=UTF-8''(.*)", content_disposition).groups()[0].replace(os.path.sep, "_")
459
+ return filenm
460
+
461
+
462
+
463
+ def done():
464
+ done = widgets.Button(
465
+ description='Done!',
466
+ disabled=True,
467
+ button_style='success',
468
+ tooltip='',
469
+ icon='check'
470
+ )
471
+ display(done)