Rename app1 (1).py to app2.py
Browse files- app1 (1).py → app2.py +132 -9
app1 (1).py → app2.py
RENAMED
@@ -1,13 +1,55 @@
|
|
1 |
import os
|
2 |
# import wandb
|
|
|
3 |
os.chdir(f"/home/xlab-app-center")
|
4 |
-
os.system(f"git clone https://openi.pcl.ac.cn/2575044704/
|
5 |
os.system(f"cp /home/xlab-app-center/styles.csv /home/xlab-app-center/stable-diffusion-webui/styles.csv")
|
6 |
os.chdir(f"/home/xlab-app-center/stable-diffusion-webui")
|
7 |
os.system(f"git lfs install")
|
8 |
os.system(f"git reset --hard")
|
9 |
os.chdir(f"/home/xlab-app-center/stable-diffusion-webui/extensions")
|
|
|
|
|
|
|
|
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
plugins = [
|
12 |
"https://gitcode.net/overbill1683/stable-diffusion-webui-localization-zh_Hans",
|
13 |
"https://gitcode.net/ranting8323/multidiffusion-upscaler-for-automatic1111",
|
@@ -17,7 +59,14 @@ plugins = [
|
|
17 |
"https://gitcode.net/ranting8323/a1111-sd-webui-tagcomplete",
|
18 |
"https://gitcode.net/nightaway/sd-webui-infinite-image-browsing",
|
19 |
"https://openi.pcl.ac.cn/2575044704/sd-extension-system-info",
|
20 |
-
"https://openi.pcl.ac.cn/2575044704/batchlinks-webui"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
]
|
22 |
|
23 |
for plugin in plugins:
|
@@ -26,7 +75,7 @@ os.makedirs('/home/xlab-app-center/stable-diffusion-webui/models/adetailer', exi
|
|
26 |
os.chdir(f"/home/xlab-app-center/stable-diffusion-webui/models/adetailer")
|
27 |
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")
|
28 |
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")
|
29 |
-
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")
|
30 |
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")
|
31 |
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")
|
32 |
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")
|
@@ -53,7 +102,75 @@ import wandb
|
|
53 |
import os
|
54 |
import time
|
55 |
import wandb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
# WandB登录
|
58 |
os.system('wandb login 5c00964de1bb95ec1ab24869d4c523c59e0fb8e3')
|
59 |
|
@@ -67,20 +184,26 @@ import time
|
|
67 |
def wandb():
|
68 |
# Assuming you have initialized WandB before this function call
|
69 |
# ...
|
70 |
-
|
|
|
|
|
|
|
|
|
71 |
while True:
|
72 |
# Loop to continuously monitor GPU temperature and usage
|
73 |
gpu_temperature_command = "nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits"
|
74 |
gpu_temperature = int(os.popen(gpu_temperature_command).read().strip())
|
75 |
-
gpu_usage_command = "nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits"
|
76 |
-
gpu_usage = int(os.popen(gpu_usage_command).read().strip())
|
77 |
|
78 |
-
wandb.log({"GPU 温度": gpu_temperature
|
79 |
time.sleep(60)
|
80 |
|
81 |
def start():
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
84 |
# Create threads for each function
|
85 |
wandb_thread = threading.Thread(target=wandb)
|
86 |
start_thread = threading.Thread(target=start)
|
|
|
1 |
import os
|
2 |
# import wandb
|
3 |
+
os.system("pip install nvidia-ml-py3")
|
4 |
os.chdir(f"/home/xlab-app-center")
|
5 |
+
os.system(f"git clone https://openi.pcl.ac.cn/2575044704/sd-v1.7.0 /home/xlab-app-center/stable-diffusion-webui")
|
6 |
os.system(f"cp /home/xlab-app-center/styles.csv /home/xlab-app-center/stable-diffusion-webui/styles.csv")
|
7 |
os.chdir(f"/home/xlab-app-center/stable-diffusion-webui")
|
8 |
os.system(f"git lfs install")
|
9 |
os.system(f"git reset --hard")
|
10 |
os.chdir(f"/home/xlab-app-center/stable-diffusion-webui/extensions")
|
11 |
+
show_shell_info = False
|
12 |
+
def run(command, cwd=None, desc=None, errdesc=None, custom_env=None,try_error:bool=True) -> str:
|
13 |
+
global show_shell_info
|
14 |
+
if desc is not None:
|
15 |
+
print(desc)
|
16 |
|
17 |
+
run_kwargs = {
|
18 |
+
"args": command,
|
19 |
+
"shell": True,
|
20 |
+
"cwd": cwd,
|
21 |
+
"env": os.environ if custom_env is None else custom_env,
|
22 |
+
"encoding": 'utf8',
|
23 |
+
"errors": 'ignore',
|
24 |
+
}
|
25 |
+
|
26 |
+
if not show_shell_info:
|
27 |
+
run_kwargs["stdout"] = run_kwargs["stderr"] = subprocess.PIPE
|
28 |
+
|
29 |
+
result = subprocess.run(**run_kwargs)
|
30 |
+
|
31 |
+
if result.returncode != 0:
|
32 |
+
error_bits = [
|
33 |
+
f"{errdesc or 'Error running command'}.",
|
34 |
+
f"Command: {command}",
|
35 |
+
f"Error code: {result.returncode}",
|
36 |
+
]
|
37 |
+
if result.stdout:
|
38 |
+
error_bits.append(f"stdout: {result.stdout}")
|
39 |
+
if result.stderr:
|
40 |
+
error_bits.append(f"stderr: {result.stderr}")
|
41 |
+
if try_error:
|
42 |
+
print((RuntimeError("\n".join(error_bits))))
|
43 |
+
else:
|
44 |
+
raise RuntimeError("\n".join(error_bits))
|
45 |
+
|
46 |
+
if show_shell_info:
|
47 |
+
print((result.stdout or ""))
|
48 |
+
return (result.stdout or "")
|
49 |
+
|
50 |
+
def mkdirs(path, exist_ok=True):
|
51 |
+
if path and not Path(path).exists():
|
52 |
+
os.makedirs(path,exist_ok=exist_ok)
|
53 |
plugins = [
|
54 |
"https://gitcode.net/overbill1683/stable-diffusion-webui-localization-zh_Hans",
|
55 |
"https://gitcode.net/ranting8323/multidiffusion-upscaler-for-automatic1111",
|
|
|
59 |
"https://gitcode.net/ranting8323/a1111-sd-webui-tagcomplete",
|
60 |
"https://gitcode.net/nightaway/sd-webui-infinite-image-browsing",
|
61 |
"https://openi.pcl.ac.cn/2575044704/sd-extension-system-info",
|
62 |
+
"https://openi.pcl.ac.cn/2575044704/batchlinks-webui",
|
63 |
+
'https://openi.pcl.ac.cn/2575044704/stable-diffusion-webui-localization-zh_CN',
|
64 |
+
'https://openi.pcl.ac.cn/2575044704/sd-webui-supermerger',
|
65 |
+
"https://openi.pcl.ac.cn/2575044704/sd-webui-supermerger",
|
66 |
+
'https://openi.pcl.ac.cn/2575044704/sd-webui-lora-block-weight',
|
67 |
+
'https://openi.pcl.ac.cn/2575044704/sd-skin-extension',
|
68 |
+
|
69 |
+
|
70 |
]
|
71 |
|
72 |
for plugin in plugins:
|
|
|
75 |
os.chdir(f"/home/xlab-app-center/stable-diffusion-webui/models/adetailer")
|
76 |
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")
|
77 |
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")
|
78 |
+
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")
|
79 |
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")
|
80 |
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")
|
81 |
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")
|
|
|
102 |
import os
|
103 |
import time
|
104 |
import wandb
|
105 |
+
proxy_path={
|
106 |
+
'/sd2/':'http://127.0.0.1:7862/',
|
107 |
+
'/sd3/':'http://127.0.0.1:7863/'
|
108 |
+
} # 增加一个comfyui的代理
|
109 |
+
server_port=7860 # webui 默认端口
|
110 |
+
_server_port = locals().get('server_port') or globals().get('server_port') or 7860
|
111 |
+
|
112 |
|
113 |
+
_proxy_path = locals().get('proxy_path') or globals().get('proxy_path') or {}
|
114 |
+
# nginx 反向代理配置文件
|
115 |
+
def echoToFile(content:str,path:str):
|
116 |
+
if path.find('/') >= 0:
|
117 |
+
_path = '/'.join(path.split('/')[:-1])
|
118 |
+
run(f'''mkdir -p {_path}''')
|
119 |
+
with open(path,'w') as sh:
|
120 |
+
sh.write(content)
|
121 |
+
# 检查网络
|
122 |
+
def check_service(host, port):
|
123 |
+
try:
|
124 |
+
socket.create_connection((host, port), timeout=5)
|
125 |
+
return True
|
126 |
+
except socket.error:
|
127 |
+
return False
|
128 |
+
def localProxy():
|
129 |
+
os.system('apt install nginx -y')
|
130 |
+
|
131 |
+
_proxy_path['/'] = f'http://127.0.0.1:{_server_port+1}/'
|
132 |
+
_proxy_path['/1/'] = f'http://127.0.0.1:{_server_port+2}/'
|
133 |
+
|
134 |
+
def getProxyLocation(subPath:str, localServer:str):
|
135 |
+
return '''
|
136 |
+
location '''+ subPath +'''
|
137 |
+
{
|
138 |
+
proxy_pass '''+ localServer +''';
|
139 |
+
proxy_set_header Host $host;
|
140 |
+
proxy_set_header X-Real-IP $remote_addr;
|
141 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
142 |
+
proxy_set_header REMOTE-HOST $remote_addr;
|
143 |
+
proxy_set_header Upgrade $http_upgrade;
|
144 |
+
proxy_set_header Connection upgrade;
|
145 |
+
proxy_http_version 1.1;
|
146 |
+
proxy_connect_timeout 10m;
|
147 |
+
proxy_read_timeout 10m;
|
148 |
+
}
|
149 |
+
|
150 |
+
'''
|
151 |
+
|
152 |
+
conf = '''
|
153 |
+
server
|
154 |
+
{
|
155 |
+
listen '''+str(_server_port)+''';
|
156 |
+
listen [::]:'''+str(_server_port)+''';
|
157 |
+
server_name 127.0.0.1 localhost 0.0.0.0 "";
|
158 |
+
|
159 |
+
if ($request_method = OPTIONS) {
|
160 |
+
return 200;
|
161 |
+
}
|
162 |
+
fastcgi_send_timeout 10m;
|
163 |
+
fastcgi_read_timeout 10m;
|
164 |
+
fastcgi_connect_timeout 10m;
|
165 |
+
|
166 |
+
'''+ ''.join([getProxyLocation(key,_proxy_path[key]) for key in _proxy_path.keys()]) +'''
|
167 |
+
}
|
168 |
+
'''
|
169 |
+
echoToFile(conf,'/etc/nginx/conf.d/proxy_nginx.conf')
|
170 |
+
if not check_service('localhost',_server_port):
|
171 |
+
run(f'''nginx -c /etc/nginx/nginx.conf''')
|
172 |
+
run(f'''nginx -s reload''')
|
173 |
+
|
174 |
# WandB登录
|
175 |
os.system('wandb login 5c00964de1bb95ec1ab24869d4c523c59e0fb8e3')
|
176 |
|
|
|
184 |
def wandb():
|
185 |
# Assuming you have initialized WandB before this function call
|
186 |
# ...
|
187 |
+
try:
|
188 |
+
localProxy()
|
189 |
+
except Exception as e:
|
190 |
+
# 在这里处理异常的代码
|
191 |
+
print(f"An error occurred: {e}")
|
192 |
while True:
|
193 |
# Loop to continuously monitor GPU temperature and usage
|
194 |
gpu_temperature_command = "nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits"
|
195 |
gpu_temperature = int(os.popen(gpu_temperature_command).read().strip())
|
|
|
|
|
196 |
|
197 |
+
wandb.log({"GPU 温度": gpu_temperature})
|
198 |
time.sleep(60)
|
199 |
|
200 |
def start():
|
201 |
+
try:
|
202 |
+
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")
|
203 |
+
os.system(f"python launch.py --api --xformers --enable-insecure-extension-access --gradio-queue --disable-safe-unpickle & python launch.py --api --xformers --enable-insecure-extension-access --gradio-queue --disable-safe-unpickle --port=7862 & python launch.py --api --xformers --enable-insecure-extension-access --gradio-queue --disable-safe-unpickle --port=7863")
|
204 |
+
except Exception as e:
|
205 |
+
# 在这里处理异常的代码
|
206 |
+
print(f"An error occurred: {e}")
|
207 |
# Create threads for each function
|
208 |
wandb_thread = threading.Thread(target=wandb)
|
209 |
start_thread = threading.Thread(target=start)
|