Update sd_launch.py
Browse files- sd_launch.py +136 -43
sd_launch.py
CHANGED
@@ -1,38 +1,72 @@
|
|
1 |
import os
|
2 |
-
|
|
|
3 |
|
4 |
-
|
5 |
-
python = launch_utils.python
|
6 |
-
git = launch_utils.git
|
7 |
-
index_url = launch_utils.index_url
|
8 |
-
dir_repos = launch_utils.dir_repos
|
9 |
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
16 |
|
17 |
-
|
18 |
-
check_run_python = launch_utils.check_run_python
|
19 |
-
git_clone = launch_utils.git_clone
|
20 |
-
git_pull_recursive = launch_utils.git_pull_recursive
|
21 |
-
list_extensions = launch_utils.list_extensions
|
22 |
-
run_extension_installer = launch_utils.run_extension_installer
|
23 |
-
prepare_environment = launch_utils.prepare_environment
|
24 |
-
configure_for_tests = launch_utils.configure_for_tests
|
25 |
-
start = launch_utils.start
|
26 |
|
|
|
|
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
|
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
import requests
|
37 |
def get_daily_sentence(types=['a']):
|
38 |
params = {
|
@@ -44,40 +78,99 @@ def main():
|
|
44 |
return "\033[36m\033[4m" + data["hitokoto"] + "\033[0m"
|
45 |
else:
|
46 |
return " \033[36m\033[4m静待花开会有时,守得云开见月明\033[0m"
|
47 |
-
daily_sentence = get_daily_sentence(['i',])
|
48 |
|
49 |
def count_execution():
|
50 |
-
if not os.path.exists("/mnt/workspace/
|
51 |
-
with open("/mnt/workspace/
|
52 |
f.write("0")
|
53 |
-
with open("/mnt/workspace/
|
54 |
count = int(f.read())
|
55 |
count += 1
|
56 |
-
with open("/mnt/workspace/
|
57 |
f.write(str(count))
|
58 |
return count
|
59 |
count=count_execution()
|
60 |
if(count<6):
|
61 |
print(f"这是您在本实例中第{count}次启动SD")
|
62 |
-
print("👇请往下滑点击蓝色的\033[34m http:\\\\0.0.0.0:6666\033[0m 打开SD界面👇")
|
63 |
if(count>5):
|
64 |
print(daily_sentence)
|
65 |
-
print(f"这是您在本实例中第{count}次启动
|
66 |
-
print("
|
67 |
if os.path.exists("/mnt/workspace/Untitled.ipynb"):
|
68 |
os.remove("/mnt/workspace/Untitled.ipynb")
|
69 |
if os.path.exists("/mnt/workspace/不会用点我.jpg"):
|
70 |
os.remove("/mnt/workspace/不会用点我.jpg")
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
-
|
74 |
-
if not args.skip_prepare_environment:
|
75 |
-
prepare_environment()
|
76 |
|
77 |
-
if args.test_server:
|
78 |
-
configure_for_tests()
|
79 |
|
80 |
-
|
|
|
|
|
81 |
|
82 |
-
|
83 |
-
|
|
|
1 |
import os
|
2 |
+
import ssl
|
3 |
+
import sys
|
4 |
|
5 |
+
print('[System ARGV] ' + str(sys.argv))
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
root = os.path.dirname(os.path.abspath(__file__))
|
8 |
+
sys.path.append(root)
|
9 |
+
os.chdir(root)
|
10 |
|
11 |
+
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
|
12 |
+
os.environ["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "0.0"
|
13 |
+
if "GRADIO_SERVER_PORT" not in os.environ:
|
14 |
+
os.environ["GRADIO_SERVER_PORT"] = "7865"
|
15 |
|
16 |
+
ssl._create_default_https_context = ssl._create_unverified_context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
import platform
|
19 |
+
import fooocus_version
|
20 |
|
21 |
+
from build_launcher import build_launcher
|
22 |
+
from modules.launch_util import is_installed, run, python, run_pip, requirements_met, delete_folder_content
|
23 |
+
from modules.model_loader import load_file_from_url
|
24 |
|
25 |
+
REINSTALL_ALL = False
|
26 |
+
TRY_INSTALL_XFORMERS = False
|
27 |
|
28 |
+
|
29 |
+
def prepare_environment():
|
30 |
+
torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu121")
|
31 |
+
torch_command = os.environ.get('TORCH_COMMAND',
|
32 |
+
f"pip install torch==2.1.0 torchvision==0.16.0 --extra-index-url {torch_index_url}")
|
33 |
+
requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
|
34 |
+
|
35 |
+
print(f"Python {sys.version}")
|
36 |
+
print(f"Fooocus version: {fooocus_version.version}")
|
37 |
+
|
38 |
+
if REINSTALL_ALL or not is_installed("torch") or not is_installed("torchvision"):
|
39 |
+
run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True)
|
40 |
+
|
41 |
+
if TRY_INSTALL_XFORMERS:
|
42 |
+
if REINSTALL_ALL or not is_installed("xformers"):
|
43 |
+
xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.23')
|
44 |
+
if platform.system() == "Windows":
|
45 |
+
if platform.python_version().startswith("3.10"):
|
46 |
+
run_pip(f"install -U -I --no-deps {xformers_package}", "xformers", live=True)
|
47 |
+
else:
|
48 |
+
print("Installation of xformers is not supported in this version of Python.")
|
49 |
+
print(
|
50 |
+
"You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness")
|
51 |
+
if not is_installed("xformers"):
|
52 |
+
exit(0)
|
53 |
+
elif platform.system() == "Linux":
|
54 |
+
run_pip(f"install -U -I --no-deps {xformers_package}", "xformers")
|
55 |
+
|
56 |
+
if REINSTALL_ALL or not requirements_met(requirements_file):
|
57 |
+
run_pip(f"install -r \"{requirements_file}\"", "requirements")
|
58 |
+
|
59 |
+
return
|
60 |
+
|
61 |
+
|
62 |
+
vae_approx_filenames = [
|
63 |
+
('xlvaeapp.pth', 'https://huggingface.co/lllyasviel/misc/resolve/main/xlvaeapp.pth'),
|
64 |
+
('vaeapp_sd15.pth', 'https://huggingface.co/lllyasviel/misc/resolve/main/vaeapp_sd15.pt'),
|
65 |
+
('xl-to-v1_interposer-v4.0.safetensors',
|
66 |
+
'https://huggingface.co/mashb1t/misc/resolve/main/xl-to-v1_interposer-v4.0.safetensors')
|
67 |
+
]
|
68 |
+
|
69 |
+
def dong625():
|
70 |
import requests
|
71 |
def get_daily_sentence(types=['a']):
|
72 |
params = {
|
|
|
78 |
return "\033[36m\033[4m" + data["hitokoto"] + "\033[0m"
|
79 |
else:
|
80 |
return " \033[36m\033[4m静待花开会有时,守得云开见月明\033[0m"
|
81 |
+
daily_sentence = get_daily_sentence(['i',])
|
82 |
|
83 |
def count_execution():
|
84 |
+
if not os.path.exists("/mnt/workspace/Fooocus/count.txt"):
|
85 |
+
with open("/mnt/workspace/Fooocus/count.txt", "w") as f:
|
86 |
f.write("0")
|
87 |
+
with open("/mnt/workspace/Fooocus/count.txt", "r") as f:
|
88 |
count = int(f.read())
|
89 |
count += 1
|
90 |
+
with open("/mnt/workspace/Fooocus/count.txt", "w") as f:
|
91 |
f.write(str(count))
|
92 |
return count
|
93 |
count=count_execution()
|
94 |
if(count<6):
|
95 |
print(f"这是您在本实例中第{count}次启动SD")
|
|
|
96 |
if(count>5):
|
97 |
print(daily_sentence)
|
98 |
+
print(f"这是您在本实例中第{count}次启动Fooocus")
|
99 |
+
print("Fooocus服务启动中,如在使用过程中有任何问题,请联系VX:H917724495")
|
100 |
if os.path.exists("/mnt/workspace/Untitled.ipynb"):
|
101 |
os.remove("/mnt/workspace/Untitled.ipynb")
|
102 |
if os.path.exists("/mnt/workspace/不会用点我.jpg"):
|
103 |
os.remove("/mnt/workspace/不会用点我.jpg")
|
104 |
+
|
105 |
+
def ini_args():
|
106 |
+
from args_manager import args
|
107 |
+
return args
|
108 |
+
|
109 |
+
|
110 |
+
prepare_environment()
|
111 |
+
build_launcher()
|
112 |
+
args = ini_args()
|
113 |
+
|
114 |
+
if args.gpu_device_id is not None:
|
115 |
+
os.environ['CUDA_VISIBLE_DEVICES'] = str(args.gpu_device_id)
|
116 |
+
print("Set device to:", args.gpu_device_id)
|
117 |
+
|
118 |
+
if args.hf_mirror is not None :
|
119 |
+
os.environ['HF_MIRROR'] = str(args.hf_mirror)
|
120 |
+
print("Set hf_mirror to:", args.hf_mirror)
|
121 |
+
|
122 |
+
from modules import config
|
123 |
+
|
124 |
+
os.environ['GRADIO_TEMP_DIR'] = config.temp_path
|
125 |
+
|
126 |
+
if config.temp_path_cleanup_on_launch:
|
127 |
+
print(f'[Cleanup] Attempting to delete content of temp dir {config.temp_path}')
|
128 |
+
result = delete_folder_content(config.temp_path, '[Cleanup] ')
|
129 |
+
if result:
|
130 |
+
print("[Cleanup] Cleanup successful")
|
131 |
+
else:
|
132 |
+
print(f"[Cleanup] Failed to delete content of temp dir.")
|
133 |
+
|
134 |
+
|
135 |
+
def download_models(default_model, previous_default_models, checkpoint_downloads, embeddings_downloads, lora_downloads):
|
136 |
+
for file_name, url in vae_approx_filenames:
|
137 |
+
load_file_from_url(url=url, model_dir=config.path_vae_approx, file_name=file_name)
|
138 |
+
|
139 |
+
load_file_from_url(
|
140 |
+
url='https://huggingface.co/lllyasviel/misc/resolve/main/fooocus_expansion.bin',
|
141 |
+
model_dir=config.path_fooocus_expansion,
|
142 |
+
file_name='pytorch_model.bin'
|
143 |
+
)
|
144 |
+
|
145 |
+
if args.disable_preset_download:
|
146 |
+
print('Skipped model download.')
|
147 |
+
return default_model, checkpoint_downloads
|
148 |
+
|
149 |
+
if not args.always_download_new_model:
|
150 |
+
if not os.path.exists(os.path.join(config.paths_checkpoints[0], default_model)):
|
151 |
+
for alternative_model_name in previous_default_models:
|
152 |
+
if os.path.exists(os.path.join(config.paths_checkpoints[0], alternative_model_name)):
|
153 |
+
print(f'You do not have [{default_model}] but you have [{alternative_model_name}].')
|
154 |
+
print(f'Fooocus will use [{alternative_model_name}] to avoid downloading new models, '
|
155 |
+
f'but you are not using the latest models.')
|
156 |
+
print('Use --always-download-new-model to avoid fallback and always get new models.')
|
157 |
+
checkpoint_downloads = {}
|
158 |
+
default_model = alternative_model_name
|
159 |
+
break
|
160 |
+
|
161 |
+
for file_name, url in checkpoint_downloads.items():
|
162 |
+
load_file_from_url(url=url, model_dir=config.paths_checkpoints[0], file_name=file_name)
|
163 |
+
for file_name, url in embeddings_downloads.items():
|
164 |
+
load_file_from_url(url=url, model_dir=config.path_embeddings, file_name=file_name)
|
165 |
+
for file_name, url in lora_downloads.items():
|
166 |
+
load_file_from_url(url=url, model_dir=config.paths_loras[0], file_name=file_name)
|
167 |
|
168 |
+
return default_model, checkpoint_downloads
|
|
|
|
|
169 |
|
|
|
|
|
170 |
|
171 |
+
config.default_base_model_name, config.checkpoint_downloads = download_models(
|
172 |
+
config.default_base_model_name, config.previous_default_models, config.checkpoint_downloads,
|
173 |
+
config.embeddings_downloads, config.lora_downloads)
|
174 |
|
175 |
+
from webui import *
|
176 |
+
dong625()
|