Update webui.py
Browse files
webui.py
CHANGED
@@ -1,600 +1,188 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
"""
|
4 |
-
|
5 |
-
Automatically generated by Colaboratory.
|
6 |
-
|
7 |
-
|
8 |
-
# Colab云端部署
|
9 |
-
|
10 |
-
# 使用说明:
|
11 |
-
|
12 |
-
* 代码基于https://github.com/{ca}/【将此括号自行更换成"s*****-d********-webui】内容进行了修改调整
|
13 |
-
* 由于官方对免费用户限制,修改代码绕开运行警告
|
14 |
-
* Pro用户同样可用
|
15 |
-
* Colab云免费空间为50G,若一些插件或者模型不需要,可以注释或者删除
|
16 |
-
* Colab云断开后所有内容会清空,所以出图后可先保存到google云盘在下载到个人电脑
|
17 |
-
* 由BBrother二次修改代码内容以绕过Colab的检测,并增加了选择下载模型的功能
|
18 |
-
|
19 |
-
## 使用方法:
|
20 |
-
|
21 |
-
首次运行步骤:
|
22 |
-
|
23 |
-
1. 新建网页,登录谷歌云盘(https://drive.google.com/)
|
24 |
-
点击左上角新建—更多-关联更多应用-搜索Colaboratory,点击进入安装
|
25 |
-
2. 在该文档上方点击【复制到云端硬盘】,或者选择上方【文件】-【在云端硬盘中保存一份副本】,页面会自动跳转至副本窗口,重命名后关闭本页面
|
26 |
-
3. 在副本页面中,选择上方【代码执行程序】-【更改运行时类型】,免费用户GPU选择【T4】,Pro用户可选【A100】或【V100】,点击保存
|
27 |
-
4. 点击右上角【连接】按钮,等待成功连接后会出现绿色对勾
|
28 |
-
5. 点击下方【安装环境并运行】运行按钮,等待10分钟左右,出现网址链接,任意点开一个即可进入
|
29 |
-
6. 之后就和本地部署一样了
|
30 |
-
|
31 |
-
## 部署涵盖的插件列表:
|
32 |
-
手动将所有的括号换成指定的内容:
|
33 |
-
(s)=s t a b l e
|
34 |
-
(d)=d i f f u s i o n
|
35 |
-
1. deforum-for-automatic1111-webui: 这是一个用于自动化web界面的插件,它可以让您在网页上创建和管理您的项目。
|
36 |
-
2. (s)-(d)-Webui-Civitai-Helper: 这是一个用于稳定扩散web界面的插件,它可以帮助您使用Civitai平台进行人工智能开发。
|
37 |
-
3. sd-web-controlnet: 这是一个用于sd-web的插件,它可以让您控制和监控您的网络状态。
|
38 |
-
4. openpose-editor: 这是一个用于编辑人体姿态的插件,它可以让您在web界面上对人体姿态进行修改和优化。
|
39 |
-
5. sd-web-depth-lib: 这是一个用于sd-web的插件,它可以让您使用深度学习库进行图像处理。
|
40 |
-
6. (s)-(d)-webui-huggingface: 这是一个用于稳定扩散web界面的插件,它可以让您使用huggingface平台进行自然语言处理。
|
41 |
-
7. sd-web-additional-networks: 这是一个用于sd-web的插件,它可以让您使用额外的网络模型进行图像处理。
|
42 |
-
8. posex: 这是一个用于生成人体姿态的插件,它可以让您在web界面上创建和编辑人体姿态。
|
43 |
-
9. sd-web-3d-open-pose-editor: 这是一个用于编辑三维人体姿态的插件,它可以让您在web界面上对三维人体姿态进行修改和优化。
|
44 |
-
10. sd-web-t'u'n'n'e'l's: 这是一个用于sd-web的插件,它可以让您使用隧道技术进行网络连接。
|
45 |
-
11. batchlinks-webui: 这是一个用于批量下载链接的插件,它可以让您在web界面上输入和管理链接。
|
46 |
-
12. (s)-(d)-webui-catppuccin: 这是一个用于稳定扩散web界面的插件,它可以让您使用catppuccin主题美化您的界面。
|
47 |
-
13. (s)-(d)-webui-rembg: 这是一个用于稳定扩散web界面的插件,它可以让您使用rembg工具去除图像背景。
|
48 |
-
14. (s)-(d)-webui-two-shot: 这是一个用于稳定扩散web界面的插件,它可以让您使用two-shot技术生成图像。
|
49 |
-
15. sd-web-aspect-ratio-helper: 这是一个用于sd-web的插件,它可以帮助您调整图像的纵横比。
|
50 |
-
16. adetailer: 这是一个用于增强图像细节的插件,它可以让您在web界面上对图像进行放大和清晰化。
|
51 |
-
17. sd-dynamic-thresholding: 这是一个用于sd-web的插件,它可以让您使用动态阈值法进行图像分割。
|
52 |
-
18. sd-dynamic-prompts: 这是一个用于sd-web的插件,它可以让您使用动态提示法生成图像。
|
53 |
-
19. (s)-(d)-webui-wildcards: 这是一个用于稳定扩散web界面的插件,它可以让您使用通配符法生成图像。
|
54 |
-
20. sd-web-segment-anything: 这是一个用于sd-web的插件,它可以让您使用segment anything技术对任意物体进行分割。
|
55 |
-
21. (s)-(d)-webui-localization-zh_CN: 这是一个用于稳定扩散web界面的插件,它可以让您使用中文语言进行界面操作。
|
56 |
-
22. multi-(d)-upscaler-for-automatic1111: 这是一个用于多扩散放大器的插件,它可以让您使用automatic1111平台进行图像放大。
|
57 |
-
23. sd-web-prompt-all-in-one: 这是一个用于sd-web的插件,它可以让您使用一体化提示法生成图像。
|
58 |
-
|
59 |
-
# 环境安装及运行
|
60 |
-
"""
|
61 |
-
|
62 |
-
import binascii
|
63 |
import os
|
64 |
-
import
|
65 |
-
|
66 |
-
import
|
67 |
-
import
|
68 |
-
import
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
subprocess.run(["git", "clone", repo_url, destination])
|
122 |
-
|
123 |
-
extensions_path = "/root/main/extensions"
|
124 |
-
|
125 |
-
extensions_to_clone = [
|
126 |
-
(f"https://github.com/deforum-art/deforum-for-automatic1111-{w}", f"{extensions_path}/deforum-for-automatic1111-{w}"),
|
127 |
-
(f"https://github.com/deforum-art/sd-{w}-deforum", f"{extensions_path}/sd-{w}-deforum"),
|
128 |
-
(f"https://github.com/butaixianran/Stable-Diffusion-Webui-Civitai-Helper", f"{extensions_path}/Stable-Diffusion-Webui-Civitai-Helper"),
|
129 |
-
(f"https://github.com/Mikubill/{c}-{w}-controlnet", f"{extensions_path}/{c}-{w}-controlnet"),
|
130 |
-
(f"https://github.com/fkunn1326/openpose-editor", f"{extensions_path}/openpose-editor"),
|
131 |
-
(f"https://github.com/{ca}/{a}-{d}-{w}-huggingface", f"{extensions_path}/{a}-{d}-{w}-huggingface"),
|
132 |
-
(f"https://github.com/kohya-ss/{c}-{w}-additional-networks", f"{extensions_path}/{c}-{w}-additional-networks"),
|
133 |
-
(f"https://github.com/hnmr293/posex", f"{extensions_path}/posex"),
|
134 |
-
(f"https://github.com/nonnonstop/{c}-{w}-3d-open-pose-editor", f"{extensions_path}/{c}-{w}-3d-open-pose-editor"),
|
135 |
-
(f"https://github.com/{ca}/{c}-{w}-tunnels", f"{extensions_path}/{c}-{w}-tunnels"),
|
136 |
-
(f"https://github.com/etherealxx/batchlinks-{w}", f"{extensions_path}/batchlinks-{w}"),
|
137 |
-
(f"https://github.com/catppuccin/{a}-{d}-{w}", f"{extensions_path}/{a}-{d}-{w}-catppuccin"),
|
138 |
-
(f"https://github.com/AUTOMATIC1111/{a}-{d}-{w}-rembg", f"{extensions_path}/{a}-{d}-{w}-rembg"),
|
139 |
-
(f"https://github.com/ashen-sensored/{a}-{d}-{w}-two-shot.git", f"{extensions_path}/{a}-{d}-{w}-two-shot"),
|
140 |
-
(f"https://github.com/thomasasfk/{c}-{w}-aspect-ratio-helper", f"{extensions_path}/{c}-{w}-aspect-ratio-helper"),
|
141 |
-
(f"https://github.com/Bing-su/adetailer", f"{extensions_path}/adetailer"),
|
142 |
-
(f"https://github.com/mcmonkeyprojects/sd-dynamic-thresholding", f"{extensions_path}/{c}-dynamic-thresholding"),
|
143 |
-
(f"https://github.com/adieyal/{c}-dynamic-prompts", f"{extensions_path}/{c}-dynamic-prompts"),
|
144 |
-
(f"https://github.com/AUTOMATIC1111/{a}-{d}-{w}-wildcards", f"{extensions_path}/{a}-{d}-{w}-wildcards"),
|
145 |
-
(f"https://github.com/continue-revolution/{c}-{w}-segment-anything", f"{extensions_path}/{c}-{w}-segment-anything"),
|
146 |
-
(f"https://github.com/pkuliyi2015/multi{d}-upscaler-for-automatic1111.git", f"{extensions_path}/multi{d}-upscaler-for-automatic1111"),
|
147 |
-
(f"https://github.com/Physton/{c}-{w}-prompt-all-in-one", f"{extensions_path}/{c}-{w}-prompt-all-in-one"),
|
148 |
-
(f"https://github.com/journey-ad/{c}-{w}-bilingual-localization", f"{extensions_path}/{c}-{w}-bilingual-localization"),
|
149 |
-
(f"https://github.com/Bobo-1125/{c}-{w}-oldsix-prompt-dynamic", f"{extensions_path}/{c}-{w}-oldsix-prompt-dynamic"),
|
150 |
-
#(f"https://github.com/dtlnor/{st}-localization-zh_CN", f"{extensions_path}/{st}-localization-zh_CN-main"),
|
151 |
-
(f"https://github.com/zanllp/sd-{w}-infinite-image-browsing", f"{extensions_path}/sd-{w}-infinite-image-browsing"),
|
152 |
-
(f"https://github.com/s0md3v/roop", f"{extensions_path}/roop"),
|
153 |
-
(f"https://github.com/journey-ad/sd-webui-bilingual-localization", f"{extensions_path}/sd-{w}-bilingual-localization"),
|
154 |
-
]
|
155 |
-
|
156 |
-
for repo_url, destination in extensions_to_clone:
|
157 |
-
run_git_clone(repo_url, destination)
|
158 |
-
|
159 |
-
|
160 |
-
# 定义一个函数来运行wget命令
|
161 |
-
def run_wget(url, output_path):
|
162 |
-
wget_command = ["wget", url, "-O", output_path]
|
163 |
-
subprocess.run(wget_command, check=True)
|
164 |
-
|
165 |
-
# 定义一个函数来创建文件夹(如果不存在的话)
|
166 |
-
def create_directory(directory):
|
167 |
-
mkdir_command = ["mkdir", "-p", directory]
|
168 |
-
subprocess.run(mkdir_command, check=True)
|
169 |
-
|
170 |
-
|
171 |
-
# 安装可选模块
|
172 |
-
print ("安装可选模块...")
|
173 |
-
|
174 |
-
# 其它基本配置
|
175 |
-
CONTROLNET_ = True
|
176 |
-
T2I_ = True
|
177 |
-
|
178 |
-
# CN
|
179 |
-
if CONTROLNET_:
|
180 |
-
os.makedirs('/root/main/extensions/control/models', exist_ok=True)
|
181 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors', '/root/main/extensions/control/models/control_v11e_sd15_ip2p_fp16.safetensors')
|
182 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors', '/root/main/extensions/control/models/control_v11e_sd15_shuffle_fp16.safetensors')
|
183 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors', '/root/main/extensions/control/models/control_v11p_sd15_canny_fp16.safetensors')
|
184 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors', '/root/main/extensions/control/models/control_v11f1p_sd15_depth_fp16.safetensors')
|
185 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors', '/root/main/extensions/control/models/control_v11p_sd15_inpaint_fp16.safetensors')
|
186 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors', '/root/main/extensions/control/models/control_v11p_sd15_lineart_fp16.safetensors')
|
187 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors', '/root/main/extensions/control/models/control_v11p_sd15_mlsd_fp16.safetensors')
|
188 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors', '/root/main/extensions/control/models/control_v11p_sd15_normalbae_fp16.safetensors')
|
189 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors', '/root/main/extensions/control/models/control_v11p_sd15_openpose_fp16.safetensors')
|
190 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors', '/root/main/extensions/control/models/control_v11p_sd15_scribble_fp16.safetensors')
|
191 |
-
#wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors', '/root/main/extensions/control/models/control_v11p_sd15_seg_fp16.safetensors')
|
192 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors', '/root/main/extensions/control/models/control_v11p_sd15_softedge_fp16.safetensors')
|
193 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors', '/root/main/extensions/control/models/control_v11p_sd15s2_lineart_anime_fp16.safetensors')
|
194 |
-
#wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_tile_fp16.yaml', '/root/main/extensions/control/models/control_v11e_sd15_tile_fp16.yaml')
|
195 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml', '/root/main/extensions/control/models/control_v11e_sd15_ip2p_fp16.yaml')
|
196 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml', '/root/main/extensions/control/models/control_v11e_sd15_shuffle_fp16.yaml')
|
197 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml', '/root/main/extensions/control/models/control_v11p_sd15_canny_fp16.yaml')
|
198 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml', '/root/main/extensions/control/models/control_v11f1p_sd15_depth_fp16.yaml')
|
199 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml', '/root/main/extensions/control/models/control_v11p_sd15_inpaint_fp16.yaml')
|
200 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml', '/root/main/extensions/control/models/control_v11p_sd15_lineart_fp16.yaml')
|
201 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml', '/root/main/extensions/control/models/control_v11p_sd15_mlsd_fp16.yaml')
|
202 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml', '/root/main/extensions/control/models/control_v11p_sd15_normalbae_fp16.yaml')
|
203 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml', '/root/main/extensions/control/models/control_v11p_sd15_openpose_fp16.yaml')
|
204 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml', '/root/main/extensions/control/models/control_v11p_sd15_scribble_fp16.yaml')
|
205 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml', '/root/main/extensions/control/models/control_v11p_sd15_seg_fp16.yaml')
|
206 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml', '/root/main/extensions/control/models/control_v11p_sd15_softedge_fp16.yaml')
|
207 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15s2_lineart_anime_fp16.yaml', '/root/main/extensions/control/models/control_v11p_sd15s2_lineart_anime_fp16.yaml')
|
208 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml', '/root/main/extensions/control/models')
|
209 |
-
|
210 |
-
# T2I
|
211 |
-
if T2I_:
|
212 |
-
os.makedirs('/root/main/extensions/control/models', exist_ok=True)
|
213 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_style_sd14v1.pth', '/root/main/extensions/control/models/t2iadapter_style_sd14v1.pth')
|
214 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_sketch_sd14v1.pth', '/root/main/extensions/control/models/t2iadapter_sketch_sd14v1.pth')
|
215 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_seg_sd14v1.pth', '/root/main/extensions/control/models/t2iadapter_seg_sd14v1.pth')
|
216 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_openpose_sd14v1.pth', '/root/main/extensions/control/models/t2iadapter_openpose_sd14v1.pth')
|
217 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_keypose_sd14v1.pth', '/root/main/extensions/control/models/t2iadapter_keypose_sd14v1.pth')
|
218 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_depth_sd14v1.pth', '/root/main/extensions/control/models/t2iadapter_depth_sd14v1.pth')
|
219 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_color_sd14v1.pth', '/root/main/extensions/control/models/t2iadapter_color_sd14v1.pth')
|
220 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_canny_sd14v1.pth', '/root/main/extensions/control/models/t2iadapter_canny_sd14v1.pth')
|
221 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_canny_sd15v2.pth', '/root/main/extensions/control/models/t2iadapter_canny_sd15v2.pth')
|
222 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_depth_sd15v2.pth', '/root/main/extensions/control/models/t2iadapter_depth_sd15v2.pth')
|
223 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_sketch_sd15v2.pth', '/root/main/extensions/control/models/t2iadapter_sketch_sd15v2.pth')
|
224 |
-
wget.download('https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_zoedepth_sd15v1.pth', '/root/main/extensions/control/models/t2iadapter_zoedepth_sd15v1.pth')
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
"""# 模型下载"""
|
230 |
-
|
231 |
-
print ("开始下载Checkpoints/safetensors等大模型")
|
232 |
-
# Checkpoints/safetensors等大模型下载
|
233 |
-
# 下载任务1
|
234 |
-
CS_destination_folder1 = f"/root/main/models/Stable-diffusion"
|
235 |
-
CS_target1 = f"{CS_destination_folder1}/{CS_filename1}"
|
236 |
-
|
237 |
-
if CS_download1:
|
238 |
-
os.makedirs(CS_destination_folder1, exist_ok=True)
|
239 |
-
response = requests.get(CS_url1)
|
240 |
-
with open(CS_target1, 'wb') as f:
|
241 |
-
f.write(response.content)
|
242 |
-
|
243 |
-
# 下载任务2
|
244 |
-
CS_destination_folder2 = f"/root/main/models/Stable-diffusion"
|
245 |
-
CS_target2 = f"{CS_destination_folder2}/{CS_filename2}"
|
246 |
-
|
247 |
-
if CS_download2:
|
248 |
-
os.makedirs(CS_destination_folder2, exist_ok=True)
|
249 |
-
response = requests.get(CS_url2)
|
250 |
-
with open(CS_target2, 'wb') as f:
|
251 |
-
f.write(response.content)
|
252 |
-
|
253 |
-
# 下载任务3
|
254 |
-
CS_destination_folder3 = f"/root/main/models/Stable-diffusion"
|
255 |
-
CS_target3 = f"{CS_destination_folder3}/{CS_filename3}"
|
256 |
-
|
257 |
-
if CS_download3:
|
258 |
-
os.makedirs(CS_destination_folder3, exist_ok=True)
|
259 |
-
response = requests.get(CS_url3)
|
260 |
-
with open(CS_target3, 'wb') as f:
|
261 |
-
f.write(response.content)
|
262 |
-
|
263 |
-
# 下载任务4
|
264 |
-
CS_destination_folder4 = f"/root/main/models/Stable-diffusion"
|
265 |
-
CS_target4 = f"{CS_destination_folder4}/{CS_filename4}"
|
266 |
-
|
267 |
-
if CS_download4:
|
268 |
-
os.makedirs(CS_destination_folder4, exist_ok=True)
|
269 |
-
response = requests.get(CS_url4)
|
270 |
-
with open(CS_target4, 'wb') as f:
|
271 |
-
f.write(response.content)
|
272 |
-
|
273 |
-
# 下载任务5
|
274 |
-
CS_destination_folder5 = f"/root/main/models/Stable-diffusion"
|
275 |
-
CS_target5 = f"{CS_destination_folder5}/{CS_filename5}"
|
276 |
-
|
277 |
-
if CS_download5:
|
278 |
-
os.makedirs(CS_destination_folder5, exist_ok=True)
|
279 |
-
response = requests.get(CS_url5)
|
280 |
-
with open(CS_target5, 'wb') as f:
|
281 |
-
f.write(response.content)
|
282 |
-
|
283 |
-
# 下载任务6
|
284 |
-
CS_destination_folder6 = f"/root/main/models/Stable-diffusion"
|
285 |
-
CS_target6 = f"{CS_destination_folder6}/{CS_filename6}"
|
286 |
-
|
287 |
-
if CS_download6:
|
288 |
-
os.makedirs(CS_destination_folder6, exist_ok=True)
|
289 |
-
response = requests.get(CS_url6)
|
290 |
-
with open(CS_target6, 'wb') as f:
|
291 |
-
f.write(response.content)
|
292 |
-
|
293 |
-
# 下载任务7
|
294 |
-
CS_destination_folder7 = f"/root/main/models/Stable-diffusion"
|
295 |
-
CS_target7 = f"{CS_destination_folder7}/{CS_filename7}"
|
296 |
-
|
297 |
-
if CS_download7:
|
298 |
-
os.makedirs(CS_destination_folder7, exist_ok=True)
|
299 |
-
response = requests.get(CS_url7)
|
300 |
-
with open(CS_target7, 'wb') as f:
|
301 |
-
f.write(response.content)
|
302 |
-
|
303 |
-
# 下载任务8
|
304 |
-
CS_destination_folder8 = f"/root/main/models/Stable-diffusion"
|
305 |
-
CS_target8 = f"{CS_destination_folder8}/{CS_filename8}"
|
306 |
-
|
307 |
-
if CS_download8:
|
308 |
-
os.makedirs(CS_destination_folder8, exist_ok=True)
|
309 |
-
response = requests.get(CS_url8)
|
310 |
-
with open(CS_target8, 'wb') as f:
|
311 |
-
f.write(response.content)
|
312 |
-
|
313 |
-
# 下载任务9
|
314 |
-
CS_destination_folder9 = f"/root/main/models/Stable-diffusion"
|
315 |
-
CS_target9 = f"{CS_destination_folder9}/{CS_filename9}"
|
316 |
-
|
317 |
-
if CS_download9:
|
318 |
-
os.makedirs(CS_destination_folder9, exist_ok=True)
|
319 |
-
response = requests.get(CS_url9)
|
320 |
-
with open(CS_target9, 'wb') as f:
|
321 |
-
f.write(response.content)
|
322 |
-
|
323 |
-
# 下载任务10
|
324 |
-
CS_destination_folder10 = f"/root/main/models/Stable-diffusion"
|
325 |
-
CS_target10 = f"{CS_destination_folder10}/{CS_filename10}"
|
326 |
-
|
327 |
-
if CS_download10:
|
328 |
-
os.makedirs(CS_destination_folder10, exist_ok=True)
|
329 |
-
response = requests.get(CS_url10)
|
330 |
-
with open(CS_target10, 'wb') as f:
|
331 |
-
f.write(response.content)
|
332 |
-
|
333 |
-
# 下载任务11
|
334 |
-
CS_destination_folder11 = f"/root/main/models/Stable-diffusion"
|
335 |
-
CS_target11 = f"{CS_destination_folder11}/{CS_filename11}"
|
336 |
-
|
337 |
-
if CS_download11:
|
338 |
-
os.makedirs(CS_destination_folder11, exist_ok=True)
|
339 |
-
response = requests.get(CS_url11)
|
340 |
-
with open(CS_target11, 'wb') as f:
|
341 |
-
f.write(response.content)
|
342 |
-
|
343 |
-
# 下载任务12
|
344 |
-
CS_destination_folder12 = f"/root/main/models/Stable-diffusion"
|
345 |
-
CS_target12 = f"{CS_destination_folder12}/{CS_filename12}"
|
346 |
-
|
347 |
-
if CS_download12:
|
348 |
-
os.makedirs(CS_destination_folder12, exist_ok=True)
|
349 |
-
response = requests.get(CS_url12)
|
350 |
-
with open(CS_target12, 'wb') as f:
|
351 |
-
f.write(response.content)
|
352 |
-
|
353 |
-
# 下载任务13
|
354 |
-
CS_destination_folder13 = f"/root/main/models/Stable-diffusion"
|
355 |
-
CS_target13 = f"{CS_destination_folder13}/{CS_filename13}"
|
356 |
-
|
357 |
-
if CS_download13:
|
358 |
-
os.makedirs(CS_destination_folder13, exist_ok=True)
|
359 |
-
response = requests.get(CS_url13)
|
360 |
-
with open(CS_target13, 'wb') as f:
|
361 |
-
f.write(response.content)
|
362 |
-
|
363 |
-
|
364 |
-
#Lora模型下载
|
365 |
-
|
366 |
-
print("开始下载Lora模型")
|
367 |
-
# Lora任务1
|
368 |
-
Lora_destination_folder1 = "/root/main/models/Lora"
|
369 |
-
Lora_target1 = os.path.join(Lora_destination_folder1, Lora_filename1)
|
370 |
-
|
371 |
-
if Lora_download1:
|
372 |
-
response = requests.get(Lora_url1)
|
373 |
-
if response.status_code == 200:
|
374 |
-
with open(Lora_target1, 'wb') as f:
|
375 |
-
f.write(response.content)
|
376 |
-
|
377 |
-
# Lora任务2
|
378 |
-
Lora_destination_folder2 = "/root/main/models/Lora"
|
379 |
-
Lora_target2 = os.path.join(Lora_destination_folder2, Lora_filename2)
|
380 |
-
|
381 |
-
if Lora_download2:
|
382 |
-
response = requests.get(Lora_url2)
|
383 |
-
if response.status_code == 200:
|
384 |
-
with open(Lora_target2, 'wb') as f:
|
385 |
-
f.write(response.content)
|
386 |
-
|
387 |
-
# Lora任务3
|
388 |
-
Lora_destination_folder3 = "/root/main/models/Lora"
|
389 |
-
Lora_target3 = os.path.join(Lora_destination_folder3, Lora_filename3)
|
390 |
-
|
391 |
-
if Lora_download3:
|
392 |
-
response = requests.get(Lora_url3)
|
393 |
-
if response.status_code == 200:
|
394 |
-
with open(Lora_target3, 'wb') as f:
|
395 |
-
f.write(response.content)
|
396 |
-
|
397 |
-
# Lora任务4
|
398 |
-
Lora_destination_folder4 = Lora_destination_folder3
|
399 |
-
Lora_target4 = os.path.join(Lora_destination_folder4, Lora_filename4)
|
400 |
-
|
401 |
-
if Lora_download4:
|
402 |
-
response = requests.get(Lora_url4)
|
403 |
-
if response.status_code == 200:
|
404 |
-
with open(Lora_target4, 'wb') as f:
|
405 |
-
f.write(response.content)
|
406 |
-
|
407 |
-
# Lora任务5
|
408 |
-
Lora_destination_folder5 = Lora_destination_folder3
|
409 |
-
Lora_target5 = os.path.join(Lora_destination_folder5, Lora_filename5)
|
410 |
-
|
411 |
-
if Lora_download5:
|
412 |
-
response = requests.get(Lora_url5)
|
413 |
-
if response.status_code == 200:
|
414 |
-
with open(Lora_target5, 'wb') as f:
|
415 |
-
f.write(response.content)
|
416 |
-
|
417 |
-
# Lora任务6
|
418 |
-
Lora_destination_folder6 = Lora_destination_folder3
|
419 |
-
Lora_target6 = os.path.join(Lora_destination_folder6, Lora_filename6)
|
420 |
-
|
421 |
-
if Lora_download6:
|
422 |
-
response = requests.get(Lora_url6)
|
423 |
-
if response.status_code == 200:
|
424 |
-
with open(Lora_target6, 'wb') as f:
|
425 |
-
f.write(response.content)
|
426 |
-
|
427 |
-
|
428 |
-
# VAE下载
|
429 |
-
|
430 |
-
print ("开始下载VAE模型")
|
431 |
-
# VAE任务1
|
432 |
-
VAE_destination_folder1 = "/root/main/models/VAE"
|
433 |
-
VAE_target1 = f"{VAE_destination_folder1}/{VAE_filename1}"
|
434 |
-
|
435 |
-
if VAE_download1:
|
436 |
-
response = requests.get(VAE_url1)
|
437 |
-
with open(VAE_target1, 'wb') as file:
|
438 |
-
file.write(response.content)
|
439 |
-
|
440 |
-
# VAE任务2
|
441 |
-
VAE_destination_folder2 = "/root/main/models/VAE"
|
442 |
-
VAE_target2 = f"{VAE_destination_folder2}/{VAE_filename2}"
|
443 |
-
|
444 |
-
if VAE_download2:
|
445 |
-
response = requests.get(VAE_url2)
|
446 |
-
with open(VAE_target2, 'wb') as file:
|
447 |
-
file.write(response.content)
|
448 |
-
|
449 |
-
# VAE任务3
|
450 |
-
VAE_destination_folder3 = "/root/main/models/VAE"
|
451 |
-
VAE_target3 = f"{VAE_destination_folder3}/{VAE_filename3}"
|
452 |
-
|
453 |
-
if VAE_download3:
|
454 |
-
response = requests.get(VAE_url3)
|
455 |
-
with open(VAE_target3, 'wb') as file:
|
456 |
-
file.write(response.content)
|
457 |
-
|
458 |
-
# VAE任务4
|
459 |
-
VAE_destination_folder4 = "/root/main/models/VAE"
|
460 |
-
VAE_target4 = f"{VAE_destination_folder4}/{VAE_filename4}"
|
461 |
-
|
462 |
-
if VAE_download4:
|
463 |
-
response = requests.get(VAE_url4)
|
464 |
-
with open(VAE_target4, 'wb') as file:
|
465 |
-
file.write(response.content)
|
466 |
-
|
467 |
-
# VAE任务5
|
468 |
-
VAE_destination_folder5 = "/root/main/models/VAE"
|
469 |
-
VAE_target5 = f"{VAE_destination_folder5}/{VAE_filename5}"
|
470 |
-
|
471 |
-
if VAE_download5:
|
472 |
-
response = requests.get(VAE_url5)
|
473 |
-
with open(VAE_target5, 'wb') as file:
|
474 |
-
file.write(response.content)
|
475 |
-
|
476 |
-
# VAE任务6
|
477 |
-
VAE_destination_folder6 = "/root/main/models/VAE"
|
478 |
-
VAE_target6 = f"{VAE_destination_folder6}/{VAE_filename6}"
|
479 |
-
|
480 |
-
if VAE_download6:
|
481 |
-
response = requests.get(VAE_url6)
|
482 |
-
with open(VAE_target6, 'wb') as file:
|
483 |
-
file.write(response.content)
|
484 |
-
|
485 |
-
# VAE任务7
|
486 |
-
VAE_destination_folder7 = "/root/main/models/VAE"
|
487 |
-
VAE_target7 = f"{VAE_destination_folder7}/{VAE_filename7}"
|
488 |
-
|
489 |
-
if VAE_download7:
|
490 |
-
response = requests.get(VAE_url7)
|
491 |
-
with open(VAE_target7, 'wb') as file:
|
492 |
-
file.write(response.content)
|
493 |
-
|
494 |
-
# VAE任务8
|
495 |
-
VAE_destination_folder8 = "/root/main/models/VAE"
|
496 |
-
VAE_target8 = f"{VAE_destination_folder8}/{VAE_filename8}"
|
497 |
-
|
498 |
-
if VAE_download8:
|
499 |
-
response = requests.get(VAE_url8)
|
500 |
-
with open(VAE_target8, 'wb') as file:
|
501 |
-
file.write(response.content)
|
502 |
-
|
503 |
-
# VAE任务9
|
504 |
-
VAE_destination_folder9 = "/root/main/models/VAE"
|
505 |
-
VAE_target9 = f"{VAE_destination_folder9}/{VAE_filename9}"
|
506 |
-
|
507 |
-
if VAE_download9:
|
508 |
-
response = requests.get(VAE_url9)
|
509 |
-
with open(VAE_target9, 'wb') as file:
|
510 |
-
file.write(response.content)
|
511 |
-
|
512 |
-
# VAE任务10
|
513 |
-
VAE_destination_folder10 = "/root/main/models/VAE"
|
514 |
-
VAE_target10 = f"{VAE_destination_folder10}/{VAE_filename10}"
|
515 |
-
|
516 |
-
if VAE_download10:
|
517 |
-
response = requests.get(VAE_url10)
|
518 |
-
with open(VAE_target10, 'wb') as file:
|
519 |
-
file.write(response.content)
|
520 |
-
|
521 |
-
# VAE任务11
|
522 |
-
VAE_destination_folder11 = "/root/main/models/VAE"
|
523 |
-
VAE_target11 = f"{VAE_destination_folder11}/{VAE_filename11}"
|
524 |
-
|
525 |
-
if VAE_download11:
|
526 |
-
response = requests.get(VAE_url11)
|
527 |
-
with open(VAE_target11, 'wb') as file:
|
528 |
-
file.write(response.content)
|
529 |
-
|
530 |
-
# VAE任务12
|
531 |
-
VAE_destination_folder12 = "/root/main/models/VAE"
|
532 |
-
VAE_target12 = f"{VAE_destination_folder12}/{VAE_filename12}"
|
533 |
-
|
534 |
-
if VAE_download12:
|
535 |
-
response = requests.get(VAE_url12)
|
536 |
-
with open(VAE_target12, 'wb') as file:
|
537 |
-
file.write(response.content)
|
538 |
-
|
539 |
-
# VAE任务13
|
540 |
-
VAE_destination_folder13 = "/root/main/models/VAE"
|
541 |
-
VAE_target13 = f"{VAE_destination_folder13}/{VAE_filename13}"
|
542 |
-
|
543 |
-
if VAE_download13:
|
544 |
-
response = requests.get(VAE_url13)
|
545 |
-
with open(VAE_target13, 'wb') as file:
|
546 |
-
file.write(response.content)
|
547 |
-
|
548 |
-
|
549 |
-
# embeddings模型下载
|
550 |
-
|
551 |
-
print ("开始下载embeddings模型")
|
552 |
-
# 下载任务1
|
553 |
-
embeddings_destination_folder1 = "/root/main/embeddings"
|
554 |
-
embeddings_target1 = f'{embeddings_destination_folder1}/{embeddings_filename1}'
|
555 |
-
|
556 |
-
if embeddings_download1:
|
557 |
-
os.makedirs(embeddings_destination_folder1, exist_ok=True)
|
558 |
-
response = requests.get(embeddings_url1)
|
559 |
-
with open(embeddings_target1, 'wb') as file:
|
560 |
-
file.write(response.content)
|
561 |
-
|
562 |
-
# 下载任务2
|
563 |
-
embeddings_destination_folder2 = "/root/main/embeddings"
|
564 |
-
embeddings_target2 = f'{embeddings_destination_folder2}/{embeddings_filename2}'
|
565 |
-
|
566 |
-
if embeddings_download2:
|
567 |
-
os.makedirs(embeddings_destination_folder2, exist_ok=True)
|
568 |
-
response = requests.get(embeddings_url2)
|
569 |
-
with open(embeddings_target2, 'wb') as file:
|
570 |
-
file.write(response.content)
|
571 |
-
|
572 |
-
# 下载任务3
|
573 |
-
embeddings_destination_folder3 = "/root/main/embeddings"
|
574 |
-
embeddings_target3 = f'{embeddings_destination_folder3}/{embeddings_filename3}'
|
575 |
-
|
576 |
-
if embeddings_download3:
|
577 |
-
os.makedirs(embeddings_destination_folder3, exist_ok=True)
|
578 |
-
response = requests.get(embeddings_url3)
|
579 |
-
with open(embeddings_target3, 'wb') as file:
|
580 |
-
file.write(response.content)
|
581 |
-
|
582 |
-
# 下载任务4
|
583 |
-
embeddings_destination_folder4 = "/root/main/embeddings"
|
584 |
-
embeddings_target4 = f'{embeddings_destination_folder4}/{embeddings_filename4}'
|
585 |
-
|
586 |
-
if embeddings_download4:
|
587 |
-
os.makedirs(embeddings_destination_folder4, exist_ok=True)
|
588 |
-
response = requests.get(embeddings_url4)
|
589 |
-
with open(embeddings_target4, 'wb') as file:
|
590 |
-
file.write(response.content)
|
591 |
-
|
592 |
-
# 下载任务5
|
593 |
-
embeddings_destination_folder5 = "/root/main/embeddings"
|
594 |
-
embeddings_target5 = f'{embeddings_destination_folder5}/{embeddings_filename5}'
|
595 |
-
|
596 |
-
if embeddings_download5:
|
597 |
-
os.makedirs(embeddings_destination_folder5, exist_ok=True)
|
598 |
-
response = requests.get(embeddings_url5)
|
599 |
-
with open(embeddings_target5, 'wb') as file:
|
600 |
-
file.write(response.content)
|
|
|
1 |
+
from __future__ import annotations
|
2 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import os
|
4 |
+
import time
|
5 |
+
|
6 |
+
from modules import timer
|
7 |
+
from modules import initialize_util
|
8 |
+
from modules import initialize
|
9 |
+
|
10 |
+
#ngrok穿透
|
11 |
+
ngrok_use = True
|
12 |
+
ngrokTokenFile='/root/main/Authtoken.txt' # 非必填 存放ngrokToken的文件的路径
|
13 |
+
|
14 |
+
def ngrok_start(ngrokTokenFile: str, port: int, address_name: str, should_run: bool):
|
15 |
+
if not should_run:
|
16 |
+
print('Skipping ngrok start')
|
17 |
+
return
|
18 |
+
if Path(ngrokTokenFile).exists():
|
19 |
+
with open(ngrokTokenFile, encoding="utf-8") as nkfile:
|
20 |
+
ngrokToken = nkfile.readline()
|
21 |
+
print('use nrgok')
|
22 |
+
from pyngrok import conf, ngrok
|
23 |
+
conf.get_default().auth_token = ngrokToken
|
24 |
+
conf.get_default().monitor_thread = False
|
25 |
+
ssh_tunnels = ngrok.get_tunnels(conf.get_default())
|
26 |
+
if len(ssh_tunnels) == 0:
|
27 |
+
ssh_tunnel = ngrok.connect(port, bind_tls=True)
|
28 |
+
print(f'{address_name}:' + ssh_tunnel.public_url)
|
29 |
+
else:
|
30 |
+
print(f'{address_name}:' + ssh_tunnels[0].public_url)
|
31 |
+
else:
|
32 |
+
print('skip start ngrok')
|
33 |
+
|
34 |
+
startup_timer = timer.startup_timer
|
35 |
+
startup_timer.record("launcher")
|
36 |
+
|
37 |
+
initialize.imports()
|
38 |
+
|
39 |
+
initialize.check_versions()
|
40 |
+
|
41 |
+
|
42 |
+
def create_api(app):
|
43 |
+
from modules.api.api import Api
|
44 |
+
from modules.call_queue import queue_lock
|
45 |
+
|
46 |
+
api = Api(app, queue_lock)
|
47 |
+
return api
|
48 |
+
|
49 |
+
|
50 |
+
def api_only():
|
51 |
+
|
52 |
+
from fastapi import FastAPI
|
53 |
+
from modules.shared_cmd_options import cmd_opts
|
54 |
+
|
55 |
+
initialize.initialize()
|
56 |
+
|
57 |
+
app = FastAPI()
|
58 |
+
initialize_util.setup_middleware(app)
|
59 |
+
api = create_api(app)
|
60 |
+
|
61 |
+
from modules import script_callbacks
|
62 |
+
script_callbacks.before_ui_callback()
|
63 |
+
script_callbacks.app_started_callback(None, app)
|
64 |
+
|
65 |
+
print(f"Startup time: {startup_timer.summary()}.")
|
66 |
+
api.launch(
|
67 |
+
server_name="0.0.0.0" if cmd_opts.listen else "127.0.0.1",
|
68 |
+
port=cmd_opts.port if cmd_opts.port else 7861,
|
69 |
+
root_path=f"/{cmd_opts.subpath}" if cmd_opts.subpath else ""
|
70 |
+
)
|
71 |
+
|
72 |
+
|
73 |
+
def webui():
|
74 |
+
from modules.shared_cmd_options import cmd_opts
|
75 |
+
|
76 |
+
launch_api = cmd_opts.api
|
77 |
+
initialize.initialize()
|
78 |
+
|
79 |
+
from modules import shared, ui_tempdir, script_callbacks, ui, progress, ui_extra_networks
|
80 |
+
|
81 |
+
while 1:
|
82 |
+
if shared.opts.clean_temp_dir_at_start:
|
83 |
+
ui_tempdir.cleanup_tmpdr()
|
84 |
+
startup_timer.record("cleanup temp dir")
|
85 |
+
|
86 |
+
script_callbacks.before_ui_callback()
|
87 |
+
startup_timer.record("scripts before_ui_callback")
|
88 |
+
|
89 |
+
shared.demo = ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)
|
90 |
+
startup_timer.record("create ui")
|
91 |
+
|
92 |
+
if not cmd_opts.no_gradio_queue:
|
93 |
+
shared.demo.queue(64)
|
94 |
+
|
95 |
+
gradio_auth_creds = list(initialize_util.get_gradio_auth_creds()) or None
|
96 |
+
|
97 |
+
auto_launch_browser = False
|
98 |
+
if os.getenv('SD_WEBUI_RESTARTING') != '1':
|
99 |
+
if shared.opts.auto_launch_browser == "Remote" or cmd_opts.autolaunch:
|
100 |
+
auto_launch_browser = True
|
101 |
+
elif shared.opts.auto_launch_browser == "Local":
|
102 |
+
auto_launch_browser = not any([cmd_opts.listen, cmd_opts.share, cmd_opts.ngrok, cmd_opts.server_name])
|
103 |
+
|
104 |
+
app, local_url, share_url = shared.demo.launch(
|
105 |
+
share=cmd_opts.share,
|
106 |
+
server_name=initialize_util.gradio_server_name(),
|
107 |
+
server_port=cmd_opts.port,
|
108 |
+
ssl_keyfile=cmd_opts.tls_keyfile,
|
109 |
+
ssl_certfile=cmd_opts.tls_certfile,
|
110 |
+
ssl_verify=cmd_opts.disable_tls_verify,
|
111 |
+
debug=cmd_opts.gradio_debug,
|
112 |
+
auth=gradio_auth_creds,
|
113 |
+
inbrowser=auto_launch_browser,
|
114 |
+
prevent_thread_lock=True,
|
115 |
+
allowed_paths=cmd_opts.gradio_allowed_path,
|
116 |
+
app_kwargs={
|
117 |
+
"docs_url": "/docs",
|
118 |
+
"redoc_url": "/redoc",
|
119 |
+
},
|
120 |
+
root_path=f"/{cmd_opts.subpath}" if cmd_opts.subpath else "",
|
121 |
+
)
|
122 |
+
|
123 |
+
startup_timer.record("gradio launch")
|
124 |
+
|
125 |
+
# gradio uses a very open CORS policy via app.user_middleware, which makes it possible for
|
126 |
+
# an attacker to trick the user into opening a malicious HTML page, which makes a request to the
|
127 |
+
# running web ui and do whatever the attacker wants, including installing an extension and
|
128 |
+
# running its code. We disable this here. Suggested by RyotaK.
|
129 |
+
app.user_middleware = [x for x in app.user_middleware if x.cls.__name__ != 'CORSMiddleware']
|
130 |
+
|
131 |
+
initialize_util.setup_middleware(app)
|
132 |
+
|
133 |
+
progress.setup_progress_api(app)
|
134 |
+
ui.setup_ui_api(app)
|
135 |
+
|
136 |
+
if launch_api:
|
137 |
+
create_api(app)
|
138 |
|
139 |
+
ui_extra_networks.add_pages_to_demo(app)
|
140 |
+
|
141 |
+
startup_timer.record("add APIs")
|
142 |
+
|
143 |
+
with startup_timer.subcategory("app_started_callback"):
|
144 |
+
script_callbacks.app_started_callback(shared.demo, app)
|
145 |
+
|
146 |
+
timer.startup_record = startup_timer.dump()
|
147 |
+
print(f"Startup time: {startup_timer.summary()}.")
|
148 |
+
|
149 |
+
try:
|
150 |
+
while True:
|
151 |
+
server_command = shared.state.wait_for_server_command(timeout=5)
|
152 |
+
if server_command:
|
153 |
+
if server_command in ("stop", "restart"):
|
154 |
+
break
|
155 |
+
else:
|
156 |
+
print(f"Unknown server command: {server_command}")
|
157 |
+
except KeyboardInterrupt:
|
158 |
+
print('Caught KeyboardInterrupt, stopping...')
|
159 |
+
server_command = "stop"
|
160 |
+
|
161 |
+
if server_command == "stop":
|
162 |
+
print("Stopping server...")
|
163 |
+
# If we catch a keyboard interrupt, we want to stop the server and exit.
|
164 |
+
shared.demo.close()
|
165 |
+
break
|
166 |
+
|
167 |
+
# disable auto launch webui in browser for subsequent UI Reload
|
168 |
+
os.environ.setdefault('SD_WEBUI_RESTARTING', '1')
|
169 |
+
|
170 |
+
print('Restarting UI...')
|
171 |
+
shared.demo.close()
|
172 |
+
time.sleep(0.5)
|
173 |
+
startup_timer.reset()
|
174 |
+
script_callbacks.app_reload_callback()
|
175 |
+
startup_timer.record("app reload callback")
|
176 |
+
script_callbacks.script_unloaded_callback()
|
177 |
+
startup_timer.record("scripts unloaded callback")
|
178 |
+
initialize.initialize_rest(reload_script_modules=True)
|
179 |
+
|
180 |
+
|
181 |
+
if __name__ == "__main__":
|
182 |
+
|
183 |
+
from modules.shared_cmd_options import cmd_opts
|
184 |
+
|
185 |
+
if cmd_opts.nowebui:
|
186 |
+
api_only()
|
187 |
+
else:
|
188 |
+
webui()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|