TheLastBen commited on
Commit
4c8703a
1 Parent(s): 8547456

Update Scripts/mainpaperspacev2.py

Browse files
Files changed (1) hide show
  1. Scripts/mainpaperspacev2.py +29 -14
Scripts/mainpaperspacev2.py CHANGED
@@ -109,17 +109,22 @@ def downloadmodel_hfv2(Path_to_HuggingFace):
109
 
110
 
111
 
112
- def downloadmodel_pthv2(CKPT_Path, Custom_Model_Version):
 
 
 
 
 
113
  import wget
114
  os.chdir('/models')
115
- clear_output()
116
  if os.path.exists(str(CKPT_Path)):
117
  if Custom_Model_Version=='512':
118
  call('wget -q -O convertodiffv2.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertodiffv2.py', shell=True)
119
- call('python convertodiffv2.py '+CKPT_Path+' stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1-base', shell=True)
120
  elif Custom_Model_Version=='768':
121
  call('wget -q -O convertodiffv2.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertodiffv2-768.py', shell=True)
122
- call('python convertodiffv2.py '+CKPT_Path+' stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1', shell=True)
123
 
124
  call('rm convertodiffv2.py', shell=True)
125
  if os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
@@ -138,22 +143,32 @@ def downloadmodel_pthv2(CKPT_Path, Custom_Model_Version):
138
 
139
 
140
 
141
- def downloadmodel_lnkv2(CKPT_Link, Custom_Model_Version):
 
 
 
 
 
 
 
 
142
  import wget
143
  os.chdir('/models')
144
- call("gdown --fuzzy " +CKPT_Link+ " -O model.ckpt", shell=True)
145
 
146
- if os.path.exists('model.ckpt'):
147
- if os.path.getsize("model.ckpt") > 1810671599:
148
  if Custom_Model_Version=='512':
149
  call('wget -q -O convertodiffv2.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertodiffv2.py', shell=True)
150
- call('python convertodiffv2.py model.ckpt stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1-base', shell=True)
 
151
  elif Custom_Model_Version=='768':
152
  call('wget -q -O convertodiffv2.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertodiffv2-768.py', shell=True)
153
- call('python convertodiffv2.py model.ckpt stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1', shell=True)
154
  call('rm convertodiffv2.py', shell=True)
 
155
  if os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
156
- call('rm model.ckpt', shell=True)
157
  os.chdir('/notebooks')
158
  clear_output()
159
  done()
@@ -163,7 +178,7 @@ def downloadmodel_lnkv2(CKPT_Link, Custom_Model_Version):
163
  os.chdir('/notebooks')
164
  time.sleep(5)
165
  else:
166
- while os.path.getsize('/models/model.ckpt') < 1810671599:
167
  print('Wrong link, check that the link is valid')
168
  os.chdir('/notebooks')
169
  time.sleep(5)
@@ -176,10 +191,10 @@ def dlv2(Path_to_HuggingFace, CKPT_Path, CKPT_Link, Model_Version, Custom_Model_
176
  downloadmodel_hfv2(Path_to_HuggingFace)
177
  MODEL_NAMEv2="/models/stable-diffusion-custom"
178
  elif CKPT_Path !="":
179
- downloadmodel_pthv2(CKPT_Path, Custom_Model_Version)
180
  MODEL_NAMEv2="/models/stable-diffusion-custom"
181
  elif CKPT_Link !="":
182
- downloadmodel_lnkv2(CKPT_Link, Custom_Model_Version)
183
  MODEL_NAMEv2="/models/stable-diffusion-custom"
184
  else:
185
  if Model_Version=="512":
 
109
 
110
 
111
 
112
+ def downloadmodel_pthv2(CKPT_Path, Custom_Model_Version, safetensors):
113
+
114
+ sftnsr=""
115
+ if safetensors:
116
+ sftnsr="--from_safetensors"
117
+
118
  import wget
119
  os.chdir('/models')
120
+ clear_output()
121
  if os.path.exists(str(CKPT_Path)):
122
  if Custom_Model_Version=='512':
123
  call('wget -q -O convertodiffv2.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertodiffv2.py', shell=True)
124
+ call('python convertodiffv2.py '+CKPT_Path+' stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1-base '+sftnsr, shell=True)
125
  elif Custom_Model_Version=='768':
126
  call('wget -q -O convertodiffv2.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertodiffv2-768.py', shell=True)
127
+ call('python convertodiffv2.py '+CKPT_Path+' stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1 '+sftnsr, shell=True)
128
 
129
  call('rm convertodiffv2.py', shell=True)
130
  if os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
 
143
 
144
 
145
 
146
+ def downloadmodel_lnkv2(CKPT_Link, Custom_Model_Version, safetensors):
147
+
148
+ sftnsr=""
149
+ if not safetensors:
150
+ modelnm="model.ckpt"
151
+ else:
152
+ modelnm="model.safetensors"
153
+ sftnsr="--from_safetensors"
154
+
155
  import wget
156
  os.chdir('/models')
157
+ call("gdown --fuzzy " +CKPT_Link+ " -O /models/"+modelnm, shell=True)
158
 
159
+ if os.path.exists("/models/"+modelnm):
160
+ if os.path.getsize("/models/"+modelnm) > 1810671599:
161
  if Custom_Model_Version=='512':
162
  call('wget -q -O convertodiffv2.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertodiffv2.py', shell=True)
163
+ call('python convertodiffv2.py /models/'+modelnm+' stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1-base '+sftnsr, shell=True)
164
+
165
  elif Custom_Model_Version=='768':
166
  call('wget -q -O convertodiffv2.py https://github.com/TheLastBen/fast-stable-diffusion/raw/main/Dreambooth/convertodiffv2-768.py', shell=True)
167
+ call('python convertodiffv2.py /models/'+modelnm+' stable-diffusion-custom --v2 --reference_model stabilityai/stable-diffusion-2-1 '+sftnsr, shell=True)
168
  call('rm convertodiffv2.py', shell=True)
169
+
170
  if os.path.exists('stable-diffusion-custom/unet/diffusion_pytorch_model.bin'):
171
+ call('rm /models/'+modelnm, shell=True)
172
  os.chdir('/notebooks')
173
  clear_output()
174
  done()
 
178
  os.chdir('/notebooks')
179
  time.sleep(5)
180
  else:
181
+ while os.path.getsize("/models/"+modelnm) < 1810671599:
182
  print('Wrong link, check that the link is valid')
183
  os.chdir('/notebooks')
184
  time.sleep(5)
 
191
  downloadmodel_hfv2(Path_to_HuggingFace)
192
  MODEL_NAMEv2="/models/stable-diffusion-custom"
193
  elif CKPT_Path !="":
194
+ downloadmodel_pthv2(CKPT_Path, Custom_Model_Version, safetensors)
195
  MODEL_NAMEv2="/models/stable-diffusion-custom"
196
  elif CKPT_Link !="":
197
+ downloadmodel_lnkv2(CKPT_Link, Custom_Model_Version, safetensors)
198
  MODEL_NAMEv2="/models/stable-diffusion-custom"
199
  else:
200
  if Model_Version=="512":