lllyasviel commited on
Commit
0b33786
·
1 Parent(s): 5f247be
Files changed (3) hide show
  1. launch.py +15 -1
  2. model_files/tmp30tvf0zr +0 -0
  3. modules/model_loader.py +25 -0
launch.py CHANGED
@@ -4,6 +4,7 @@ import platform
4
 
5
  from modules.launch_util import commit_hash, fooocus_tag, is_installed, run, python, \
6
  run_pip, repo_dir, git_clone, requirements_met, script_path, dir_repos
 
7
 
8
 
9
  REINSTALL_ALL = False
@@ -51,8 +52,21 @@ def prepare_environment():
51
  return
52
 
53
 
54
- prepare_environment()
 
 
 
 
 
 
 
 
 
 
 
55
 
 
 
56
 
57
  from webui import *
58
 
 
4
 
5
  from modules.launch_util import commit_hash, fooocus_tag, is_installed, run, python, \
6
  run_pip, repo_dir, git_clone, requirements_met, script_path, dir_repos
7
+ from modules.model_loader import load_file_from_url
8
 
9
 
10
  REINSTALL_ALL = False
 
52
  return
53
 
54
 
55
+ model_file_path = os.path.abspath('./model_files/')
56
+ model_filenames = [
57
+ ('sd_xl_base_1.0.safetensors', 'https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'),
58
+ ('sd_xl_refiner_1.0.safetensors', 'https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors')
59
+ ]
60
+
61
+
62
+ def download_models():
63
+ for file_name, url in model_filenames:
64
+ load_file_from_url(url=url, model_dir=model_file_path, file_name=file_name)
65
+ return
66
+
67
 
68
+ prepare_environment()
69
+ download_models()
70
 
71
  from webui import *
72
 
model_files/tmp30tvf0zr ADDED
File without changes
modules/model_loader.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from urllib.parse import urlparse
3
+
4
+
5
+ def load_file_from_url(
6
+ url: str,
7
+ *,
8
+ model_dir: str,
9
+ progress: bool = True,
10
+ file_name: str | None = None,
11
+ ) -> str:
12
+ """Download a file from `url` into `model_dir`, using the file present if possible.
13
+
14
+ Returns the path to the downloaded file.
15
+ """
16
+ os.makedirs(model_dir, exist_ok=True)
17
+ if not file_name:
18
+ parts = urlparse(url)
19
+ file_name = os.path.basename(parts.path)
20
+ cached_file = os.path.abspath(os.path.join(model_dir, file_name))
21
+ if not os.path.exists(cached_file):
22
+ print(f'Downloading: "{url}" to {cached_file}\n')
23
+ from torch.hub import download_url_to_file
24
+ download_url_to_file(url, cached_file, progress=progress)
25
+ return cached_file