ACCA225 commited on
Commit
19492e7
1 Parent(s): 01fa7a6

Upload app3.py

Browse files
Files changed (1) hide show
  1. app3.py +291 -0
app3.py ADDED
@@ -0,0 +1,291 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 给我的朋友写的
2
+ import os
3
+ import threading
4
+ #使用的库
5
+ os.system("mkdir -p /home/xlab-app-center")
6
+ from pathlib import Path
7
+ import subprocess
8
+ import pandas as pd
9
+ import shutil
10
+ import os
11
+ import time
12
+ import re
13
+ import gc
14
+ import requests
15
+ import zipfile
16
+ import threading
17
+ import time
18
+ import socket
19
+ from concurrent.futures import ProcessPoolExecutor
20
+ # import wandb
21
+ os.system("pip install nvidia-ml-py3")
22
+ os.chdir(f"/home/xlab-app-center")
23
+ os.system(f"git clone https://openi.pcl.ac.cn/2575044704/stab /home/xlab-app-center/stable-diffusion-webui")
24
+
25
+ os.system(f"cp /home/xlab-app-center/styles.csv /home/xlab-app-center/stable-diffusion-webui/styles.csv")
26
+ os.chdir(f"/home/xlab-app-center/stable-diffusion-webui")
27
+ os.system(f"git lfs install")
28
+ os.system(f"git reset --hard")
29
+ import os
30
+
31
+ def remove_restart():
32
+ os.chdir("/home/xlab-app-center/stable-diffusion-webui/html")
33
+ os.system("rm ./footer.html && wget -O footer.html https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/footer.html")
34
+ os.chdir("/home/xlab-app-center/stable-diffusion-webui/modules")
35
+ os.system("rm ./ui_settings.py && wget -O ui_settings.py https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/ui_settings.py ")
36
+ remove_restart()
37
+ def create_directory(directory_path):
38
+ if not os.path.exists(directory_path):
39
+ os.makedirs(directory_path)
40
+
41
+ def download_file(url, destination_path):
42
+ os.system(f'wget -O {destination_path} {url}')
43
+
44
+ # 设置基本路径
45
+ base_directory = '/home/xlab-app-center/stable-diffusion-webui'
46
+ configs_directory = os.path.join(base_directory, 'configs')
47
+
48
+ # 创建configs文件夹
49
+ create_directory(configs_directory)
50
+
51
+ # 下载配置文件
52
+ #download_file('https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/config-pub.json', os.path.join(configs_directory, 'config.json'))
53
+ #download_file('https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/ui-config-pri2.json', os.path.join(configs_directory, 'ui-config-pri.json'))
54
+ #download_file('https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/ui-config-pub.json', os.path.join(configs_directory, 'ui-config.json'))
55
+ # 下载配置文件
56
+ download_file('https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/config-pub.json', os.path.join(base_directory, 'config.json'))
57
+ download_file('https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/ui-config-pri2.json', os.path.join(base_directory, 'ui-config-pri.json'))
58
+ download_file('https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/ui-config-pub.json', os.path.join(base_directory, 'ui-config.json'))
59
+
60
+ os.chdir(f"/home/xlab-app-center/stable-diffusion-webui/extensions")
61
+ os.system(f"rm -rf ./batchlinks-webui")
62
+ os.system(f"rm -rf ./sd-extension-system-info")
63
+ show_shell_info = False
64
+ def run(command, cwd=None, desc=None, errdesc=None, custom_env=None,try_error:bool=True) -> str:
65
+ global show_shell_info
66
+ if desc is not None:
67
+ print(desc)
68
+
69
+ run_kwargs = {
70
+ "args": command,
71
+ "shell": True,
72
+ "cwd": cwd,
73
+ "env": os.environ if custom_env is None else custom_env,
74
+ "encoding": 'utf8',
75
+ "errors": 'ignore',
76
+ }
77
+
78
+ if not show_shell_info:
79
+ run_kwargs["stdout"] = run_kwargs["stderr"] = subprocess.PIPE
80
+
81
+ result = subprocess.run(**run_kwargs)
82
+
83
+ if result.returncode != 0:
84
+ error_bits = [
85
+ f"{errdesc or 'Error running command'}.",
86
+ f"Command: {command}",
87
+ f"Error code: {result.returncode}",
88
+ ]
89
+ if result.stdout:
90
+ error_bits.append(f"stdout: {result.stdout}")
91
+ if result.stderr:
92
+ error_bits.append(f"stderr: {result.stderr}")
93
+ if try_error:
94
+ print((RuntimeError("\n".join(error_bits))))
95
+ else:
96
+ raise RuntimeError("\n".join(error_bits))
97
+
98
+ if show_shell_info:
99
+ print((result.stdout or ""))
100
+ return (result.stdout or "")
101
+ import subprocess
102
+ def sdmodel():
103
+ def download_with_aria2(urls):
104
+ # 使用循环遍历所有的下载链接
105
+ for url in urls:
106
+ # 将huggingface.co替换为hf-mirror.com
107
+ url = url.replace('huggingface.co', 'hf-mirror.com')
108
+ file_name = url.split('/')[-1].split('?')[0]
109
+ # 构建aria2c命令
110
+ command = f'aria2c -x 16 -s 16 -c -k 1M -o "{file_name}" "{url}" -d /home/xlab-app-center/stable-diffusion-webui/models/Stable-diffusion'
111
+
112
+ try:
113
+ # 使用subprocess模块运行aria2c命令
114
+ subprocess.run(command, shell=True, check=True)
115
+ except subprocess.CalledProcessError as e:
116
+ # 打印错误信息(如果有)
117
+ print(f'Error downloading {url}: {e}')
118
+
119
+ # 直接将链接作为多行字符串传递给函数
120
+ download_urls = """
121
+ https://huggingface.co/HiroHiroHirook/meinamix_meinaV8/resolve/main/meinamix_meinaV8.safetensors?download=true
122
+ https://huggingface.co/datasets/ACCA225/kagglemodel/resolve/main/kaggle/temp/anything_v50.safetensors?download=true
123
+ https://huggingface.co/datasets/ACCA225/kagglemodel/resolve/main/kaggle/temp/blindbox_v1_mix.safetensors?download=true
124
+ https://huggingface.co/datasets/ACCA225/kagglemodel/resolve/main/kaggle/temp/cuteyukimixAdorable_naiV3style.safetensors?download=true
125
+ https://huggingface.co/datasets/ACCA225/kagglemodel/resolve/main/kaggle/temp/ddicon_v10.ckpt?download=true
126
+ https://huggingface.co/datasets/ACCA225/kagglemodel/resolve/main/kaggle/temp/meinamix_meinaV11.safetensors?download=true
127
+ https://huggingface.co/datasets/ACCA225/kagglemodel/resolve/main/kaggle/temp/meinapastel_v6-inpainting.safetensors?download=true
128
+ https://huggingface.co/datasets/ACCA225/kagglemodel/resolve/main/kaggle/temp/meinapastel_v6Pastel.safetensors?download=true
129
+ https://huggingface.co/datasets/ACCA225/kagglemodel/resolve/main/kaggle/temp/midjourney_20230624181825.safetensors?download=true
130
+ https://huggingface.co/datasets/ACCA225/kagglemodel/resolve/main/kaggle/temp/mixProV4_v4.safetensors?download=true
131
+ https://huggingface.co/datasets/ACCA225/kagglemodel/resolve/main/kaggle/temp/qteamixQ_omegaFp16.safetensors?download=true
132
+ https://huggingface.co/datasets/ACCA225/kagglemodel/resolve/main/kaggle/temp/uberRealisticPornMerge_urpmv13.safetensors?download=true
133
+ https://huggingface.co/datasets/ACCA225/kagglemodel/resolve/main/kaggle/temp/velaMix_velaMixVersion2.safetensors?download=true
134
+ """
135
+
136
+ # 使用字符串的splitlines方法将字符串分割成列表
137
+ urls_list = download_urls.strip().splitlines()
138
+
139
+ # 调用函数开始下载
140
+ download_with_aria2(urls_list)
141
+ #sdmodel()
142
+ def mkdirs(path, exist_ok=True):
143
+ if path and not Path(path).exists():
144
+ os.makedirs(path,exist_ok=exist_ok)
145
+ plugins = [
146
+ "https://gitcode.net/overbill1683/stable-diffusion-webui-localization-zh_Hans",
147
+ "https://gitcode.net/ranting8323/multidiffusion-upscaler-for-automatic1111",
148
+ "https://gitcode.net/ranting8323/adetailer",
149
+ "https://gitcode.net/ranting8323/sd-webui-inpaint-anything",
150
+ "https://gitcode.net/ranting8323/a1111-sd-webui-tagcomplete",
151
+ "https://gitcode.net/nightaway/sd-webui-infinite-image-browsing",
152
+ "https://openi.pcl.ac.cn/2575044704/sd-extension-system-info",
153
+ "https://openi.pcl.ac.cn/2575044704/batchlinks-webui",
154
+ 'https://openi.pcl.ac.cn/2575044704/stable-diffusion-webui-localization-zh_CN',
155
+ 'https://openi.pcl.ac.cn/2575044704/sd-webui-lora-block-weight',
156
+ 'https://openi.pcl.ac.cn/2575044704/sd-skin-extension',
157
+ "https://kkgithub.com/thygate/stable-diffusion-webui-depthmap-script.git",
158
+ "https://gitcode.net/ranting8323/sd-webui-prompt-all-in-one",
159
+ "https://gitcode.net/ranting8323/sd-webui-controlnet",
160
+ "https://kkgithub.com/SignalFlagZ/sd-webui-civbrowser.git",
161
+ "https://kkgithub.com/continue-revolution/sd-webui-animatediff.git",
162
+ "https://kkkkgithub.com/aigc-apps/sd-webui-EasyPhoto.git",
163
+ "https://kkgithub.com/Iyashinouta/sd-model-downloader.git",
164
+ "https://kkgithub.com/fkunn1326/openpose-editor.git",
165
+ "https://kkgithub.com/zero01101/openOutpaint-webUI-extension.git",
166
+ "https://kkgithub.com/LonicaMewinsky/gif2gif.git",
167
+ "https://kkgithub.com/modelscope/facechain.git",
168
+ "https://openi.pcl.ac.cn/2575044704/Kohaku-NAI"
169
+ ]
170
+
171
+ for plugin in plugins:
172
+ os.system(f"git clone {plugin}")
173
+ os.makedirs('/home/xlab-app-center/stable-diffusion-webui/models/adetailer', exist_ok=True)
174
+ os.chdir(f"/home/xlab-app-center/stable-diffusion-webui/models/adetailer")
175
+ os.system(f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hf-mirror.com/Bingsu/adetailer/resolve/main/hand_yolov8s.pt -d /home/xlab-app-center/stable-diffusion-webui/models/adetailer -o hand_yolov8s.pt")
176
+ os.system(f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hf-mirror.com/Bingsu/adetailer/resolve/main/hand_yolov8n.pt -d /home/xlab-app-center/stable-diffusion-webui/models/adetailer -o hand_yolov8n.pt")
177
+ 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")
178
+ os.system(f"rm /home/xlab-app-center/stable-diffusion-webui/models/Stable-diffusion/*porn*.safetensors")
179
+ 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/ba.safetensors -d /home/xlab-app-center/stable-diffusion-webui/models/Lora -o ba.safetensors")
180
+ 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/racaco2.safetensors -d /home/xlab-app-center/stable-diffusion-webui/models/Lora -o racaco2.safetensors")
181
+ os.system(f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hf-mirror.com/coinz/Add-detail/resolve/main/add_detail.safetensors -d /home/xlab-app-center/stable-diffusion-webui/models/Lora -o add_detail.safetensors")
182
+ os.system(f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hf-mirror.com/datasets/VASVASVAS/vae/resolve/main/pastel-waifu-diffusion.vae.pt -d /home/xlab-app-center/stable-diffusion-webui/models/VAE -o pastel-waifu-diffusion.vae.pt")
183
+ # os.system(f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://download.openxlab.org.cn/models/camenduru/sdxl-refiner-1.0/weight//sd_xl_refiner_1.0.safetensors -d /home/xlab-app-center/stable-diffusion-webui/models/Stable-diffusion -o sd_xl_refiner_1.0.safetensors")
184
+ # os.system(f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://download.openxlab.org.cn/models/camenduru/cyber-realistic/weight//cyberrealistic_v32.safetensors -d /home/xlab-app-center/stable-diffusion-webui/models/Stable-diffusion -o cyberrealistic_v32.safetensors")
185
+ os.chdir(f"/home/xlab-app-center/stable-diffusion-webui")
186
+ print('webui launching...')
187
+ package_envs = [
188
+ {"env": "STABLE_DIFFUSION_REPO", "url": os.environ.get('STABLE_DIFFUSION_REPO', "https://gitcode.net/overbill1683/stablediffusion")},
189
+ {"env": "STABLE_DIFFUSION_XL_REPO", "url": os.environ.get('STABLE_DIFFUSION_XL_REPO', "https://gitcode.net/overbill1683/generative-models")},
190
+ {"env": "K_DIFFUSION_REPO", "url": os.environ.get('K_DIFFUSION_REPO', "https://gitcode.net/overbill1683/k-diffusion")},
191
+ {"env": "CODEFORMER_REPO", "url": os.environ.get('CODEFORMER_REPO', "https://gitcode.net/overbill1683/CodeFormer")},
192
+ {"env": "BLIP_REPO", "url": os.environ.get('BLIP_REPO', "https://gitcode.net/overbill1683/BLIP")},
193
+ ]
194
+ os.environ["PIP_INDEX_URL"] = "https://mirrors.aliyun.com/pypi/simple/"
195
+ for i in package_envs:
196
+ os.environ[i["env"]] = i["url"]
197
+
198
+ import os
199
+ import time
200
+ import wandb
201
+ import nvidia_smi
202
+ import os
203
+ import time
204
+ import wandb
205
+
206
+ # nginx 反向代理配置文件
207
+ def echoToFile(content:str,path:str):
208
+ if path.find('/') >= 0:
209
+ _path = '/'.join(path.split('/')[:-1])
210
+ run(f'''mkdir -p {_path}''')
211
+ with open(path,'w') as sh:
212
+ sh.write(content)
213
+ # 检查网络
214
+ def check_service(host, port):
215
+ try:
216
+ socket.create_connection((host, port), timeout=5)
217
+ return True
218
+ except socket.error:
219
+ return False
220
+ def localProxy():
221
+ os.system('sudo apt install nginx -y')
222
+ download_file('https://huggingface.co/datasets/ACCA225/openxlab/resolve/main/proxy_nginx.conf', os.path.join(base_directory, 'proxy_nginx.conf'))
223
+ if not check_service('localhost',_server_port):
224
+ run(f'''nginx -c /home/xlab-app-center/stable-diffusion-webui/proxy_nginx.conf''')
225
+ run(f'''nginx -s reload''')
226
+
227
+ # WandB登录
228
+ os.system('wandb login 5c00964de1bb95ec1ab24869d4c523c59e0fb8e3')
229
+ # 初始化WandB项目
230
+ wandb.init(project="gpu-temperature-monitor")
231
+
232
+ import os
233
+ import threading
234
+ import wandb
235
+ import time
236
+ def monitor_gpu():
237
+ start_thread = threading.Thread(target=start)
238
+ start_thread.start()
239
+ while True:
240
+ try:
241
+ gpu_temperature = "100"
242
+ wandb.log({"GPU 温度": gpu_temperature})
243
+
244
+ except Exception as e:
245
+ print(f"Error: {e}")
246
+
247
+ time.sleep(60)
248
+ def zrok():
249
+
250
+ #os.system("wget https://hf-mirror.com/datasets/ACCA225/frp-1/resolve/main/frpc")
251
+ #os.system("chmod +x ./frpc")
252
+ #os.system("./frpc -f bsnehoeds17ett71i2cr79ujoa7ndkxz:13738352 & ./frpc -f bsnehoeds17ett71i2cr79ujoa7ndkxz:13738353")
253
+ pass
254
+ def start():
255
+ #os.system("pip install pyngrok")
256
+ #try:
257
+ # print('启动proxy')
258
+ # threading.Thread(target = localProxy,daemon=True).start()
259
+ #except Exception as e:
260
+ # # 在这里处理异常的代码
261
+ # print(f"proxy An error occurred: {e}")
262
+ try:
263
+ #安装环境
264
+ os.system(f"python launch.py --skip-torch-cuda-test --use-cpu=True --no-half --api --exit --enable-insecure-extension-access --gradio-queue --disable-safe-unpickle")
265
+ #time.sleep(5)
266
+
267
+ command = "python launch.py --skip-torch-cuda-test --use-cpu=True --no-half --api --enable-insecure-extension-access --gradio-queue --disable-safe-unpickle"
268
+ command1 = "python launch.py --api --xformers --enable-insecure-extension-access --gradio-queue --disable-safe-unpickle --port=7862 --ngrok=2bgXLjjKFvxfbuZFlR2NMZkvL8n_4WrK7f15FLtWb8p7v3oaF"
269
+ command2 = "python launch.py --api --xformers --enable-insecure-extension-access --gradio-queue --disable-safe-unpickle --port=7863 --ngrok=2CXyNlT9xGfFoL5ruI6hQV20FNq_7tbmuzS9RtyNTkyEe1J6C"
270
+ process = subprocess.Popen(command, shell=True)
271
+ time.sleep(250)
272
+ #process = subprocess.Popen(command1, shell=True)
273
+ time.sleep(100)
274
+ #print("启动ngrok中")
275
+ #os.system(f"{command2}")
276
+ except Exception as e:
277
+ # 在这里处理异常的代码
278
+ print(f"启动SD发生错误: {e}")
279
+ try:
280
+ #os.system(f"python launch.py --api --xformers --exit --enable-insecure-extension-access --ui-settings-file /home/xlab-app-center/config.json --ui-config-file /home/xlab-app-center/ui-config.json --gradio-queue --disable-safe-unpickle")
281
+ os.system(f"python launch.py --api --xformers --enable-insecure-extension-access --gradio-queue --disable-safe-unpickle")
282
+ except Exception as e:
283
+ # 在这里处理异常的代码
284
+ print(f"An error occurred: {e}")
285
+
286
+
287
+ net_thread = threading.Thread(target=zrok)
288
+
289
+ net_thread.start()
290
+
291
+ monitor_gpu()