apollo812 commited on
Commit
1b0d7bf
1 Parent(s): 7d283a7

Update Scripts/runpodSD.py

Browse files
Files changed (1) hide show
  1. Scripts/runpodSD.py +28 -28
Scripts/runpodSD.py CHANGED
@@ -114,7 +114,7 @@ def repo(Huggingface_token_optional):
114
  call('tar --zstd -xf sd_mrep.tar.zst', shell=True)
115
  call('rm sd_mrep.tar.zst', shell=True)
116
  os.chdir('/workspace/sd')
117
- if not os.path.exists('stable-diffusion-webui'):
118
  call('git clone -q --depth 1 --branch main https://github.com/apollo812/SD', shell=True)
119
 
120
  else:
@@ -126,11 +126,11 @@ def repo(Huggingface_token_optional):
126
  call('rm sd_mrep.tar.zst', shell=True)
127
 
128
  os.chdir('/workspace/sd')
129
- if not os.path.exists('stable-diffusion-webui'):
130
  call('git clone -q --depth 1 --branch main https://github.com/apollo812/SD', shell=True)
131
 
132
 
133
- os.chdir('/workspace/sd/stable-diffusion-webui/')
134
  call('git reset --hard', shell=True)
135
  print('')
136
  call('git pull', shell=True)
@@ -146,8 +146,8 @@ def mdl(Original_Model_Version, Path_to_MODEL, MODEL_LINK):
146
 
147
  src=getsrc(MODEL_LINK)
148
 
149
- if not os.path.exists('/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/SDv1-5.ckpt'):
150
- call('ln -s /workspace/auto-models/* /workspace/sd/stable-diffusion-webui/models/Stable-diffusion', shell=True)
151
 
152
  if Path_to_MODEL !='':
153
  if os.path.exists(str(Path_to_MODEL)):
@@ -160,7 +160,7 @@ def mdl(Original_Model_Version, Path_to_MODEL, MODEL_LINK):
160
 
161
  if src=='civitai':
162
  modelname=get_name(MODEL_LINK, False)
163
- model=f'/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/{modelname}'
164
  if not os.path.exists(model):
165
  dwn(MODEL_LINK, model, 'Downloading the custom model')
166
  clear_output()
@@ -168,7 +168,7 @@ def mdl(Original_Model_Version, Path_to_MODEL, MODEL_LINK):
168
  print('Model already exists')
169
  elif src=='gdrive':
170
  modelname=get_name(MODEL_LINK, True)
171
- model=f'/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/{modelname}'
172
  if not os.path.exists(model):
173
  gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)
174
  clear_output()
@@ -176,7 +176,7 @@ def mdl(Original_Model_Version, Path_to_MODEL, MODEL_LINK):
176
  print('Model already exists')
177
  else:
178
  modelname=os.path.basename(MODEL_LINK)
179
- model=f'/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/{modelname}'
180
  if not os.path.exists(model):
181
  gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)
182
  clear_output()
@@ -191,29 +191,29 @@ def mdl(Original_Model_Version, Path_to_MODEL, MODEL_LINK):
191
 
192
  else:
193
  if Original_Model_Version == "v1.5":
194
- model="/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/SDv1-5.ckpt"
195
  print('Using the original V1.5 model')
196
  elif Original_Model_Version == "v2-512":
197
- model='/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/SDv2-512.ckpt'
198
- if not os.path.exists('/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/SDv2-512.ckpt'):
199
  print('Downloading the V2-512 model...')
200
  call('gdown -O '+model+' https://huggingface.co/stabilityai/stable-diffusion-2-1-base/resolve/main/v2-1_512-nonema-pruned.ckpt', shell=True)
201
  clear_output()
202
  print('Using the original V2-512 model')
203
  elif Original_Model_Version == "v2-768":
204
- model="/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/SDv2-768.ckpt"
205
  print('Using the original V2-768 model')
206
  elif Original_Model_Version == "SDXL":
207
- model="/workspace/sd/stable-diffusion-webui/models/Stable-diffusion/sd_xl_base_1.0.safetensors"
208
  print('Using the original SDXL model')
209
 
210
  else:
211
- model="/workspace/sd/stable-diffusion-webui/models/Stable-diffusion"
212
  print('Wrong model version, try again')
213
  try:
214
  model
215
  except:
216
- model="/workspace/sd/stable-diffusion-webui/models/Stable-diffusion"
217
 
218
  return model
219
 
@@ -223,13 +223,13 @@ def loradwn(LoRA_LINK):
223
  if LoRA_LINK=='':
224
  print('Nothing to do')
225
  else:
226
- os.makedirs('/workspace/sd/stable-diffusion-webui/models/Lora', exist_ok=True)
227
 
228
  src=getsrc(LoRA_LINK)
229
 
230
  if src=='civitai':
231
  modelname=get_name(LoRA_LINK, False)
232
- loramodel=f'/workspace/sd/stable-diffusion-webui/models/Lora/{modelname}'
233
  if not os.path.exists(loramodel):
234
  dwn(LoRA_LINK, loramodel, 'Downloading the LoRA model')
235
  clear_output()
@@ -237,7 +237,7 @@ def loradwn(LoRA_LINK):
237
  print('Model already exists')
238
  elif src=='gdrive':
239
  modelname=get_name(LoRA_LINK, True)
240
- loramodel=f'/workspace/sd/stable-diffusion-webui/models/Lora/{modelname}'
241
  if not os.path.exists(loramodel):
242
  gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)
243
  clear_output()
@@ -245,7 +245,7 @@ def loradwn(LoRA_LINK):
245
  print('Model already exists')
246
  else:
247
  modelname=os.path.basename(LoRA_LINK)
248
- loramodel=f'/workspace/sd/stable-diffusion-webui/models/Lora/{modelname}'
249
  if not os.path.exists(loramodel):
250
  gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)
251
  clear_output()
@@ -272,7 +272,7 @@ def CNet(ControlNet_Model, ControlNet_XL_Model):
272
  print(f"The model {filename} already exists")
273
 
274
  wrngv1=False
275
- os.chdir('/workspace/sd/stable-diffusion-webui/extensions')
276
  if not os.path.exists("sd-webui-controlnet"):
277
  call('git clone https://github.com/Mikubill/sd-webui-controlnet.git', shell=True)
278
  os.chdir('/workspace')
@@ -282,7 +282,7 @@ def CNet(ControlNet_Model, ControlNet_XL_Model):
282
  call('git pull', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
283
  os.chdir('/workspace')
284
 
285
- mdldir="/workspace/sd/stable-diffusion-webui/extensions/sd-webui-controlnet/models"
286
  for filename in os.listdir(mdldir):
287
  if "_sd14v1" in filename:
288
  renamed = re.sub("_sd14v1", "-fp16", filename)
@@ -361,16 +361,16 @@ def sd(User, Password, model):
361
 
362
  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)
363
 
364
- os.chdir('/workspace/sd/stable-diffusion-webui/modules')
365
 
366
- call("sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\"/workspace/sd/stablediffusion\"]@' /workspace/sd/stable-diffusion-webui/modules/paths.py", shell=True)
367
- call("sed -i 's@\.\.\/@src/@g' /workspace/sd/stable-diffusion-webui/modules/paths.py", shell=True)
368
- call("sed -i 's@src\/generative-models@generative-models@g' /workspace/sd/stable-diffusion-webui/modules/paths.py", shell=True)
369
 
370
- call("sed -i 's@\[\"sd_model_checkpoint\"\]@\[\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \"inpainting_mask_weight\", \"initial_noise_multiplier\"\]@g' /workspace/sd/stable-diffusion-webui/modules/shared.py", shell=True)
371
 
372
  call("sed -i 's@print(\"No module.*@@' /workspace/sd/stablediffusion/ldm/modules/diffusionmodules/model.py", shell=True)
373
- os.chdir('/workspace/sd/stable-diffusion-webui')
374
  clear_output()
375
 
376
  podid=os.environ.get('RUNPOD_POD_ID')
@@ -414,7 +414,7 @@ def save(Huggingface_Write_token):
414
 
415
  if os.path.exists('sd'):
416
 
417
- call('tar --exclude="stable-diffusion-webui/models/*/*" --exclude="sd-webui-controlnet/models/*" --zstd -cf sd_backup_rnpd.tar.zst sd', shell=True)
418
  api = HfApi()
419
  username = api.whoami(token=Huggingface_Write_token)["name"]
420
 
 
114
  call('tar --zstd -xf sd_mrep.tar.zst', shell=True)
115
  call('rm sd_mrep.tar.zst', shell=True)
116
  os.chdir('/workspace/sd')
117
+ if not os.path.exists('SD'):
118
  call('git clone -q --depth 1 --branch main https://github.com/apollo812/SD', shell=True)
119
 
120
  else:
 
126
  call('rm sd_mrep.tar.zst', shell=True)
127
 
128
  os.chdir('/workspace/sd')
129
+ if not os.path.exists('SD'):
130
  call('git clone -q --depth 1 --branch main https://github.com/apollo812/SD', shell=True)
131
 
132
 
133
+ os.chdir('/workspace/sd/SD/')
134
  call('git reset --hard', shell=True)
135
  print('')
136
  call('git pull', shell=True)
 
146
 
147
  src=getsrc(MODEL_LINK)
148
 
149
+ if not os.path.exists('/workspace/sd/SD/models/Stable-diffusion/SDv1-5.ckpt'):
150
+ call('ln -s /workspace/auto-models/* /workspace/sd/SD/models/Stable-diffusion', shell=True)
151
 
152
  if Path_to_MODEL !='':
153
  if os.path.exists(str(Path_to_MODEL)):
 
160
 
161
  if src=='civitai':
162
  modelname=get_name(MODEL_LINK, False)
163
+ model=f'/workspace/sd/SD/models/Stable-diffusion/{modelname}'
164
  if not os.path.exists(model):
165
  dwn(MODEL_LINK, model, 'Downloading the custom model')
166
  clear_output()
 
168
  print('Model already exists')
169
  elif src=='gdrive':
170
  modelname=get_name(MODEL_LINK, True)
171
+ model=f'/workspace/sd/SD/models/Stable-diffusion/{modelname}'
172
  if not os.path.exists(model):
173
  gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)
174
  clear_output()
 
176
  print('Model already exists')
177
  else:
178
  modelname=os.path.basename(MODEL_LINK)
179
+ model=f'/workspace/sd/SD/models/Stable-diffusion/{modelname}'
180
  if not os.path.exists(model):
181
  gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)
182
  clear_output()
 
191
 
192
  else:
193
  if Original_Model_Version == "v1.5":
194
+ model="/workspace/sd/SD/models/Stable-diffusion/SDv1-5.ckpt"
195
  print('Using the original V1.5 model')
196
  elif Original_Model_Version == "v2-512":
197
+ model='/workspace/sd/SD/models/Stable-diffusion/SDv2-512.ckpt'
198
+ if not os.path.exists('/workspace/sd/SD/models/Stable-diffusion/SDv2-512.ckpt'):
199
  print('Downloading the V2-512 model...')
200
  call('gdown -O '+model+' https://huggingface.co/stabilityai/stable-diffusion-2-1-base/resolve/main/v2-1_512-nonema-pruned.ckpt', shell=True)
201
  clear_output()
202
  print('Using the original V2-512 model')
203
  elif Original_Model_Version == "v2-768":
204
+ model="/workspace/sd/SD/models/Stable-diffusion/SDv2-768.ckpt"
205
  print('Using the original V2-768 model')
206
  elif Original_Model_Version == "SDXL":
207
+ model="/workspace/sd/SD/models/Stable-diffusion/sd_xl_base_1.0.safetensors"
208
  print('Using the original SDXL model')
209
 
210
  else:
211
+ model="/workspace/sd/SD/models/Stable-diffusion"
212
  print('Wrong model version, try again')
213
  try:
214
  model
215
  except:
216
+ model="/workspace/sd/SD/models/Stable-diffusion"
217
 
218
  return model
219
 
 
223
  if LoRA_LINK=='':
224
  print('Nothing to do')
225
  else:
226
+ os.makedirs('/workspace/sd/SD/models/Lora', exist_ok=True)
227
 
228
  src=getsrc(LoRA_LINK)
229
 
230
  if src=='civitai':
231
  modelname=get_name(LoRA_LINK, False)
232
+ loramodel=f'/workspace/sd/SD/models/Lora/{modelname}'
233
  if not os.path.exists(loramodel):
234
  dwn(LoRA_LINK, loramodel, 'Downloading the LoRA model')
235
  clear_output()
 
237
  print('Model already exists')
238
  elif src=='gdrive':
239
  modelname=get_name(LoRA_LINK, True)
240
+ loramodel=f'/workspace/sd/SD/models/Lora/{modelname}'
241
  if not os.path.exists(loramodel):
242
  gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)
243
  clear_output()
 
245
  print('Model already exists')
246
  else:
247
  modelname=os.path.basename(LoRA_LINK)
248
+ loramodel=f'/workspace/sd/SD/models/Lora/{modelname}'
249
  if not os.path.exists(loramodel):
250
  gdown.download(url=LoRA_LINK, output=loramodel, quiet=False, fuzzy=True)
251
  clear_output()
 
272
  print(f"The model {filename} already exists")
273
 
274
  wrngv1=False
275
+ os.chdir('/workspace/sd/SD/extensions')
276
  if not os.path.exists("sd-webui-controlnet"):
277
  call('git clone https://github.com/Mikubill/sd-webui-controlnet.git', shell=True)
278
  os.chdir('/workspace')
 
282
  call('git pull', shell=True, stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
283
  os.chdir('/workspace')
284
 
285
+ mdldir="/workspace/sd/SD/extensions/sd-webui-controlnet/models"
286
  for filename in os.listdir(mdldir):
287
  if "_sd14v1" in filename:
288
  renamed = re.sub("_sd14v1", "-fp16", filename)
 
361
 
362
  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)
363
 
364
+ os.chdir('/workspace/sd/SD/modules')
365
 
366
+ call("sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\"/workspace/sd/stablediffusion\"]@' /workspace/sd/SD/modules/paths.py", shell=True)
367
+ call("sed -i 's@\.\.\/@src/@g' /workspace/sd/SD/modules/paths.py", shell=True)
368
+ call("sed -i 's@src\/generative-models@generative-models@g' /workspace/sd/SD/modules/paths.py", shell=True)
369
 
370
+ call("sed -i 's@\[\"sd_model_checkpoint\"\]@\[\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \"inpainting_mask_weight\", \"initial_noise_multiplier\"\]@g' /workspace/sd/SD/modules/shared.py", shell=True)
371
 
372
  call("sed -i 's@print(\"No module.*@@' /workspace/sd/stablediffusion/ldm/modules/diffusionmodules/model.py", shell=True)
373
+ os.chdir('/workspace/sd/SD')
374
  clear_output()
375
 
376
  podid=os.environ.get('RUNPOD_POD_ID')
 
414
 
415
  if os.path.exists('sd'):
416
 
417
+ call('tar --exclude="SD/models/*/*" --exclude="sd-webui-controlnet/models/*" --zstd -cf sd_backup_rnpd.tar.zst sd', shell=True)
418
  api = HfApi()
419
  username = api.whoami(token=Huggingface_Write_token)["name"]
420