Commit
·
ea27184
1
Parent(s):
b3ad617
Upload mainpaperspaceA1111.py
Browse files- Scripts/mainpaperspaceA1111.py +110 -0
Scripts/mainpaperspaceA1111.py
CHANGED
@@ -172,6 +172,116 @@ def mdl(Original_Model_Version, Path_to_MODEL, MODEL_LINK, safetensors, Temporar
|
|
172 |
return model
|
173 |
|
174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
def CN(ControlNet_Model, ControlNet_v2_Model):
|
176 |
|
177 |
def download(url, model_dir):
|
|
|
172 |
return model
|
173 |
|
174 |
|
175 |
+
|
176 |
+
def mdls(Original_Model_Version, Path_to_MODEL, MODEL_LINK, Temporary_Storage):
|
177 |
+
|
178 |
+
import gdown
|
179 |
+
from gdown.download import get_url_from_gdrive_confirmation
|
180 |
+
|
181 |
+
def getsrc(url):
|
182 |
+
parsed_url = urlparse(url)
|
183 |
+
if parsed_url.netloc == 'civitai.com':
|
184 |
+
src='civitai'
|
185 |
+
elif parsed_url.netloc == 'drive.google.com':
|
186 |
+
src='gdrive'
|
187 |
+
elif parsed_url.netloc == 'huggingface.co':
|
188 |
+
src='huggingface'
|
189 |
+
else:
|
190 |
+
src='others'
|
191 |
+
return src
|
192 |
+
|
193 |
+
src=getsrc(MODEL_LINK)
|
194 |
+
|
195 |
+
def get_name(url, gdrive):
|
196 |
+
if not gdrive:
|
197 |
+
response = requests.get(url, allow_redirects=False)
|
198 |
+
if "Location" in response.headers:
|
199 |
+
redirected_url = response.headers["Location"]
|
200 |
+
quer = parse_qs(urlparse(redirected_url).query)
|
201 |
+
if "response-content-disposition" in quer:
|
202 |
+
disp_val = quer["response-content-disposition"][0].split(";")
|
203 |
+
for vals in disp_val:
|
204 |
+
if vals.strip().startswith("filename="):
|
205 |
+
filenm=unquote(vals.split("=", 1)[1].strip())
|
206 |
+
return filenm.replace("\"","")
|
207 |
+
else:
|
208 |
+
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"}
|
209 |
+
lnk="https://drive.google.com/uc?id={id}&export=download".format(id=url[url.find("/d/")+3:url.find("/view")])
|
210 |
+
res = requests.session().get(lnk, headers=headers, stream=True, verify=True)
|
211 |
+
res = requests.session().get(get_url_from_gdrive_confirmation(res.text), headers=headers, stream=True, verify=True)
|
212 |
+
content_disposition = six.moves.urllib_parse.unquote(res.headers["Content-Disposition"])
|
213 |
+
filenm = re.search(r"filename\*=UTF-8''(.*)", content_disposition).groups()[0].replace(os.path.sep, "_")
|
214 |
+
return filenm
|
215 |
+
|
216 |
+
|
217 |
+
if Path_to_MODEL !='':
|
218 |
+
if os.path.exists(str(Path_to_MODEL)):
|
219 |
+
print('[1;32mUsing the custom model.')
|
220 |
+
model=Path_to_MODEL
|
221 |
+
else:
|
222 |
+
print('[1;31mWrong path, check that the path to the model is correct')
|
223 |
+
|
224 |
+
elif MODEL_LINK !="":
|
225 |
+
|
226 |
+
if src=='civitai':
|
227 |
+
modelname=get_name(MODEL_LINK, False)
|
228 |
+
if Temporary_Storage:
|
229 |
+
model=f'/models/{modelname}'
|
230 |
+
else:
|
231 |
+
model=f'/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/{modelname}'
|
232 |
+
dwn(MODEL_LINK, model, 'Downloading the custom model')
|
233 |
+
elif src=='gdrive':
|
234 |
+
modelname=get_name(MODEL_LINK, True)
|
235 |
+
if Temporary_Storage:
|
236 |
+
model=f'/models/{modelname}'
|
237 |
+
else:
|
238 |
+
model=f'/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/{modelname}'
|
239 |
+
gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)
|
240 |
+
else:
|
241 |
+
modelname=os.path.basename(MODEL_LINK)
|
242 |
+
if Temporary_Storage:
|
243 |
+
model=f'/models/{modelname}'
|
244 |
+
else:
|
245 |
+
model=f'/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/{modelname}'
|
246 |
+
gdown.download(url=MODEL_LINK, output=model, quiet=False, fuzzy=True)
|
247 |
+
|
248 |
+
if os.path.exists(model) and os.path.getsize(model) > 1810671599:
|
249 |
+
clear_output()
|
250 |
+
print('[1;32mModel downloaded, using the custom model.')
|
251 |
+
else:
|
252 |
+
print('[1;31mWrong link, check that the link is valid')
|
253 |
+
|
254 |
+
else:
|
255 |
+
if Original_Model_Version == "v1.5":
|
256 |
+
model="/datasets/stable-diffusion-classic/SDv1.5.ckpt"
|
257 |
+
print('[1;32mUsing the original V1.5 model')
|
258 |
+
elif Original_Model_Version == "v2-512":
|
259 |
+
model="/datasets/stable-diffusion-v2-1-base-diffusers/stable-diffusion-2-1-base/v2-1_512-nonema-pruned.safetensors"
|
260 |
+
print('[1;32mUsing the original V2-512 model')
|
261 |
+
elif Original_Model_Version == "v2-768":
|
262 |
+
model="/datasets/stable-diffusion-v2-1/stable-diffusion-2-1/v2-1_768-nonema-pruned.safetensors"
|
263 |
+
print('[1;32mUsing the original V2-768 model')
|
264 |
+
elif Original_Model_Version == "SDXL":
|
265 |
+
model="/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/sd_xl_base_1.0.safetensors"
|
266 |
+
if not os.path.exists('/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion/sd_xl_base_1.0.safetensors'):
|
267 |
+
print('[1;33mDownloading SDXL...')
|
268 |
+
call('gdown -O '+model+' https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors', shell=True)
|
269 |
+
clear_output()
|
270 |
+
print('[1;32mUsing the original SDXL model')
|
271 |
+
|
272 |
+
else:
|
273 |
+
model="/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion"
|
274 |
+
print('[1;31mWrong model version, try again')
|
275 |
+
try:
|
276 |
+
model
|
277 |
+
except:
|
278 |
+
model="/notebooks/sd/stable-diffusion-webui/models/Stable-diffusion"
|
279 |
+
|
280 |
+
return model
|
281 |
+
|
282 |
+
|
283 |
+
|
284 |
+
|
285 |
def CN(ControlNet_Model, ControlNet_v2_Model):
|
286 |
|
287 |
def download(url, model_dir):
|