BBrother commited on
Commit
364a029
1 Parent(s): 6b3d181

Update v2_3.py

Browse files
Files changed (1) hide show
  1. v2_3.py +46 -60
v2_3.py CHANGED
@@ -189,38 +189,29 @@ for repo_url, destination in extensions_to_clone:
189
  run_git_clone(repo_url, destination)
190
 
191
  print ("修改启动文件...")
192
- # 第一个命令:在导入行后插入 import os
193
- launch_file_path = "/bushu/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 = "/bushu/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 = "/bushu/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
 
@@ -305,35 +296,30 @@ if T2I_:
305
 
306
 
307
  print ("修改启动文件...")
308
- # 第一个命令:在导入行后插入 import os
309
- launch_file_path = "/bushu/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 = "/bushu/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 = "/bushu/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
 
 
189
  run_git_clone(repo_url, destination)
190
 
191
  print ("修改启动文件...")
192
+ # 打开launch.py文件
193
+ with open("/content/ui/launch.py", "r+") as f:
194
+ # 读取文件内容
195
+ content = f.read()
196
+ # 在from modules import launch_utils后面插入import os
197
+ content = content.replace("from modules import launch_utils", "from modules import launch_utils\nimport os")
198
+ # 在prepare_environment()后面插入os.system命令
199
+ content = content.replace("prepare_environment()", "prepare_environment()\n os.system(f\"\"\"sed -i -e ''\"s/stable/dict()))/dict())).cuda()/g\"'' /content/ui/repositories/diffusion-stability-stable/ldm/util.py\"\"\")")
200
+ # 重写文件内容
201
+ f.seek(0)
202
+ f.write(content)
203
+ f.truncate()
204
+
205
+ # 打开shared.py文件
206
+ with open("/content/ui/modules/shared.py", "r+") as f:
207
+ # 读取文件内容
208
+ content = f.read()
209
+ # 替换["sd_model_checkpoint"]为["sd_model_checkpoint","sd_vae","CLIP_stop_at_last_layers"]
210
+ content = content.replace('["sd_model_checkpoint"]', '["sd_model_checkpoint","sd_vae","CLIP_stop_at_last_layers"]')
211
+ # 重写文件内容
212
+ f.seek(0)
213
+ f.write(content)
214
+ f.truncate()
 
 
 
 
 
 
 
 
 
215
 
216
 
217
 
 
296
 
297
 
298
  print ("修改启动文件...")
299
+ # 打开launch.py文件
300
+ with open("/content/ui/launch.py", "r+") as f:
301
+ # 读取文件内容
302
+ content = f.read()
303
+ # 在from modules import launch_utils后面插入import os
304
+ content = content.replace("from modules import launch_utils", "from modules import launch_utils\nimport os")
305
+ # 在prepare_environment()后面插入os.system命令
306
+ content = content.replace("prepare_environment()", "prepare_environment()\n os.system(f\"\"\"sed -i -e ''\"s/dict()))/dict())).cuda()/g\"'' /content/ui/repositories/stable-diffusion-stability-ai/ldm/util.py\"\"\")")
307
+ # 重写文件内容
308
+ f.seek(0)
309
+ f.write(content)
310
+ f.truncate()
311
+
312
+ # 打开shared.py文件
313
+ with open("/content/ui/modules/shared.py", "r+") as f:
314
+ # 读取文件内容
315
+ content = f.read()
316
+ # 替换["sd_model_checkpoint"]为["sd_model_checkpoint","sd_vae","CLIP_stop_at_last_layers"]
317
+ content = content.replace('["sd_model_checkpoint"]', '["sd_model_checkpoint","sd_vae","CLIP_stop_at_last_layers"]')
318
+ # 重写文件内容
319
+ f.seek(0)
320
+ f.write(content)
321
+ f.truncate()
 
 
 
322
 
 
 
323
 
324
 
325