Update v2_3.py
Browse files
v2_3.py
CHANGED
|
@@ -163,36 +163,27 @@ for repo_url, destination in extensions_to_clone:
|
|
| 163 |
run_git_clone(repo_url, destination)
|
| 164 |
|
| 165 |
|
| 166 |
-
#
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
print(line, end='')
|
| 177 |
-
print("import os")
|
| 178 |
-
# 在prepare_environment()函数后插入os.system命令
|
| 179 |
-
elif "prepare_environment()" in line:
|
| 180 |
-
print(line, end='')
|
| 181 |
-
print(' os.system(f"sed -i -e \'s/stable/dict()))/dict())).cuda()/g\' /bushu/ui/repositories/diffusion-stability-stable/ldm/util.py")')
|
| 182 |
-
# 替换指定文本
|
| 183 |
else:
|
| 184 |
-
|
| 185 |
|
| 186 |
-
#
|
| 187 |
-
with
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
if os.path.exists(path):
|
| 195 |
-
os.remove(path)
|
| 196 |
|
| 197 |
|
| 198 |
|
|
@@ -220,70 +211,73 @@ def create_directory(directory):
|
|
| 220 |
mkdir_command = ["mkdir", "-p", directory]
|
| 221 |
subprocess.run(mkdir_command, check=True)
|
| 222 |
|
| 223 |
-
|
|
|
|
|
|
|
| 224 |
CONTROLNET_ = True
|
| 225 |
T2I_ = True
|
| 226 |
|
| 227 |
-
#
|
| 228 |
if CONTROLNET_:
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
# T2I
|
| 242 |
if T2I_:
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
shared_py_path = "/bushu/ui/modules/shared.py"
|
| 260 |
-
|
| 261 |
-
# 更新相关的sed命令
|
| 262 |
-
sed_command_1 = 'import os'
|
| 263 |
-
sed_command_2 = ' os.system(f"sed -i -e \'s/dict()))/dict())).cuda()/g\' {util_py_path}")'
|
| 264 |
-
sed_command_3 = '["sd_model_checkpoint", "sd_vae", "CLIP_stop_at_last_layers"]'
|
| 265 |
-
|
| 266 |
-
# 使用fileinput模块编辑launch.py文件
|
| 267 |
-
with fileinput.FileInput(launch_py_path, inplace=True, backup=".bak") as file:
|
| 268 |
for line in file:
|
| 269 |
-
|
| 270 |
-
print(line, end='')
|
| 271 |
-
print(sed_command_1)
|
| 272 |
-
elif "prepare_environment()" in line:
|
| 273 |
-
print(line, end='')
|
| 274 |
-
print(sed_command_2)
|
| 275 |
-
else:
|
| 276 |
-
print(line, end='')
|
| 277 |
|
| 278 |
-
|
| 279 |
-
with fileinput.FileInput(shared_py_path, inplace=True, backup=".bak") as file:
|
| 280 |
for line in file:
|
| 281 |
-
print(line.replace('
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
-
# 删除备份文件
|
| 284 |
-
for path in [launch_py_path + '.bak', shared_py_path + '.bak']:
|
| 285 |
-
if os.path.exists(path):
|
| 286 |
-
os.remove(path)
|
| 287 |
|
| 288 |
|
| 289 |
|
|
|
|
| 163 |
run_git_clone(repo_url, destination)
|
| 164 |
|
| 165 |
|
| 166 |
+
# 修改 launch.py 文件
|
| 167 |
+
with open('/content/ui/launch.py', 'r') as file:
|
| 168 |
+
lines = file.readlines()
|
| 169 |
+
|
| 170 |
+
with open('/content/ui/launch.py', 'w') as file:
|
| 171 |
+
for line in lines:
|
| 172 |
+
if 'from modules import launch_utils' in line:
|
| 173 |
+
file.write('import os\n')
|
| 174 |
+
elif 'prepare_environment()' in line:
|
| 175 |
+
file.write(' os.system(f\'sed -i -e \'\'\'s/stable/dict()))/dict())).cuda()/g\'\'\' /content/ui/repositories/diffusion-stability-stable/ldm/util.py\')\n')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
else:
|
| 177 |
+
file.write(line)
|
| 178 |
|
| 179 |
+
# 修改 shared.py 文件
|
| 180 |
+
with open('/content/ui/modules/shared.py', 'r') as file:
|
| 181 |
+
content = file.read()
|
| 182 |
+
|
| 183 |
+
content = content.replace('["sd_model_checkpoint"]', '["sd_model_checkpoint","sd_vae","CLIP_stop_at_last_layers"]')
|
| 184 |
|
| 185 |
+
with open('/content/ui/modules/shared.py', 'w') as file:
|
| 186 |
+
file.write(content)
|
|
|
|
|
|
|
| 187 |
|
| 188 |
|
| 189 |
|
|
|
|
| 211 |
mkdir_command = ["mkdir", "-p", directory]
|
| 212 |
subprocess.run(mkdir_command, check=True)
|
| 213 |
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
# 其它基本配置
|
| 217 |
CONTROLNET_ = True
|
| 218 |
T2I_ = True
|
| 219 |
|
| 220 |
+
# CN
|
| 221 |
if CONTROLNET_:
|
| 222 |
+
os.makedirs('/content/ui/extensions/control/models', exist_ok=True)
|
| 223 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors', '/content/ui/extensions/control/models/control_v11e_sd15_ip2p_fp16.safetensors')
|
| 224 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors', '/content/ui/extensions/control/models/control_v11e_sd15_shuffle_fp16.safetensors')
|
| 225 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors', '/content/ui/extensions/control/models/control_v11p_sd15_canny_fp16.safetensors')
|
| 226 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors', '/content/ui/extensions/control/models/control_v11f1p_sd15_depth_fp16.safetensors')
|
| 227 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors', '/content/ui/extensions/control/models/control_v11p_sd15_inpaint_fp16.safetensors')
|
| 228 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors', '/content/ui/extensions/control/models/control_v11p_sd15_lineart_fp16.safetensors')
|
| 229 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors', '/content/ui/extensions/control/models/control_v11p_sd15_mlsd_fp16.safetensors')
|
| 230 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors', '/content/ui/extensions/control/models/control_v11p_sd15_normalbae_fp16.safetensors')
|
| 231 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors', '/content/ui/extensions/control/models/control_v11p_sd15_openpose_fp16.safetensors')
|
| 232 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors', '/content/ui/extensions/control/models/control_v11p_sd15_scribble_fp16.safetensors')
|
| 233 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors', '/content/ui/extensions/control/models/control_v11p_sd15_seg_fp16.safetensors')
|
| 234 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors', '/content/ui/extensions/control/models/control_v11p_sd15_softedge_fp16.safetensors')
|
| 235 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors', '/content/ui/extensions/control/models/control_v11p_sd15s2_lineart_anime_fp16.safetensors')
|
| 236 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_tile_fp16.yaml', '/content/ui/extensions/control/models/control_v11e_sd15_tile_fp16.yaml')
|
| 237 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml', '/content/ui/extensions/control/models/control_v11e_sd15_ip2p_fp16.yaml')
|
| 238 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml', '/content/ui/extensions/control/models/control_v11e_sd15_shuffle_fp16.yaml')
|
| 239 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml', '/content/ui/extensions/control/models/control_v11p_sd15_canny_fp16.yaml')
|
| 240 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml', '/content/ui/extensions/control/models/control_v11f1p_sd15_depth_fp16.yaml')
|
| 241 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml', '/content/ui/extensions/control/models/control_v11p_sd15_inpaint_fp16.yaml')
|
| 242 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml', '/content/ui/extensions/control/models/control_v11p_sd15_lineart_fp16.yaml')
|
| 243 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml', '/content/ui/extensions/control/models/control_v11p_sd15_mlsd_fp16.yaml')
|
| 244 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml', '/content/ui/extensions/control/models/control_v11p_sd15_normalbae_fp16.yaml')
|
| 245 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml', '/content/ui/extensions/control/models/control_v11p_sd15_openpose_fp16.yaml')
|
| 246 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml', '/content/ui/extensions/control/models/control_v11p_sd15_scribble_fp16.yaml')
|
| 247 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml', '/content/ui/extensions/control/models/control_v11p_sd15_seg_fp16.yaml')
|
| 248 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml', '/content/ui/extensions/control/models/control_v11p_sd15_softedge_fp16.yaml')
|
| 249 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15s2_lineart_anime_fp16.yaml', '/content/ui/extensions/control/models/control_v11p_sd15s2_lineart_anime_fp16.yaml')
|
| 250 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml', '/content/ui/extensions/control/models')
|
| 251 |
|
| 252 |
# T2I
|
| 253 |
if T2I_:
|
| 254 |
+
os.makedirs('/content/ui/extensions/control/models', exist_ok=True)
|
| 255 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_style_sd14v1.pth', '/content/ui/extensions/control/models/t2iadapter_style_sd14v1.pth')
|
| 256 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_sketch_sd14v1.pth', '/content/ui/extensions/control/models/t2iadapter_sketch_sd14v1.pth')
|
| 257 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_seg_sd14v1.pth', '/content/ui/extensions/control/models/t2iadapter_seg_sd14v1.pth')
|
| 258 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_openpose_sd14v1.pth', '/content/ui/extensions/control/models/t2iadapter_openpose_sd14v1.pth')
|
| 259 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_keypose_sd14v1.pth', '/content/ui/extensions/control/models/t2iadapter_keypose_sd14v1.pth')
|
| 260 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_depth_sd14v1.pth', '/content/ui/extensions/control/models/t2iadapter_depth_sd14v1.pth')
|
| 261 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_color_sd14v1.pth', '/content/ui/extensions/control/models/t2iadapter_color_sd14v1.pth')
|
| 262 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_canny_sd14v1.pth', '/content/ui/extensions/control/models/t2iadapter_canny_sd14v1.pth')
|
| 263 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_canny_sd15v2.pth', '/content/ui/extensions/control/models/t2iadapter_canny_sd15v2.pth')
|
| 264 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_depth_sd15v2.pth', '/content/ui/extensions/control/models/t2iadapter_depth_sd15v2.pth')
|
| 265 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_sketch_sd15v2.pth', '/content/ui/extensions/control/models/t2iadapter_sketch_sd15v2.pth')
|
| 266 |
+
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_zoedepth_sd15v1.pth', '/content/ui/extensions/control/models/t2iadapter_zoedepth_sd15v1.pth')
|
| 267 |
+
|
| 268 |
+
# 修改文件
|
| 269 |
+
with fileinput.FileInput('/content/ui/launch.py', inplace=True, backup='.bak') as file:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
for line in file:
|
| 271 |
+
print(line.replace('from modules import launch_utils', 'import os'), end='')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
+
with fileinput.FileInput('/content/ui/launch.py', inplace=True, backup='.bak') as file:
|
|
|
|
| 274 |
for line in file:
|
| 275 |
+
print(line.replace('prepare_environment()', 'os.system(f"""sed -i -e \'\'\'s/dict()))/dict())).cuda()/g\"\'\' /content/ui/repositories/stable-diffusion-stability-ai/ldm/util.py\"")'), end='')
|
| 276 |
+
|
| 277 |
+
with fileinput.FileInput('/content/ui/modules/shared.py', inplace=True, backup='.bak') as file:
|
| 278 |
+
for line in file:
|
| 279 |
+
print(line.replace('["sd_model_checkpoint"]', '["sd_model_checkpoint","sd_vae","CLIP_stop_at_last_layers"]'), end='')
|
| 280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
|
| 282 |
|
| 283 |
|