forked from runew0lf/RuinedFooocus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.py
More file actions
247 lines (212 loc) · 7.55 KB
/
launch.py
File metadata and controls
247 lines (212 loc) · 7.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import os
import sys
import platform
import version
import warnings
from pathlib import Path
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
warnings.filterwarnings("ignore", category=FutureWarning, module="insightface")
warnings.filterwarnings("ignore", category=UserWarning, module="torchvision")
warnings.filterwarnings("ignore", category=UserWarning, module="gradio")
warnings.filterwarnings("ignore", category=UserWarning, module="torchsde")
warnings.filterwarnings("ignore", category=UserWarning)
warnings.filterwarnings(
"ignore", category=UserWarning, module="torchvision.transforms.functional_tensor"
)
warnings.filterwarnings(
"ignore", category=UserWarning, message="TypedStorage is deprecated"
)
from modules.launch_util import (
is_installed,
run,
python,
run_pip,
repo_dir,
git_clone,
requirements_met,
script_path,
dir_repos,
)
from modules.util import load_file_from_url
from shared import path_manager
REINSTALL_ALL = False
if os.path.exists("reinstall"):
REINSTALL_ALL = True
def prepare_environment():
torch_index_url = os.environ.get(
"TORCH_INDEX_URL", "https://download.pytorch.org/whl/cu121"
)
torch_command = os.environ.get(
"TORCH_COMMAND",
f"pip install torch==2.1.2 torchvision==0.16.2 --extra-index-url {torch_index_url}",
)
insightface_package = os.environ.get(
"INSIGHTFACE_PACKAGE",
f"https://github.com/Gourieff/sd-webui-reactor/raw/main/example/insightface-0.7.3-cp310-cp310-win_amd64.whl",
)
requirements_file = os.environ.get("REQS_FILE", "requirements_versions.txt")
xformers_package = os.environ.get("XFORMERS_PACKAGE", "xformers==0.0.23")
comfy_repo = os.environ.get(
"COMFY_REPO", "https://github.com/comfyanonymous/ComfyUI"
)
comfy_commit_hash = os.environ.get(
"COMFY_COMMIT_HASH", "1281f933c1c38ac0491ff2f86cbcd2ec90743ce3"
)
print(f"Python {sys.version}")
print(f"RuinedFooocus version: {version.version}")
comfyui_name = "ComfyUI-from-StabilityAI-Official"
git_clone(comfy_repo, repo_dir(comfyui_name), "Comfy Backend", comfy_commit_hash)
path = Path(script_path) / dir_repos / comfyui_name
sys.path.append(str(path))
if REINSTALL_ALL or not is_installed("torch") or not is_installed("torchvision"):
run(
f'"{python}" -m {torch_command}',
"Installing torch and torchvision",
"Couldn't install torch",
live=True,
)
if REINSTALL_ALL or not is_installed("xformers"):
if platform.system() == "Windows":
if platform.python_version().startswith("3.10"):
run_pip(
f"install -U -I --no-deps {xformers_package}", "xformers", live=True
)
else:
print(
"Installation of xformers is not supported in this version of Python."
)
print(
"You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness"
)
if not is_installed("xformers"):
exit(0)
elif platform.system() == "Linux":
run_pip(f"install -U -I --no-deps {xformers_package}", "xformers")
if REINSTALL_ALL or not requirements_met(requirements_file):
run_pip(f'install -r "{requirements_file}"', "requirements")
return
model_filenames = [
(
"sd_xl_base_1.0_0.9vae.safetensors",
"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0_0.9vae.safetensors",
),
]
lora_filenames = [
(
"sd_xl_offset_example-lora_1.0.safetensors",
"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_offset_example-lora_1.0.safetensors",
),
(
"lcm-lora-sdxl.safetensors",
"https://huggingface.co/latent-consistency/lcm-lora-sdxl/resolve/main/pytorch_lora_weights.safetensors",
),
(
"lcm-lora-ssd-1b.safetensors",
"https://huggingface.co/latent-consistency/lcm-lora-ssd-1b/resolve/main/pytorch_lora_weights.safetensors",
),
]
vae_approx_filenames = [
(
"taesdxl_decoder",
"https://github.com/madebyollin/taesd/raw/main/taesdxl_decoder.pth",
)
]
controlnet_filenames = [
(
"control-lora-canny-rank128.safetensors",
"https://huggingface.co/stabilityai/control-lora/resolve/main/control-LoRAs-rank128/control-lora-canny-rank128.safetensors",
),
(
"control-lora-depth-rank128.safetensors",
"https://huggingface.co/stabilityai/control-lora/resolve/main/control-LoRAs-rank128/control-lora-depth-rank128.safetensors",
),
(
"control-lora-recolor-rank128.safetensors",
"https://huggingface.co/stabilityai/control-lora/resolve/main/control-LoRAs-rank128/control-lora-recolor-rank128.safetensors",
),
(
"control-lora-sketch-rank128-metadata.safetensors",
"https://huggingface.co/stabilityai/control-lora/resolve/main/control-LoRAs-rank128/control-lora-sketch-rank128-metadata.safetensors",
),
]
upscaler_filenames = [
(
"4x-UltraSharp.pth",
"https://huggingface.co/lokCX/4x-Ultrasharp/resolve/main/4x-UltraSharp.pth",
),
]
magic_prompt_filenames = [
(
"pytorch_model.bin",
"https://huggingface.co/lllyasviel/misc/resolve/main/fooocus_expansion.bin",
),
]
layer_diffuse_filenames = [
(
"layer_xl_transparent_attn.safetensors",
"https://huggingface.co/LayerDiffusion/layerdiffusion-v1/resolve/main/layer_xl_transparent_attn.safetensors",
),
(
"vae_transparent_decoder.safetensors",
"https://huggingface.co/LayerDiffusion/layerdiffusion-v1/resolve/main/vae_transparent_decoder.safetensors",
),
]
def download_models():
for file_name, url in model_filenames:
load_file_from_url(
url=url,
model_dir=path_manager.model_paths["modelfile_path"],
file_name=file_name,
)
for file_name, url in lora_filenames:
load_file_from_url(
url=url,
model_dir=path_manager.model_paths["lorafile_path"],
file_name=file_name,
)
for file_name, url in controlnet_filenames:
load_file_from_url(
url=url,
model_dir=path_manager.model_paths["controlnet_path"],
file_name=file_name,
)
for file_name, url in vae_approx_filenames:
load_file_from_url(
url=url,
model_dir=path_manager.model_paths["vae_approx_path"],
file_name=file_name,
)
for file_name, url in upscaler_filenames:
load_file_from_url(
url=url,
model_dir=path_manager.model_paths["upscaler_path"],
file_name=file_name,
)
for file_name, url in magic_prompt_filenames:
load_file_from_url(
url=url,
model_dir="prompt_expansion",
file_name=file_name,
)
for file_name, url in layer_diffuse_filenames:
load_file_from_url(
url=url,
model_dir="models/layerdiffuse/",
file_name=file_name,
)
return
def clear_comfy_args():
argv = sys.argv
sys.argv = [sys.argv[0]]
import comfy.cli_args
sys.argv = argv
def cuda_malloc():
import cuda_malloc
prepare_environment()
if os.path.exists("reinstall"):
os.remove("reinstall")
clear_comfy_args()
# cuda_malloc()
download_models()
from webui import *