ACCA225 commited on
Commit
c31b522
1 Parent(s): 9089653

Create new.py

Browse files
Files changed (1) hide show
  1. new.py +217 -0
new.py ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 配置
2
+ install_path = '/home/xlab-app-center'
3
+ webui_repo = 'AUTOMATIC1111/stable-diffusion-webui --branch v1.7.0'
4
+ rename_repo = 'stable-diffusion-webui'
5
+ git_url = 'gitcode.com'
6
+ webui_port = 7860
7
+
8
+ api_auth = 'Echoflare:Tt25faj8'
9
+
10
+ download_tool = 'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M'
11
+
12
+ webui_args = [
13
+ # '--api',
14
+ '--xformers',
15
+ '--no-hashing',
16
+ '--disable-nan-check',
17
+ '--disable-console-progressbars',
18
+ '--enable-console-prompts',
19
+ #'--no-gradio-queue',
20
+ '--no-half-vae',
21
+ "--skip-torch-cuda-test",
22
+ '--lowram',
23
+ "--allow-code"
24
+ # f'--api-auth={api_auth}',
25
+ # '--freeze-settings',
26
+ ]
27
+
28
+ extensions = [
29
+ 'https://gitcode.com/zanllp/sd-webui-infinite-image-browsing',
30
+ 'https://gitcode.com/dtlnor/stable-diffusion-webui-localization-zh_CN', # 汉化
31
+ 'https://gitcode.com/DominikDoom/a1111-sd-webui-tagcomplete', # 提示词提示器
32
+ 'https://gitcode.com/Mikubill/sd-webui-controlnet', # ControlNet
33
+ "https://gitcode.net/overbill1683/stable-diffusion-webui-localization-zh_Hans",
34
+ #"https://gitcode.net/ranting8323/multidiffusion-upscaler-for-automatic1111",
35
+ "https://gitcode.net/ranting8323/adetailer",
36
+ "https://gitcode.net/ranting8323/sd-webui-inpaint-anything",
37
+ "https://gitcode.net/ranting8323/a1111-sd-webui-tagcomplete",
38
+ "https://openi.pcl.ac.cn/2575044704/sd-extension-system-info",
39
+ "https://openi.pcl.ac.cn/2575044704/batchlinks-webui",
40
+ 'https://openi.pcl.ac.cn/2575044704/stable-diffusion-webui-localization-zh_CN',
41
+ 'https://openi.pcl.ac.cn/2575044704/sd-webui-lora-block-weight',
42
+ 'https://openi.pcl.ac.cn/2575044704/sd-skin-extension',
43
+ "https://kkgithub.com/thygate/stable-diffusion-webui-depthmap-script.git",
44
+ #"https://gitcode.net/ranting8323/sd-webui-controlnet",
45
+ #"https://kkgithub.com/SignalFlagZ/sd-webui-civbrowser.git",
46
+ #"https://kkgithub.com/continue-revolution/sd-webui-animatediff.git",
47
+ #"https://kkkkgithub.com/aigc-apps/sd-webui-EasyPhoto.git",
48
+ "https://kkgithub.com/Iyashinouta/sd-model-downloader.git",
49
+ "https://kkgithub.com/fkunn1326/openpose-editor.git",
50
+ "https://kkgithub.com/zero01101/openOutpaint-webUI-extension.git",
51
+ "https://kkgithub.com/LonicaMewinsky/gif2gif.git",
52
+ #"https://kkgithub.com/modelscope/facechain.git",
53
+ "https://openi.pcl.ac.cn/2575044704/sd-webui-agent-scheduler",
54
+ "https://openi.pcl.ac.cn/2575044704/sd-webui-depth-lib",
55
+ "https://openi.pcl.ac.cn/Echoflare/letest"
56
+ ]
57
+
58
+ sd_models = [
59
+ #"kohakuXLDelta_rev1.safetensors@https://civitai-delivery-worker-prod.5ac0637cfd0766c97916cefa3764fbdf.r2.cloudflarestorage.com/model/478208/kohakuXlDeltaRev1.OzRM.safetensors?X-Amz-Expires=86400&response-content-disposition=attachment%3B%20filename%3D%22kohakuXLDelta_rev1.safetensors%22&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=e01358d793ad6966166af8b3064953ad/20240323/us-east-1/s3/aws4_request&X-Amz-Date=20240323T165433Z&X-Amz-SignedHeaders=host&X-Amz-Signature=7a14ba6161f355f0dd93229089f503fbbe94fbe994d42ba1e7efc1566ba584a6",
60
+ ]
61
+ lora_models = [
62
+ "https://hf-mirror.com/datasets/ACCC1380/private-model/resolve/main/ba.safetensors",
63
+ "https://hf-mirror.com/datasets/ACCC1380/private-model/resolve/main/racaco2.safetensors",
64
+
65
+ ]
66
+
67
+ vae_models = [
68
+ "https://hf-mirror.com/datasets/VASVASVAS/vae/resolve/main/pastel-waifu-diffusion.vae.pt"
69
+ ]
70
+
71
+ ControlNet = True
72
+
73
+ controlnet_models = [
74
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors',
75
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors',
76
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors',
77
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_canny_fp16.safetensors',
78
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors',
79
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_lineart_fp16.safetensors',
80
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors',
81
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors',
82
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_openpose_fp16.safetensors',
83
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_scribble_fp16.safetensors',
84
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_softedge_fp16.safetensors',
85
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors',
86
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11u_sd15_tile_fp16.safetensors',
87
+ 'https://hf-mirror.com/DionTimmer/controlnet_qrcode-control_v1p_sd15/resolve/main/control_v1p_sd15_qrcode.safetensors',
88
+ ]
89
+
90
+ embedding_models = [
91
+ "unaestheticXL_Alb2.safetensors@https://civitai-delivery-worker-prod.5ac0637cfd0766c97916cefa3764fbdf.r2.cloudflarestorage.com/model/61235/unaestheticxlAlb2.7VDr.safetensors?X-Amz-Expires=86400&response-content-disposition=attachment%3B%20filename%3D%22unaestheticXL_Alb2.safetensors%22&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=e01358d793ad6966166af8b3064953ad/20240324/us-east-1/s3/aws4_request&X-Amz-Date=20240324T042909Z&X-Amz-SignedHeaders=host&X-Amz-Signature=9d4dd419dd2e579ca1ae88fe3315f4245edc5dbfb82d38e6aaa0cd383b8889c0",
92
+ ]
93
+
94
+ hypernetwork_models = []
95
+
96
+ esrgan_models = []
97
+
98
+ custom_commands = [
99
+ f'rm -rf {install_path}/{rename_repo}/config.json',
100
+ f'rm -rf {install_path}/{rename_repo}/ui-config.json',
101
+ f'rm -rf {install_path}/{rename_repo}/modules/ui_settings.py',
102
+ f"{download_tool} https://hf-mirror.com/datasets/Mira-LeafTown/sd-webui-openxlab/raw/main/config.json -d {install_path}/{rename_repo} -o config.json --allow-overwrite=true",
103
+ f"{download_tool} https://hf-mirror.com/datasets/Mira-LeafTown/sd-webui-openxlab/raw/main/ui-config.json -d {install_path}/{rename_repo} -o ui-config.json --allow-overwrite=true",
104
+ f"{download_tool} https://hf-mirror.com/datasets/Mira-LeafTown/sd-webui-openxlab/raw/main/ui_settings.py -d {install_path}/{rename_repo}/modules -o ui_settings.py --allow-overwrite=true",
105
+ ]
106
+
107
+ # WebUI部署
108
+ import os
109
+ import re
110
+
111
+ def download_extensions(extensions):
112
+ os.chdir(f'{install_path}/{rename_repo}/extensions')
113
+ for extension in extensions:
114
+ os.system(f'git clone {extension}')
115
+
116
+ def model_download(models, type_w):
117
+ for model in models:
118
+ download_files(model, type_w)
119
+
120
+ def download_files(url, source):
121
+ if '@' in url and (not url.startswith('http://') and not url.startswith('https://')):
122
+ parts = url.split('@', 1)
123
+ name = parts[0]
124
+ url = parts[1]
125
+ rename = f"-o '{name}'"
126
+ if 'huggingface.co' in url:
127
+ url = url.replace("huggingface.co", "hf-mirror.com")
128
+ else:
129
+ if ('huggingface.co' or 'hf-mirror.com' or 'huggingface.sukaka.top') in url:
130
+ url = url.replace("huggingface.co", "hf-mirror.com")
131
+ match_name = re.search(r'/([^/?]+)(?:\?download=true)?$', url).group(1)
132
+ if match_name:
133
+ rename = f"-o '{match_name}'"
134
+ else:
135
+ rename = ''
136
+ else:
137
+ rename = ''
138
+ source_dir = f'{install_path}/{rename_repo}/{source}'
139
+ os.makedirs(source_dir, exist_ok=True)
140
+ os.chdir(source_dir)
141
+ os.system(f"{download_tool} '{url}' {rename}")
142
+ def run_webui():
143
+ os.system("pip install nvidia-ml-py3")
144
+
145
+ os.chdir(install_path)
146
+ if not os.path.exists(f'{install_path}/{rename_repo}'):
147
+ os.system(f"git clone https://openi.pcl.ac.cn/2575044704/stable-diffusion-webui-v1.8.0 {install_path}/{rename_repo}")
148
+ os.system(f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hf-mirror.com/datasets/ACCC1380/private-model/resolve/main/kaggle/input/museum/131-half.safetensors -d /home/xlab-app-center/stable-diffusion-webui/models/Stable-diffusion -o [萌二次元]131-half.safetensors")
149
+ if not os.path.exists(f'{install_path}/{rename_repo}'):
150
+ print(f'在克隆 https://{git_url}/{webui_repo} 时出错')
151
+ exit()
152
+
153
+ download_extensions(extensions)
154
+
155
+ model_download(sd_models, 'models/Stable-diffusion')
156
+ model_download(lora_models, 'models/Lora')
157
+ model_download(vae_models, 'models/VAE')
158
+ if ControlNet:
159
+ model_download(controlnet_models, 'extensions/sd-webui-controlnet/models')
160
+ model_download(hypernetwork_models, 'models/hypernetworks')
161
+ model_download(embedding_models, 'embeddings')
162
+ model_download(esrgan_models, 'models/ESRGAN')
163
+
164
+ os.chdir(f"{install_path}/{rename_repo}")
165
+ package_envs = [
166
+ {"env": "STABLE_DIFFUSION_REPO", "url": os.environ.get('STABLE_DIFFUSION_REPO', "https://gitcode.net/overbill1683/stablediffusion")},
167
+ {"env": "STABLE_DIFFUSION_XL_REPO", "url": os.environ.get('STABLE_DIFFUSION_XL_REPO', "https://gitcode.net/overbill1683/generative-models")},
168
+ {"env": "K_DIFFUSION_REPO", "url": os.environ.get('K_DIFFUSION_REPO', "https://gitcode.net/overbill1683/k-diffusion")},
169
+ {"env": "CODEFORMER_REPO", "url": os.environ.get('CODEFORMER_REPO', "https://gitcode.net/overbill1683/CodeFormer")},
170
+ {"env": "BLIP_REPO", "url": os.environ.get('BLIP_REPO', "https://gitcode.net/overbill1683/BLIP")},
171
+ ]
172
+ os.environ["PIP_INDEX_URL"] = "https://mirrors.aliyun.com/pypi/simple/"
173
+ for i in package_envs:
174
+ os.environ[i["env"]] = i["url"]
175
+
176
+ os.chdir(install_path)
177
+ for custom_command in custom_commands:
178
+ os.system(custom_command)
179
+
180
+ os.chdir(f"{install_path}/{rename_repo}")
181
+ os.system(f"python launch.py {' '.join(webui_args)} --port {webui_port}")
182
+
183
+ # 实例保活
184
+ import time
185
+
186
+ def session_saver():
187
+ try:
188
+ import cupy as cp
189
+ except ImportError:
190
+ print("cupy模块未安装,正在安装...")
191
+ try:
192
+ import pip
193
+ pip.main(['install', 'cupy'])
194
+ import cupy as cp
195
+ except ImportError:
196
+ print("无法安装模块,请确保已正确安装pip。")
197
+ return
198
+
199
+ while True:
200
+ for _ in range(1):
201
+ matrix_a = cp.random.rand(2000, 2000)
202
+ matrix_b = cp.random.rand(2000, 2000)
203
+ result = cp.dot(matrix_a, matrix_b)
204
+ print("实例保活:", result)
205
+ del matrix_a, matrix_b, result
206
+ cp.cuda.Stream.null.synchronize()
207
+ time.sleep(600)
208
+
209
+ # 启动
210
+ import threading
211
+
212
+ def run():
213
+ webui = threading.Thread(target=run_webui)
214
+ saver = threading.Thread(target=session_saver)
215
+
216
+ webui.start()
217
+ saver.start()