Update v2_3.py
Browse files
v2_3.py
CHANGED
|
@@ -68,6 +68,7 @@ import wget
|
|
| 68 |
import fileinput
|
| 69 |
import requests
|
| 70 |
import datetime
|
|
|
|
| 71 |
|
| 72 |
# 初始化变量
|
| 73 |
a = ""
|
|
@@ -188,16 +189,39 @@ for repo_url, destination in extensions_to_clone:
|
|
| 188 |
run_git_clone(repo_url, destination)
|
| 189 |
|
| 190 |
print ("修改启动文件...")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
-
|
| 193 |
-
subprocess.run(["sed", "-i", r"/from modules import launch_utils/a\import os", "/bushu/ui/launch.py"])
|
| 194 |
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
-
# 第三个命令
|
| 200 |
-
subprocess.run(["sed", "-i", r"s/\[\"sd_model_checkpoint\"\]/\[\"sd_model_checkpoint\",\"sd_vae\",\"CLIP_stop_at_last_layers\"\]/g", "/bushu/ui/modules/shared.py"])
|
| 201 |
|
| 202 |
|
| 203 |
# 汉化
|
|
@@ -281,15 +305,36 @@ if T2I_:
|
|
| 281 |
|
| 282 |
|
| 283 |
print ("修改启动文件...")
|
| 284 |
-
#
|
| 285 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
subprocess.run(["sed", "-i", sed_command, "/bushu/ui/launch.py"])
|
| 290 |
|
| 291 |
-
# 第三个命令
|
| 292 |
-
subprocess.run(["sed", "-i", r's/\["sd_model_checkpoint"\]/\["sd_model_checkpoint","sd_vae","CLIP_stop_at_last_layers"\]/g', '/bushu/ui/modules/shared.py'])
|
| 293 |
|
| 294 |
|
| 295 |
"""# 模型下载"""
|
|
|
|
| 68 |
import fileinput
|
| 69 |
import requests
|
| 70 |
import datetime
|
| 71 |
+
import re
|
| 72 |
|
| 73 |
# 初始化变量
|
| 74 |
a = ""
|
|
|
|
| 189 |
run_git_clone(repo_url, destination)
|
| 190 |
|
| 191 |
print ("修改启动文件...")
|
| 192 |
+
# 第一个命令:在导入行后插入 import os
|
| 193 |
+
launch_file_path = "/content/ui/launch.py"
|
| 194 |
+
with open(launch_file_path, 'r') as file:
|
| 195 |
+
content = file.read()
|
| 196 |
|
| 197 |
+
content = re.sub(r'from modules import launch_utils', 'import os\n\nfrom modules import launch_utils', content)
|
|
|
|
| 198 |
|
| 199 |
+
with open(launch_file_path, 'w') as file:
|
| 200 |
+
file.write(content)
|
| 201 |
+
|
| 202 |
+
# 第二个命令:在 prepare_environment() 行后执行 sed 命令
|
| 203 |
+
util_file_path = "/content/ui/repositories/diffusion-stability-stable/ldm/util.py"
|
| 204 |
+
with open(util_file_path, 'r') as file:
|
| 205 |
+
content = file.read()
|
| 206 |
+
|
| 207 |
+
inserted_code = 'os.system("sed -i -e \'s/stable/dict()))/dict())).cuda()/g\' ' + util_file_path + '")'
|
| 208 |
+
|
| 209 |
+
# 使用正则表达式查找 prepare_environment() 行,并在其后插入代码
|
| 210 |
+
content = re.sub(r'( prepare_environment\(\)\n)', r'\1' + inserted_code + '\n', content)
|
| 211 |
+
|
| 212 |
+
with open(util_file_path, 'w') as file:
|
| 213 |
+
file.write(content)
|
| 214 |
+
|
| 215 |
+
# 第三个命令:将列表中添加元素
|
| 216 |
+
shared_file_path = "/content/ui/modules/shared.py"
|
| 217 |
+
with open(shared_file_path, 'r') as file:
|
| 218 |
+
content = file.read()
|
| 219 |
+
|
| 220 |
+
content = re.sub(r'\["sd_model_checkpoint"\]', '["sd_model_checkpoint","sd_vae","CLIP_stop_at_last_layers"]', content)
|
| 221 |
+
|
| 222 |
+
with open(shared_file_path, 'w') as file:
|
| 223 |
+
file.write(content)
|
| 224 |
|
|
|
|
|
|
|
| 225 |
|
| 226 |
|
| 227 |
# 汉化
|
|
|
|
| 305 |
|
| 306 |
|
| 307 |
print ("修改启动文件...")
|
| 308 |
+
# 第一个命令:在导入行后插入 import os
|
| 309 |
+
launch_file_path = "/content/ui/launch.py"
|
| 310 |
+
with open(launch_file_path, 'r') as file:
|
| 311 |
+
content = file.read()
|
| 312 |
+
|
| 313 |
+
content = re.sub(r'from modules import launch_utils', 'import os\n\nfrom modules import launch_utils', content)
|
| 314 |
+
|
| 315 |
+
with open(launch_file_path, 'w') as file:
|
| 316 |
+
file.write(content)
|
| 317 |
+
|
| 318 |
+
# 第二个命令:在 prepare_environment() 行后执行 sed 命令
|
| 319 |
+
util_file_path = "/content/ui/repositories/stable-diffusion-stability-ai/ldm/util.py"
|
| 320 |
+
with open(util_file_path, 'r') as file:
|
| 321 |
+
content = file.read()
|
| 322 |
+
|
| 323 |
+
content = re.sub(r'prepare_environment\(\)', f'prepare_environment()\n os.system("sed -i -e \'s/dict()))/dict())).cuda()/g\' {util_file_path}")', content)
|
| 324 |
+
|
| 325 |
+
with open(util_file_path, 'w') as file:
|
| 326 |
+
file.write(content)
|
| 327 |
+
|
| 328 |
+
# 第三个命令:将列表中添加元素
|
| 329 |
+
shared_file_path = "/content/ui/modules/shared.py"
|
| 330 |
+
with open(shared_file_path, 'r') as file:
|
| 331 |
+
content = file.read()
|
| 332 |
+
|
| 333 |
+
content = re.sub(r'\["sd_model_checkpoint"\]', '["sd_model_checkpoint","sd_vae","CLIP_stop_at_last_layers"]', content)
|
| 334 |
|
| 335 |
+
with open(shared_file_path, 'w') as file:
|
| 336 |
+
file.write(content)
|
|
|
|
| 337 |
|
|
|
|
|
|
|
| 338 |
|
| 339 |
|
| 340 |
"""# 模型下载"""
|