666
commited on
Commit
•
31d5904
1
Parent(s):
33c8907
Update ziyong.py
Browse files
ziyong.py
CHANGED
@@ -15,16 +15,15 @@ parser = argparse.ArgumentParser()
|
|
15 |
|
16 |
parser.add_argument('--UI', type=str)
|
17 |
parser.add_argument('--Version', type=str)
|
18 |
-
parser.add_argument('--ControlNet', type=
|
19 |
-
parser.add_argument('--Roop', type=str_to_bool)
|
20 |
parser.add_argument('--Drive_Map', type=str_to_bool)
|
21 |
parser.add_argument('--Key_words', type=str_to_bool)
|
22 |
|
23 |
# 解析命令行参数
|
24 |
args = parser.parse_args()
|
25 |
|
|
|
26 |
UI = args.UI
|
27 |
-
Roop = args.Roop
|
28 |
Version = args.Version
|
29 |
ControlNet = args.ControlNet
|
30 |
Drive_Map = args.Drive_Map
|
@@ -34,8 +33,10 @@ Key_words = args.Key_words
|
|
34 |
|
35 |
import sys
|
36 |
import os
|
|
|
37 |
import base64
|
38 |
import importlib.util
|
|
|
39 |
from IPython.display import clear_output
|
40 |
from google.colab import drive
|
41 |
import tensorflow as tf
|
@@ -47,12 +48,10 @@ if tf.test.gpu_device_name():
|
|
47 |
else:
|
48 |
raise Exception("\n请在《代码执行程序》-《更改运行时类型》-设置为GPU~")
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
sdw = binascii.unhexlify("737461626c652d646966667573696f6e2d7765627569").decode('ascii')
|
53 |
-
w = binascii.unhexlify("7765627569").decode('ascii')
|
54 |
wb = f'/content/{sdw}'
|
55 |
-
gwb = f'/content/drive/MyDrive/
|
56 |
|
57 |
get_ipython().run_line_magic('cd', '/content')
|
58 |
get_ipython().run_line_magic('env', 'TF_CPP_MIN_LOG_LEVEL=1')
|
@@ -76,9 +75,22 @@ def cloudDriveSync(cloudPath, localPath='', sync=False):
|
|
76 |
# 初始化云盘
|
77 |
def initCloudDrive():
|
78 |
cloudDriveSync(f'{gwb}')
|
79 |
-
cloudDriveSync(f'{gwb}/
|
80 |
-
cloudDriveSync(f'{gwb}/
|
81 |
-
cloudDriveSync(f'{gwb}/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
# clong git
|
84 |
def gitDownload(url, localPath):
|
@@ -87,33 +99,28 @@ def gitDownload(url, localPath):
|
|
87 |
|
88 |
get_ipython().system(f'git clone {url} {localPath}')
|
89 |
|
90 |
-
|
91 |
# 安装附加功能
|
92 |
def installAdditional():
|
93 |
# 安装扩展
|
94 |
urls = [
|
95 |
-
f'https://github.com/camenduru/{sdw}-images-browser',
|
96 |
-
f'https://github.com/camenduru/{
|
97 |
-
f'https://github.com/
|
98 |
-
f'https://github.com/
|
99 |
-
f'https://github.com/
|
100 |
-
f'https://github.com/
|
101 |
-
f'https://github.com/
|
102 |
-
f'https://github.com/
|
103 |
-
f'https://github.com/
|
104 |
-
f'https://github.com/
|
105 |
-
f'https://github.com/
|
106 |
-
f'https://github.com/
|
107 |
-
f'https://github.com/
|
108 |
-
f'https://github.com/
|
109 |
-
f'https://github.com/
|
110 |
-
f'https://github.com/
|
111 |
-
|
112 |
-
|
113 |
-
# f'https://github.com/camenduru/a1111-sd-{w}-locon',
|
114 |
-
# f'https://github.com/camenduru/sd_{w}_stealth_pnginfo',
|
115 |
-
# f'https://github.com/Scholar01/sd-{w}-mov2mov',
|
116 |
-
# f'https://github.com/deforum-art/deforum-for-automatic1111-{w}',
|
117 |
]
|
118 |
for url in urls:
|
119 |
|
@@ -124,6 +131,8 @@ def installAdditional():
|
|
124 |
|
125 |
get_ipython().system(f'wget https://raw.githubusercontent.com/camenduru/{sdw}-scripts/main/run_n_times.py -O {wb}/scripts/run_n_times.py')
|
126 |
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -d {wb}/models/ESRGAN -o 4x-UltraSharp.pth')
|
|
|
|
|
127 |
|
128 |
# 优化embeddings
|
129 |
gitDownload(f'https://huggingface.co/embed/negative',f'{wb}/embeddings/negative')
|
@@ -139,44 +148,56 @@ def installAdditional():
|
|
139 |
get_ipython().system(f'rm -f {wb}/extensions/a1111-sd-{w}-tagcomplete/tags/danbooru.csv')
|
140 |
get_ipython().system(f'wget https://beehomefile.oss-cn-beijing.aliyuncs.com/20210114/danbooru.csv -O {wb}/extensions/a1111-sd-{w}-tagcomplete/tags/danbooru.csv')
|
141 |
gitDownload(f'https://github.com/toriato/{sdw}-wd14-tagger',f'{wb}/extensions/{sdw}-wd14-tagge')
|
142 |
-
get_ipython().system(f'rm -f {wb}/localizations')
|
143 |
-
gitDownload(f'https://github.com/dtlnor/{sdw}-localization-zh_CN',f'{wb}/extensions/{sdw}-localization-zh_CN')
|
144 |
-
|
|
|
145 |
gitDownload(f'https://github.com/Bing-su/adetailer',f'{wb}/extensions/adetailer')
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
gitDownload(f'https://github.com/s0md3v/sd-{w}-roop',f'{wb}/extensions/sd-{w}-roop')
|
150 |
-
print('Roop换脸启用')
|
151 |
-
else:
|
152 |
-
print('Roop换脸不启用')
|
153 |
|
154 |
# ControlNet模型
|
155 |
Cnt_models = [
|
156 |
-
'
|
157 |
-
'
|
158 |
-
'
|
159 |
-
'
|
160 |
-
'
|
161 |
-
'
|
162 |
-
'
|
163 |
-
'
|
164 |
-
'
|
165 |
-
'
|
166 |
-
'
|
167 |
-
'
|
168 |
-
'
|
169 |
-
'
|
170 |
]
|
171 |
get_ipython().system(f'rm -rf {wb}/extensions/sd-{w}-controlnet')
|
172 |
# 模型下载到Colab
|
173 |
-
if ControlNet:
|
174 |
gitDownload(f'https://github.com/Mikubill/sd-{w}-controlnet',f'{wb}/extensions/sd-{w}-controlnet')
|
175 |
for v in Cnt_models:
|
176 |
-
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/
|
177 |
-
|
178 |
-
|
179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
|
181 |
# 各种UI界面
|
182 |
if UI == "Kitchen_Ui":
|
@@ -185,15 +206,13 @@ def installAdditional():
|
|
185 |
elif UI == "Lobe_Ui":
|
186 |
gitDownload(f'https://github.com/canisminor1990/sd-web-ui-kitchen-theme', f'{wb}/extensions/sd-web-ui-kitchen-theme')
|
187 |
print("Lobe界面插件启用")
|
188 |
-
elif UI == "Ux_Ui":
|
189 |
-
gitDownload(f'https://github.com/anapnoe/{sdw}-ux', f'{wb}/extensions/{sdw}-ux')
|
190 |
-
print("UX界面插件启用")
|
191 |
elif UI == "No":
|
192 |
print("UI插件不启用")
|
193 |
-
|
194 |
# 关键词
|
195 |
if Key_words:
|
196 |
gitDownload(f'https://github.com/Physton/sd-{w}-prompt-all-in-one', f'{wb}/extensions/sd-{w}-prompt-all-in-one')
|
|
|
197 |
print("关键词插件启用")
|
198 |
else:
|
199 |
get_ipython().system(f'rm -rf {wb}/extensions/sd-{w}-prompt-all-in-one')
|
@@ -201,10 +220,9 @@ def installAdditional():
|
|
201 |
|
202 |
# 初始化本地环境
|
203 |
def initLocal():
|
204 |
-
|
205 |
#部署 env 环境变量
|
206 |
get_ipython().system(f'apt -y update -qq')
|
207 |
-
get_ipython().system(f'wget https://
|
208 |
get_ipython().run_line_magic('env', 'LD_PRELOAD=/content/libtcmalloc_minimal.so.4')
|
209 |
|
210 |
#设置 python 环境
|
@@ -214,49 +232,46 @@ def initLocal():
|
|
214 |
|
215 |
#主框架模块
|
216 |
if Version == "A1111":
|
217 |
-
get_ipython().system(f'git clone https://github.com/AUTOMATIC1111/{sdw} {wb}')
|
218 |
-
elif Version == "V2.
|
219 |
-
get_ipython().system(f'git clone -b v2.
|
220 |
-
elif Version == "V2.
|
221 |
get_ipython().system(f'git clone -b v2.4 https://github.com/camenduru/{sdw} {wb}')
|
222 |
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
# 初始化云盘
|
227 |
initCloudDrive()
|
228 |
|
229 |
# 安装附加功能
|
230 |
installAdditional()
|
231 |
|
232 |
-
|
|
|
|
|
|
|
|
|
233 |
|
234 |
-
|
235 |
-
if
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
if len(os.listdir(f"{gwb}/
|
245 |
#下载主模型
|
246 |
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/coco233/colab/resolve/main/ZR888.safetensors -d {wb}/models/Stable-diffusion -o zr888.safetensors')
|
247 |
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/wageguagua/sdmodels/resolve/main/long9.safetensors -d {wb}/models/Stable-diffusion -o long9.safetensors')
|
|
|
248 |
# 如果云盘Vae模型
|
249 |
-
if len(os.listdir(f"{gwb}/
|
250 |
# #VAE
|
251 |
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors -d {wb}/models/VAE -o vae-ft-mse-840000-ema-pruned.safetensors')
|
252 |
-
|
253 |
-
if len(os.listdir(f"{gwb}/lora")) == 0:
|
254 |
-
#下载lora
|
255 |
-
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://civitai.com/api/download/models/78701 -d {wb}/models/Lora -o jingye1.safetensors')
|
256 |
-
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://civitai.com/api/download/models/11914 -d {wb}/models/Lora -o jingye2.safetensors')
|
257 |
-
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://civitai.com/api/download/models/99602 -d {wb}/models/Lora -o BBB1.safetensors')
|
258 |
-
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://civitai.com/api/download/models/101662 -d {wb}/models/Lora -o BBB2.safetensors')
|
259 |
-
|
260 |
#放大
|
261 |
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -d {wb}/models/ESRGAN -o 4x-UltraSharp.pth')
|
262 |
|
@@ -266,12 +281,12 @@ def initLocal():
|
|
266 |
get_ipython().system(f'sed -i "s@os.path.splitext(model_file)@os.path.splitext(model_file); map_location=\'cuda\'@" {wb}/modules/sd_models.py')
|
267 |
get_ipython().system(f'sed -i "s@map_location=\'cpu\'@map_location=\'cuda\'@" {wb}/modules/extras.py')
|
268 |
get_ipython().system(f"sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' {wb}/webui.py")
|
269 |
-
|
270 |
# 运行
|
271 |
def run(script):
|
272 |
clear_output()
|
273 |
get_ipython().run_line_magic('cd', f'{wb}')
|
274 |
-
get_ipython().system(f'python {script} --listen --xformers --enable-insecure-extension-access --theme dark --gradio-queue --
|
275 |
|
276 |
# 运行脚本
|
277 |
if os.path.exists(f'{wb}'):
|
@@ -280,4 +295,4 @@ else:
|
|
280 |
# 初化本地环境
|
281 |
initLocal()
|
282 |
# 运行
|
283 |
-
run('launch.py')
|
|
|
15 |
|
16 |
parser.add_argument('--UI', type=str)
|
17 |
parser.add_argument('--Version', type=str)
|
18 |
+
parser.add_argument('--ControlNet', type=str)
|
|
|
19 |
parser.add_argument('--Drive_Map', type=str_to_bool)
|
20 |
parser.add_argument('--Key_words', type=str_to_bool)
|
21 |
|
22 |
# 解析命令行参数
|
23 |
args = parser.parse_args()
|
24 |
|
25 |
+
|
26 |
UI = args.UI
|
|
|
27 |
Version = args.Version
|
28 |
ControlNet = args.ControlNet
|
29 |
Drive_Map = args.Drive_Map
|
|
|
33 |
|
34 |
import sys
|
35 |
import os
|
36 |
+
import json
|
37 |
import base64
|
38 |
import importlib.util
|
39 |
+
from IPython import get_ipython
|
40 |
from IPython.display import clear_output
|
41 |
from google.colab import drive
|
42 |
import tensorflow as tf
|
|
|
48 |
else:
|
49 |
raise Exception("\n请在《代码执行程序》-《更改运行时类型》-设置为GPU~")
|
50 |
|
51 |
+
w = base64.b64decode(("d2VidWk=").encode('ascii')).decode('ascii')
|
52 |
+
sdw = base64.b64decode(("c3RhYmxlLWRpZmZ1c2lvbi13ZWJ1aQ==").encode('ascii')).decode('ascii')
|
|
|
|
|
53 |
wb = f'/content/{sdw}'
|
54 |
+
gwb = f'/content/drive/MyDrive/SD_DATA'
|
55 |
|
56 |
get_ipython().run_line_magic('cd', '/content')
|
57 |
get_ipython().run_line_magic('env', 'TF_CPP_MIN_LOG_LEVEL=1')
|
|
|
75 |
# 初始化云盘
|
76 |
def initCloudDrive():
|
77 |
cloudDriveSync(f'{gwb}')
|
78 |
+
cloudDriveSync(f'{gwb}/Config')
|
79 |
+
cloudDriveSync(f'{gwb}/Models', f'{wb}/models/Stable-diffusion', Drive_Map)
|
80 |
+
cloudDriveSync(f'{gwb}/Lora', f'{wb}/models/Lora', Drive_Map)
|
81 |
+
cloudDriveSync(f'{gwb}/LyCORIS', f'{wb}/models/LyCORIS', Drive_Map)
|
82 |
+
cloudDriveSync(f'{gwb}/hypernetworks', f'{wb}/models/hypernetworks', Drive_Map)
|
83 |
+
cloudDriveSync(f'{gwb}/Vae', f'{wb}/models/VAE', Drive_Map)
|
84 |
+
cloudDriveSync(f'{gwb}/Outputs', f'{wb}/outputs', Drive_Map)
|
85 |
+
|
86 |
+
|
87 |
+
# 云盘没有配置文件
|
88 |
+
if not os.path.exists(f'{gwb}/Config/config.json'):
|
89 |
+
get_ipython().system(f'wget -O {gwb}/Config/config.json "https://huggingface.co/wageguagua/main/raw/main/config.json"')
|
90 |
+
# 如果云盘没有styles.csv文件则手动创建
|
91 |
+
if not os.path.exists(f'{gwb}/styles.csv'):
|
92 |
+
#创建styles.csv文件
|
93 |
+
get_ipython().system(f'wget -O {gwb}/styles.csv "https://huggingface.co/wageguagua/main/raw/main/styles.csv"')
|
94 |
|
95 |
# clong git
|
96 |
def gitDownload(url, localPath):
|
|
|
99 |
|
100 |
get_ipython().system(f'git clone {url} {localPath}')
|
101 |
|
|
|
102 |
# 安装附加功能
|
103 |
def installAdditional():
|
104 |
# 安装扩展
|
105 |
urls = [
|
106 |
+
f'https://github.com/camenduru/{sdw}-images-browser', # 图像浏览器
|
107 |
+
f'https://github.com/camenduru/sd-{w}-tunnels', # Tunnel 网络支持
|
108 |
+
f'https://github.com/etherealxx/batchlinks-{w}', # 批量下载模型lora
|
109 |
+
f'https://github.com/camenduru/sd-civitai-browser', # Civitai 分类和搜索
|
110 |
+
f'https://github.com/AUTOMATIC1111/{sdw}-rembg', # 背景移除功能
|
111 |
+
f'https://github.com/thomasasfk/sd-{w}-aspect-ratio-helper', # 宽高比调整功能
|
112 |
+
f'https://github.com/hanamizuki-ai/{sdw}-localization-zh_Hans', # 中文
|
113 |
+
f'https://github.com/kohya-ss/sd-{w}-additional-networks', # 模型网络
|
114 |
+
f'https://github.com/fkunn1326/openpose-editor', # 人体姿态编辑功能
|
115 |
+
f'https://github.com/hnmr293/posex', # 人体姿态估计
|
116 |
+
f'https://github.com/s9roll7/ebsynth_utility', # 视频的图像生成
|
117 |
+
f'https://github.com/ashen-sensored/{sdw}-two-shot', # 潜变量成对(双人特写)
|
118 |
+
f'https://github.com/nonnonstop/sd-{w}-3d-open-pose-editor', # 3D 人体姿态编辑功能
|
119 |
+
f'https://github.com/camenduru/{sdw}-huggingface', # 整合 Huggingface 的模型功能
|
120 |
+
f'https://github.com/camenduru/{sdw}-catppuccin', # Catppuccin 主题
|
121 |
+
f'https://github.com/IDEA-Research/DWPose', # cnt手部模型
|
122 |
+
f'https://github.com/KohakuBlueleaf/a1111-sd-{w}-lycoris', # 人物生成模型
|
123 |
+
|
|
|
|
|
|
|
|
|
124 |
]
|
125 |
for url in urls:
|
126 |
|
|
|
131 |
|
132 |
get_ipython().system(f'wget https://raw.githubusercontent.com/camenduru/{sdw}-scripts/main/run_n_times.py -O {wb}/scripts/run_n_times.py')
|
133 |
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -d {wb}/models/ESRGAN -o 4x-UltraSharp.pth')
|
134 |
+
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -d {wb}/models/ESRGAN -o RealESRGAN_x4plus_anime_6B.pth')
|
135 |
+
|
136 |
|
137 |
# 优化embeddings
|
138 |
gitDownload(f'https://huggingface.co/embed/negative',f'{wb}/embeddings/negative')
|
|
|
148 |
get_ipython().system(f'rm -f {wb}/extensions/a1111-sd-{w}-tagcomplete/tags/danbooru.csv')
|
149 |
get_ipython().system(f'wget https://beehomefile.oss-cn-beijing.aliyuncs.com/20210114/danbooru.csv -O {wb}/extensions/a1111-sd-{w}-tagcomplete/tags/danbooru.csv')
|
150 |
gitDownload(f'https://github.com/toriato/{sdw}-wd14-tagger',f'{wb}/extensions/{sdw}-wd14-tagge')
|
151 |
+
# get_ipython().system(f'rm -f {wb}/localizations')
|
152 |
+
# gitDownload(f'https://github.com/dtlnor/{sdw}-localization-zh_CN',f'{wb}/extensions/{sdw}-localization-zh_CN')
|
153 |
+
|
154 |
+
#附加插件=脸部修复/颜色细化/ps组件/漫画助手/分块vae
|
155 |
gitDownload(f'https://github.com/Bing-su/adetailer',f'{wb}/extensions/adetailer')
|
156 |
+
gitDownload(f'https://github.com/antfu/sd-{w}-qrcode-toolkit',f'{wb}/extensions/sd-{w}-qrcode-toolkit')
|
157 |
+
gitDownload(f'https://github.com/yankooliveira/sd-{w}-photopea-embed',f'{wb}/extensions/sd-{w}-photopea-embed')
|
158 |
+
gitDownload(f'https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111',f'{wb}/extensions/multidiffusion-upscaler-for-automatic1111')
|
|
|
|
|
|
|
|
|
159 |
|
160 |
# ControlNet模型
|
161 |
Cnt_models = [
|
162 |
+
'control_v11e_sd15_ip2p.pth',
|
163 |
+
'control_v11e_sd15_shuffle.pth',
|
164 |
+
'control_v11f1e_sd15_tile.pth',
|
165 |
+
'control_v11f1p_sd15_depth.pth',
|
166 |
+
'control_v11p_sd15_canny.pth',
|
167 |
+
'control_v11p_sd15_inpaint.pth',
|
168 |
+
'control_v11p_sd15_lineart.pth',
|
169 |
+
'control_v11p_sd15_mlsd.pth',
|
170 |
+
'control_v11p_sd15_normalbae.pth',
|
171 |
+
'control_v11p_sd15_openpose.pth',
|
172 |
+
'control_v11p_sd15_scribble.pth',
|
173 |
+
'control_v11p_sd15_seg.pth',
|
174 |
+
'control_v11p_sd15_softedge.pth',
|
175 |
+
'control_v11p_sd15s2_lineart_anime.pth',
|
176 |
]
|
177 |
get_ipython().system(f'rm -rf {wb}/extensions/sd-{w}-controlnet')
|
178 |
# 模型下载到Colab
|
179 |
+
if ControlNet == "Colab":
|
180 |
gitDownload(f'https://github.com/Mikubill/sd-{w}-controlnet',f'{wb}/extensions/sd-{w}-controlnet')
|
181 |
for v in Cnt_models:
|
182 |
+
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/{v} -d {wb}/extensions/sd-{w}-controlnet/models -o {v}')
|
183 |
+
|
184 |
+
# 模型下载到Google_Drive
|
185 |
+
elif ControlNet == "Google_Drive":
|
186 |
+
cloudDriveSync(f'{gwb}/CntModels')
|
187 |
+
gitDownload(f'https://github.com/Mikubill/sd-{w}-controlnet',f'{wb}/extensions/sd-{w}-controlnet')
|
188 |
+
for v in Cnt_models:
|
189 |
+
if not os.path.exists(f'{gwb}/CntModels/{v}'):
|
190 |
+
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/{v} -d {gwb}/CntModels -o {v}')
|
191 |
+
print("创建扩展",f'{v}')
|
192 |
+
else:
|
193 |
+
print("扩展存在",f'{v}')
|
194 |
+
# 遍历cntmodels目录下的文件,将文件银接到Colab目录下的extensions目录下
|
195 |
+
for v in os.listdir(f'{gwb}/CntModels'):
|
196 |
+
# 链接云盘目录
|
197 |
+
get_ipython().system(f'ln -s {gwb}/CntModels/{v} {wb}/extensions/sd-{w}-controlnet/models')
|
198 |
+
|
199 |
+
elif ControlNet == "No":
|
200 |
+
print("不使用 ControlNet")
|
201 |
|
202 |
# 各种UI界面
|
203 |
if UI == "Kitchen_Ui":
|
|
|
206 |
elif UI == "Lobe_Ui":
|
207 |
gitDownload(f'https://github.com/canisminor1990/sd-web-ui-kitchen-theme', f'{wb}/extensions/sd-web-ui-kitchen-theme')
|
208 |
print("Lobe界面插件启用")
|
|
|
|
|
|
|
209 |
elif UI == "No":
|
210 |
print("UI插件不启用")
|
211 |
+
|
212 |
# 关键词
|
213 |
if Key_words:
|
214 |
gitDownload(f'https://github.com/Physton/sd-{w}-prompt-all-in-one', f'{wb}/extensions/sd-{w}-prompt-all-in-one')
|
215 |
+
cloudDriveSync(f'{gwb}/Storage', f'{wb}/extensions/sd-{w}-prompt-all-in-one/storage', Drive_Map)
|
216 |
print("关键词插件启用")
|
217 |
else:
|
218 |
get_ipython().system(f'rm -rf {wb}/extensions/sd-{w}-prompt-all-in-one')
|
|
|
220 |
|
221 |
# 初始化本地环境
|
222 |
def initLocal():
|
|
|
223 |
#部署 env 环境变量
|
224 |
get_ipython().system(f'apt -y update -qq')
|
225 |
+
get_ipython().system(f'wget https://github.com/camenduru/gperftools/releases/download/v1.0/libtcmalloc_minimal.so.4 -O /content/libtcmalloc_minimal.so.4')
|
226 |
get_ipython().run_line_magic('env', 'LD_PRELOAD=/content/libtcmalloc_minimal.so.4')
|
227 |
|
228 |
#设置 python 环境
|
|
|
232 |
|
233 |
#主框架模块
|
234 |
if Version == "A1111":
|
235 |
+
get_ipython().system(f'git clone -b master https://github.com/AUTOMATIC1111/{sdw} {wb}')
|
236 |
+
elif Version == "V2.5":
|
237 |
+
get_ipython().system(f'git clone -b v2.5 https://github.com/camenduru/{sdw} {wb}')
|
238 |
+
elif Version == "V2.4":
|
239 |
get_ipython().system(f'git clone -b v2.4 https://github.com/camenduru/{sdw} {wb}')
|
240 |
|
241 |
+
get_ipython().system(f'git -C {wb}/repositories/stable-diffusion-stability-ai reset --hard')
|
242 |
+
|
|
|
243 |
# 初始化云盘
|
244 |
initCloudDrive()
|
245 |
|
246 |
# 安装附加功能
|
247 |
installAdditional()
|
248 |
|
249 |
+
# 删除原配置
|
250 |
+
get_ipython().system(f'rm -f {wb}/config.json')
|
251 |
+
|
252 |
+
# 链接用户配置
|
253 |
+
get_ipython().system(f'ln -s {gwb}/Config/config.json {wb}/config.json')
|
254 |
|
255 |
+
#如果{gwb}有styles.csv文件则同��到{wb},反之则取消该操作
|
256 |
+
if os.path.exists(f"{gwb}/styles.csv"):
|
257 |
+
get_ipython().system(f'ln -s {gwb}/styles.csv {wb}/styles.csv')
|
258 |
+
|
259 |
+
# 同步additional-networks
|
260 |
+
if os.path.exists(f"{wb}/extensions/sd-{w}-additional-networks"):
|
261 |
+
cloudDriveSync(f'{gwb}/Lora', f'{wb}/extensions/sd-{w}-additional-networks/models/lora', Drive_Map)
|
262 |
+
# cloudDriveSync(f'{gwb}/LyCORIS', f'{wb}/extensions/sd-{w}-additional-networks/models/lora/lycoris', Drive_Map)
|
263 |
+
|
264 |
+
# 如果云盘没有模型
|
265 |
+
if len(os.listdir(f"{gwb}/Models")) == 0:
|
266 |
#下载主模型
|
267 |
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/coco233/colab/resolve/main/ZR888.safetensors -d {wb}/models/Stable-diffusion -o zr888.safetensors')
|
268 |
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/wageguagua/sdmodels/resolve/main/long9.safetensors -d {wb}/models/Stable-diffusion -o long9.safetensors')
|
269 |
+
|
270 |
# 如果云盘Vae模型
|
271 |
+
if len(os.listdir(f"{gwb}/Vae")) == 0:
|
272 |
# #VAE
|
273 |
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors -d {wb}/models/VAE -o vae-ft-mse-840000-ema-pruned.safetensors')
|
274 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
275 |
#放大
|
276 |
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -d {wb}/models/ESRGAN -o 4x-UltraSharp.pth')
|
277 |
|
|
|
281 |
get_ipython().system(f'sed -i "s@os.path.splitext(model_file)@os.path.splitext(model_file); map_location=\'cuda\'@" {wb}/modules/sd_models.py')
|
282 |
get_ipython().system(f'sed -i "s@map_location=\'cpu\'@map_location=\'cuda\'@" {wb}/modules/extras.py')
|
283 |
get_ipython().system(f"sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' {wb}/webui.py")
|
284 |
+
|
285 |
# 运行
|
286 |
def run(script):
|
287 |
clear_output()
|
288 |
get_ipython().run_line_magic('cd', f'{wb}')
|
289 |
+
get_ipython().system(f'python {script} --listen --xformers --enable-insecure-extension-access --theme dark --gradio-queue --disable-console-progressbars --multiple --api --cors-allow-origins=*')
|
290 |
|
291 |
# 运行脚本
|
292 |
if os.path.exists(f'{wb}'):
|
|
|
295 |
# 初化本地环境
|
296 |
initLocal()
|
297 |
# 运行
|
298 |
+
run('launch.py')
|