TheLastBen commited on
Commit
e14c3e8
1 Parent(s): e656995

Update Scripts/mainpaperspaceA1111.py

Browse files
Files changed (1) hide show
  1. Scripts/mainpaperspaceA1111.py +118 -172
Scripts/mainpaperspaceA1111.py CHANGED
@@ -1,117 +1,94 @@
1
  import os
2
  from IPython.display import clear_output
3
- from subprocess import call, getoutput, Popen, run
4
  import time
5
- import ipywidgets as widgets
6
- import requests
7
  import sys
8
  import fileinput
 
9
  from torch.hub import download_url_to_file
10
  from urllib.parse import urlparse
11
  import re
12
 
13
 
 
14
  def Deps(force_reinstall):
15
 
16
- if not force_reinstall and os.path.exists('/usr/local/lib/python3.10/dist-packages/safetensors'):
17
- ntbks()
18
  print('Modules and notebooks updated, dependencies already installed')
19
- os.environ['PYTHONWARNINGS'] = 'ignore'
20
  else:
21
  print('Installing the dependencies...')
22
- call('pip install --root-user-action=ignore --disable-pip-version-check --no-deps -qq gdown numpy==1.23.5 accelerate==0.12.0 --force-reinstall', shell=True, stdout=open('/dev/null', 'w'))
23
- ntbks()
24
- if os.path.exists('deps'):
25
- call("rm -r deps", shell=True)
26
- if os.path.exists('diffusers'):
27
- call("rm -r diffusers", shell=True)
28
- call('mkdir deps', shell=True)
 
 
 
 
 
29
  if not os.path.exists('cache'):
30
  call('mkdir cache', shell=True)
31
- os.chdir('deps')
32
- call('wget -q https://huggingface.co/TheLastBen/dependencies/resolve/main/rnpddeps-t2.tar.zst', shell=True, stdout=open('/dev/null', 'w'))
33
- call('tar -C / --zstd -xf rnpddeps-t2.tar.zst', shell=True, stdout=open('/dev/null', 'w'))
34
- call("sed -i 's@~/.cache@/workspace/cache@' /usr/local/lib/python3.10/dist-packages/transformers/utils/hub.py", shell=True)
35
- os.chdir('/workspace')
36
- call("git clone --depth 1 -q --branch main https://github.com/TheLastBen/diffusers", shell=True, stdout=open('/dev/null', 'w'))
37
- call("rm -r deps", shell=True)
38
- os.chdir('/workspace')
39
- os.environ['PYTHONWARNINGS'] = 'ignore'
 
 
 
 
40
  clear_output()
41
 
42
  done()
43
 
44
- def ntbks():
45
 
46
- os.chdir('/workspace')
 
 
47
  if not os.path.exists('Latest_Notebooks'):
48
  call('mkdir Latest_Notebooks', shell=True)
49
  else:
50
  call('rm -r Latest_Notebooks', shell=True)
51
  call('mkdir Latest_Notebooks', shell=True)
52
- os.chdir('/workspace/Latest_Notebooks')
53
- call('wget -q -i https://huggingface.co/datasets/TheLastBen/RNPD/raw/main/Notebooks.txt', shell=True)
54
  call('rm Notebooks.txt', shell=True)
55
- os.chdir('/workspace')
56
 
57
 
58
- def repo(Huggingface_token_optional):
59
-
60
- from slugify import slugify
61
- from huggingface_hub import HfApi, CommitOperationAdd, create_repo
62
-
63
- os.chdir('/workspace')
64
- if Huggingface_token_optional!="":
65
- username = HfApi().whoami(Huggingface_token_optional)["name"]
66
- backup=f"https://USER:{Huggingface_token_optional}@huggingface.co/datasets/{username}/fast-stable-diffusion/resolve/main/sd_backup_rnpd.tar.zst"
67
- response = requests.head(backup)
68
- if response.status_code == 302:
69
- print('Restoring the SD folder...')
70
- open('/workspace/sd_backup_rnpd.tar.zst', 'wb').write(requests.get(backup).content)
71
- call('tar --zstd -xf sd_backup_rnpd.tar.zst', shell=True)
72
- call('rm sd_backup_rnpd.tar.zst', shell=True)
73
- else:
74
- print('Backup not found, using a fresh/existing repo...')
75
- time.sleep(2)
76
- if not os.path.exists('/workspace/sd/stablediffusion'):
77
- call('wget -q -O sd_rep.tar.zst https://huggingface.co/TheLastBen/dependencies/resolve/main/sd_rep.tar.zst', shell=True)
78
- call('tar --zstd -xf sd_rep.tar.zst', shell=True)
79
- call('rm sd_rep.tar.zst', shell=True)
80
- os.chdir('/workspace/sd')
81
- if not os.path.exists('stable-diffusion-webui'):
82
- call('git clone -q --depth 1 --branch master https://github.com/AUTOMATIC1111/stable-diffusion-webui', shell=True)
83
-
84
- else:
85
- print('Installing/Updating the repo...')
86
- os.chdir('/workspace')
87
- if not os.path.exists('/workspace/sd/stablediffusion'):
88
- call('wget -q -O sd_rep.tar.zst https://huggingface.co/TheLastBen/dependencies/resolve/main/sd_rep.tar.zst', shell=True)
89
- call('tar --zstd -xf sd_rep.tar.zst', shell=True)
90
- call('rm sd_rep.tar.zst', shell=True)
91
 
92
- os.chdir('/workspace/sd')
93
- if not os.path.exists('stable-diffusion-webui'):
94
- call('git clone -q --depth 1 --branch master https://github.com/AUTOMATIC1111/stable-diffusion-webui', shell=True)
 
 
 
95
 
 
 
 
96
 
97
- os.chdir('/workspace/sd/stable-diffusion-webui/')
98
- call('git reset --hard', shell=True)
99
  print('')
100
- call('git pull', shell=True)
101
- os.chdir('/workspace')
102
  clear_output()
103
  done()
104
 
105
 
106
-
107
- def mdls(Original_Model_Version, Path_to_MODEL, MODEL_LINK, safetensors):
108
-
109
  import gdown
110
-
111
- if os.path.exists('/workspace/auto-models/SDv1-5.ckpt'):
112
- call('mv /workspace/auto-models/* /workspace/sd/stable-diffusion-webui/models/Stable-diffusion', shell=True)
113
- call('rm -r /workspace/auto-models', shell=True)
114
-
115
  if Path_to_MODEL !='':
116
  if os.path.exists(str(Path_to_MODEL)):
117
  print('Using the trained model.')
@@ -121,7 +98,10 @@ def mdls(Original_Model_Version, Path_to_MODEL, MODEL_LINK, safetensors):
121
 
122
  elif MODEL_LINK != "":
123
  modelname="model.safetensors" if safetensors else "model.ckpt"
124
- model=f'/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/{modelname}'
 
 
 
125
  if os.path.exists(model):
126
  call('rm '+model, shell=True)
127
  gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)
@@ -134,34 +114,26 @@ def mdls(Original_Model_Version, Path_to_MODEL, MODEL_LINK, safetensors):
134
 
135
  else:
136
  if Original_Model_Version == "v1.5":
137
- model="/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/SDv1-5.ckpt"
138
  print('Using the original V1.5 model')
139
  elif Original_Model_Version == "v2-512":
140
- if not os.path.exists('/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/SDv2-512.ckpt'):
141
- print('Downlading the V2-512 model...')
142
- model='/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/SDv2-512.ckpt'
143
- call('gdown -O '+model+' https://huggingface.co/stabilityai/stable-diffusion-2-1-base/resolve/main/v2-1_512-nonema-pruned.ckpt', shell=True)
144
- clear_output()
145
- print('Using the original V2-512 model')
146
- else:
147
- print('Using the original V2-512 model')
148
- model='/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/SDv2-512.ckpt'
149
  elif Original_Model_Version == "v2-768":
150
- model="/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/SDv2-768.ckpt"
151
  print('Using the original V2-768 model')
152
  else:
153
- model="/workspace/sd/stable-diffusion-webui/models/Stable-diffusion"
154
- print('Wrong model version, try again')
155
  try:
156
  model
157
  except:
158
- model="/workspace/sd/stable-diffusion-webui/models/Stable-diffusion"
159
 
160
  return model
161
 
162
 
163
-
164
- def CNet(ControlNet_Model, ControlNet_v2_Model):
165
 
166
  def download(url, model_dir):
167
 
@@ -174,17 +146,17 @@ def CNet(ControlNet_Model, ControlNet_v2_Model):
174
  print(f"The model {filename} already exists")
175
 
176
  wrngv1=False
177
- os.chdir('/workspace/sd/stable-diffusion-webui/extensions')
178
  if not os.path.exists("sd-webui-controlnet"):
179
  call('git clone https://github.com/Mikubill/sd-webui-controlnet.git', shell=True)
180
- os.chdir('/workspace')
181
  else:
182
  os.chdir('sd-webui-controlnet')
183
  call('git reset --hard', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
184
  call('git pull', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
185
- os.chdir('/workspace')
186
 
187
- mdldir="/workspace/sd/stable-diffusion-webui/extensions/sd-webui-controlnet/models"
188
  for filename in os.listdir(mdldir):
189
  if "_sd14v1" in filename:
190
  renamed = re.sub("_sd14v1", "-fp16", filename)
@@ -192,7 +164,7 @@ def CNet(ControlNet_Model, ControlNet_v2_Model):
192
 
193
  call('wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models.txt', shell=True)
194
  call('wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_v2.txt', shell=True)
195
-
196
  with open("CN_models.txt", 'r') as f:
197
  mdllnk = f.read().splitlines()
198
  with open("CN_models_v2.txt", 'r') as d:
@@ -200,10 +172,10 @@ def CNet(ControlNet_Model, ControlNet_v2_Model):
200
  call('rm CN_models.txt CN_models_v2.txt', shell=True)
201
 
202
  cfgnames=[os.path.basename(url).split('.')[0]+'.yaml' for url in mdllnk_v2]
203
- os.chdir('/workspace/sd/stable-diffusion-webui/extensions/sd-webui-controlnet/models')
204
  for name in cfgnames:
205
  run(['cp', 'cldm_v21.yaml', name])
206
- os.chdir('/workspace')
207
 
208
  if ControlNet_Model == "All" or ControlNet_Model == "all" :
209
  for lnk in mdllnk:
@@ -230,7 +202,6 @@ def CNet(ControlNet_Model, ControlNet_v2_Model):
230
  print('Wrong ControlNet V1 choice, try again')
231
  wrngv1=True
232
 
233
-
234
  if ControlNet_v2_Model == "All" or ControlNet_v2_Model == "all" :
235
  for lnk_v2 in mdllnk_v2:
236
  download(lnk_v2, mdldir)
@@ -247,7 +218,7 @@ def CNet(ControlNet_Model, ControlNet_v2_Model):
247
  elif ControlNet_v2_Model == "none":
248
  pass
249
  if not wrngv1:
250
- clear_output()
251
  done()
252
 
253
  else:
@@ -255,93 +226,68 @@ def CNet(ControlNet_Model, ControlNet_v2_Model):
255
 
256
 
257
 
258
- def sd(User, Password, model):
259
 
260
- import gradio
261
-
262
- gradio.close_all()
263
-
264
  auth=f"--gradio-auth {User}:{Password}"
265
  if User =="" or Password=="":
266
  auth=""
267
-
268
- call('wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py', shell=True)
269
-
270
- os.chdir('/workspace/sd/stable-diffusion-webui/modules')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
  call('wget -q -O paths.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/paths.py', shell=True)
272
- call("sed -i 's@/content/gdrive/MyDrive/sd/stablediffusion@/workspace/sd/stablediffusion@' /workspace/sd/stable-diffusion-webui/modules/paths.py", shell=True)
273
- call("sed -i 's@\"quicksettings\": OptionInfo(.*@\"quicksettings\": OptionInfo(\"sd_model_checkpoint, sd_vae, CLIP_stop_at_last_layers, inpainting_mask_weight, initial_noise_multiplier\", \"Quicksettings list\"),@' /workspace/sd/stable-diffusion-webui/modules/shared.py", shell=True)
274
- call("sed -i 's@print(\"No module.*@@' /workspace/sd/stablediffusion/ldm/modules/diffusionmodules/model.py", shell=True)
275
- os.chdir('/workspace/sd/stable-diffusion-webui')
276
  clear_output()
277
 
278
- podid=os.environ.get('RUNPOD_POD_ID')
279
- localurl=f"{podid}-3000.proxy.runpod.net"
280
-
281
- for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):
282
- if line.strip().startswith('self.server_name ='):
283
- line = f' self.server_name = "{localurl}"\n'
284
- if line.strip().startswith('self.protocol = "https"'):
285
- line = ' self.protocol = "https"\n'
286
- if line.strip().startswith('if self.local_url.startswith("https") or self.is_colab'):
287
- line = ''
288
- if line.strip().startswith('else "http"'):
289
- line = ''
290
- sys.stdout.write(line)
291
-
292
-
293
  if os.path.isfile(model):
294
  mdlpth="--ckpt "+model
295
  else:
296
  mdlpth="--ckpt-dir "+model
297
 
298
- configf="--disable-console-progressbars --no-half-vae --disable-safe-unpickle --api --no-download-sd-model --opt-sdp-attention --enable-insecure-extension-access --skip-version-check --listen --port 3000 "+auth+" "+mdlpth
299
-
300
- return configf
301
 
 
302
 
303
- def save(Huggingface_Write_token):
304
 
305
- from slugify import slugify
306
- from huggingface_hub import HfApi, CommitOperationAdd, create_repo
307
 
308
- if Huggingface_Write_token=="":
309
- print('A huggingface write token is required')
310
-
311
- else:
312
- os.chdir('/workspace')
313
-
314
- if os.path.exists('sd'):
315
-
316
- call('tar --exclude="stable-diffusion-webui/models/*/*" --exclude="sd-webui-controlnet/models/*" --zstd -cf sd_backup_rnpd.tar.zst sd', shell=True)
317
- api = HfApi()
318
- username = api.whoami(token=Huggingface_Write_token)["name"]
319
-
320
- repo_id = f"{username}/{slugify('fast-stable-diffusion')}"
321
-
322
- print("Backing up...")
323
-
324
- operations = [CommitOperationAdd(path_in_repo="sd_backup_rnpd.tar.zst", path_or_fileobj="/workspace/sd_backup_rnpd.tar.zst")]
325
-
326
- create_repo(repo_id,private=True, token=Huggingface_Write_token, exist_ok=True, repo_type="dataset")
327
-
328
- api.create_commit(
329
- repo_id=repo_id,
330
- repo_type="dataset",
331
- operations=operations,
332
- commit_message="SD folder Backup",
333
- token=Huggingface_Write_token
334
- )
335
-
336
- call('rm sd_backup_rnpd.tar.zst', shell=True)
337
- clear_output()
338
-
339
- done()
340
-
341
- else:
342
- print('Nothing to backup')
343
-
344
-
345
  def done():
346
  done = widgets.Button(
347
  description='Done!',
 
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
10
  import re
11
 
12
 
13
+
14
  def Deps(force_reinstall):
15
 
16
+ if not force_reinstall and os.path.exists('/usr/local/lib/python3.9/dist-packages/safetensors'):
17
+ ntbk()
18
  print('Modules and notebooks updated, dependencies already installed')
19
+
20
  else:
21
  print('Installing the dependencies...')
22
+ call("pip install --root-user-action=ignore --no-deps -q accelerate==0.12.0", shell=True, stdout=open('/dev/null', 'w'))
23
+ if not os.path.exists('/usr/local/lib/python3.9/dist-packages/safetensors'):
24
+ os.chdir('/usr/local/lib/python3.9/dist-packages')
25
+ call("rm -r torch torch-1.12.1+cu116.dist-info torchaudio* torchvision* PIL Pillow* transformers* numpy* gdown*", shell=True, stdout=open('/dev/null', 'w'))
26
+ ntbk()
27
+ if not os.path.exists('/models'):
28
+ call('mkdir /models', shell=True)
29
+ if not os.path.exists('/notebooks/models'):
30
+ call('ln -s /models /notebooks', shell=True)
31
+ if os.path.exists('/deps'):
32
+ call("rm -r /deps", shell=True)
33
+ call('mkdir /deps', shell=True)
34
  if not os.path.exists('cache'):
35
  call('mkdir cache', shell=True)
36
+ os.chdir('/deps')
37
+ call('wget -q -i https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/Dependencies/aptdeps.txt', shell=True)
38
+ call('dpkg -i *.deb', shell=True, stdout=open('/dev/null', 'w'))
39
+ call('wget -q https://huggingface.co/TheLastBen/dependencies/resolve/main/ppsdeps.tar.zst', shell=True, stdout=open('/dev/null', 'w'))
40
+ call('tar -C / --zstd -xf ppsdeps.tar.zst', shell=True, stdout=open('/dev/null', 'w'))
41
+ call("sed -i 's@~/.cache@/notebooks/cache@' /usr/local/lib/python3.9/dist-packages/transformers/utils/hub.py", shell=True)
42
+ os.chdir('/notebooks')
43
+ call("git clone --depth 1 -q --branch main https://github.com/TheLastBen/diffusers /diffusers", shell=True, stdout=open('/dev/null', 'w'))
44
+ call("pip install --root-user-action=ignore -qq gradio==3.23", shell=True, stdout=open('/dev/null', 'w'))
45
+ if not os.path.exists('/notebooks/diffusers'):
46
+ call('ln -s /diffusers /notebooks', shell=True)
47
+ call("rm -r /deps", shell=True)
48
+ os.chdir('/notebooks')
49
  clear_output()
50
 
51
  done()
52
 
 
53
 
54
+ def ntbk():
55
+
56
+ os.chdir('/notebooks')
57
  if not os.path.exists('Latest_Notebooks'):
58
  call('mkdir Latest_Notebooks', shell=True)
59
  else:
60
  call('rm -r Latest_Notebooks', shell=True)
61
  call('mkdir Latest_Notebooks', shell=True)
62
+ os.chdir('/notebooks/Latest_Notebooks')
63
+ call('wget -q -i https://huggingface.co/datasets/TheLastBen/PPS/raw/main/Notebooks.txt', shell=True)
64
  call('rm Notebooks.txt', shell=True)
65
+ os.chdir('/notebooks')
66
 
67
 
68
+ def repo():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
+ print('Installing/Updating the repo...')
71
+ os.chdir('/notebooks')
72
+ if not os.path.exists('/notebooks/sd/stablediffusion'):
73
+ call('wget -q -O sd_rep.tar.zst https://huggingface.co/TheLastBen/dependencies/resolve/main/sd_rep.tar.zst', shell=True)
74
+ call('tar --zstd -xf sd_rep.tar.zst', shell=True)
75
+ call('rm sd_rep.tar.zst', shell=True)
76
 
77
+ os.chdir('/notebooks/sd')
78
+ if not os.path.exists('stable-diffusion-webui'):
79
+ call('git clone -q --depth 1 --branch master https://github.com/AUTOMATIC1111/stable-diffusion-webui', shell=True)
80
 
81
+ os.chdir('/notebooks/sd/stable-diffusion-webui/')
82
+ call('git reset --hard', shell=True, stdout=open('/dev/null', 'w'))
83
  print('')
84
+ call('git pull', shell=True, stdout=open('/dev/null', 'w'))
85
+ os.chdir('/notebooks')
86
  clear_output()
87
  done()
88
 
89
 
90
+ def mdl(Original_Model_Version, Path_to_MODEL, MODEL_LINK, safetensors, Temporary_Storage):
 
 
91
  import gdown
 
 
 
 
 
92
  if Path_to_MODEL !='':
93
  if os.path.exists(str(Path_to_MODEL)):
94
  print('Using the trained model.')
 
98
 
99
  elif MODEL_LINK != "":
100
  modelname="model.safetensors" if safetensors else "model.ckpt"
101
+ if Temporary_Storage:
102
+ model=f'/models/{modelname}'
103
+ else:
104
+ model=f'/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/{modelname}'
105
  if os.path.exists(model):
106
  call('rm '+model, shell=True)
107
  gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)
 
114
 
115
  else:
116
  if Original_Model_Version == "v1.5":
117
+ model="/datasets/stable-diffusion-classic/SDv1.5.ckpt"
118
  print('Using the original V1.5 model')
119
  elif Original_Model_Version == "v2-512":
120
+ model="/datasets/stable-diffusion-v2-1-base-diffusers/stable-diffusion-2-1-base/v2-1_512-nonema-pruned.safetensors"
121
+ print('Using the original V2-512 model')
 
 
 
 
 
 
 
122
  elif Original_Model_Version == "v2-768":
123
+ model="/datasets/stable-diffusion-v2-1/stable-diffusion-2-1/v2-1_768-nonema-pruned.safetensors"
124
  print('Using the original V2-768 model')
125
  else:
126
+ model=""
127
+ print('Wrong model version')
128
  try:
129
  model
130
  except:
131
+ model="/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion"
132
 
133
  return model
134
 
135
 
136
+ def CN(ControlNet_Model, ControlNet_v2_Model):
 
137
 
138
  def download(url, model_dir):
139
 
 
146
  print(f"The model {filename} already exists")
147
 
148
  wrngv1=False
149
+ os.chdir('/notebooks/sd/stable-diffusion-webui/extensions')
150
  if not os.path.exists("sd-webui-controlnet"):
151
  call('git clone https://github.com/Mikubill/sd-webui-controlnet.git', shell=True)
152
+ os.chdir('/notebooks')
153
  else:
154
  os.chdir('sd-webui-controlnet')
155
  call('git reset --hard', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
156
  call('git pull', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
157
+ os.chdir('/notebooks')
158
 
159
+ mdldir="/notebooks/sd/stable-diffusion-webui/extensions/sd-webui-controlnet/models"
160
  for filename in os.listdir(mdldir):
161
  if "_sd14v1" in filename:
162
  renamed = re.sub("_sd14v1", "-fp16", filename)
 
164
 
165
  call('wget -q -O CN_models.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models.txt', shell=True)
166
  call('wget -q -O CN_models_v2.txt https://github.com/TheLastBen/fast-stable-diffusion/raw/main/AUTOMATIC1111_files/CN_models_v2.txt', shell=True)
167
+
168
  with open("CN_models.txt", 'r') as f:
169
  mdllnk = f.read().splitlines()
170
  with open("CN_models_v2.txt", 'r') as d:
 
172
  call('rm CN_models.txt CN_models_v2.txt', shell=True)
173
 
174
  cfgnames=[os.path.basename(url).split('.')[0]+'.yaml' for url in mdllnk_v2]
175
+ os.chdir('/notebooks/sd/stable-diffusion-webui/extensions/sd-webui-controlnet/models')
176
  for name in cfgnames:
177
  run(['cp', 'cldm_v21.yaml', name])
178
+ os.chdir('/notebooks')
179
 
180
  if ControlNet_Model == "All" or ControlNet_Model == "all" :
181
  for lnk in mdllnk:
 
202
  print('Wrong ControlNet V1 choice, try again')
203
  wrngv1=True
204
 
 
205
  if ControlNet_v2_Model == "All" or ControlNet_v2_Model == "all" :
206
  for lnk_v2 in mdllnk_v2:
207
  download(lnk_v2, mdldir)
 
218
  elif ControlNet_v2_Model == "none":
219
  pass
220
  if not wrngv1:
221
+ clear_output()
222
  done()
223
 
224
  else:
 
226
 
227
 
228
 
 
229
 
230
+ def sd(User, Password, Use_localtunnel, model):
231
+
 
 
232
  auth=f"--gradio-auth {User}:{Password}"
233
  if User =="" or Password=="":
234
  auth=""
235
+
236
+ if not os.path.exists('/usr/lib/node_modules/localtunnel'):
237
+ call('npm install -g localtunnel --silent', shell=True, stdout=open('/dev/null', 'w'))
238
+ clear_output()
239
+
240
+
241
+ share=''
242
+ call('wget -q -O /usr/local/lib/python3.9/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py', shell=True)
243
+
244
+ if not Use_localtunnel:
245
+ share='--share'
246
+
247
+ else:
248
+ share=''
249
+ os.chdir('/notebooks')
250
+ call('nohup lt --port 7860 > srv.txt 2>&1 &', shell=True)
251
+ time.sleep(2)
252
+ call("grep -o 'https[^ ]*' /notebooks/srv.txt >srvr.txt", shell=True)
253
+ time.sleep(2)
254
+ srv= getoutput('cat /notebooks/srvr.txt')
255
+
256
+ for line in fileinput.input('/usr/local/lib/python3.9/dist-packages/gradio/blocks.py', inplace=True):
257
+ if line.strip().startswith('self.server_name ='):
258
+ line = f' self.server_name = "{srv[8:]}"\n'
259
+ if line.strip().startswith('self.server_port ='):
260
+ line = ' self.server_port = 443\n'
261
+ if line.strip().startswith('self.protocol = "https"'):
262
+ line = ' self.protocol = "https"\n'
263
+ if line.strip().startswith('if self.local_url.startswith("https") or self.is_colab'):
264
+ line = ''
265
+ if line.strip().startswith('else "http"'):
266
+ line = ''
267
+ sys.stdout.write(line)
268
+
269
+ call('rm srv.txt srvr.txt', shell=True)
270
+
271
+ os.chdir('/notebooks/sd/stable-diffusion-webui/modules')
272
  call('wget -q -O paths.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/paths.py', shell=True)
273
+ call("sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /notebooks/sd/stable-diffusion-webui/webui.py", shell=True)
274
+ call("sed -i 's@/content/gdrive/MyDrive/sd/stablediffusion@/notebooks/sd/stablediffusion@' /notebooks/sd/stable-diffusion-webui/modules/paths.py", shell=True)
275
+ call("sed -i 's@\"quicksettings\": OptionInfo(.*@\"quicksettings\": OptionInfo(\"sd_model_checkpoint, sd_vae, CLIP_stop_at_last_layers, inpainting_mask_weight, initial_noise_multiplier\", \"Quicksettings list\"),@' /notebooks/sd/stable-diffusion-webui/modules/shared.py", shell=True)
276
+ os.chdir('/notebooks/sd/stable-diffusion-webui')
277
  clear_output()
278
 
279
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  if os.path.isfile(model):
281
  mdlpth="--ckpt "+model
282
  else:
283
  mdlpth="--ckpt-dir "+model
284
 
 
 
 
285
 
286
+ configf="--disable-console-progressbars --no-half-vae --disable-safe-unpickle --api --no-download-sd-model --xformers --enable-insecure-extension-access --skip-version-check "+auth+" "+share+" "+mdlpth
287
 
288
+ return configf
289
 
 
 
290
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
291
  def done():
292
  done = widgets.Button(
293
  description='Done!',