Upload 14 files
Browse files- 1.py +2 -0
- app.py +180 -0
- here.py +121 -0
- models.py +3 -0
- proxy_nginx.conf +70 -0
- sd2.ipynb +238 -0
- sel.py +249 -0
- selenium_example.py +229 -0
- shutdown.sh +18 -0
- the_flask.py +48 -0
- the_flask2.py +62 -0
- the_flask_ngrok.py +19 -0
- train.py +3 -0
- webui.py +171 -0
1.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.system("python /tmp/code/sd2/here.py && echo success")
|
app.py
ADDED
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
import httpx
|
3 |
+
import os
|
4 |
+
|
5 |
+
import threading
|
6 |
+
#使用的库
|
7 |
+
os.system("pip install nvidia-ml-py3 wandb")
|
8 |
+
#print("替换webui.py")
|
9 |
+
#webpy()
|
10 |
+
import os
|
11 |
+
|
12 |
+
def create_symlinks(folder_paths, target_dir):
|
13 |
+
print('链接模型中')
|
14 |
+
# Create target directory if it doesn't exist
|
15 |
+
if not os.path.exists(target_dir):
|
16 |
+
os.makedirs(target_dir)
|
17 |
+
# Remove broken symlinks in target directory
|
18 |
+
for filename in os.listdir(target_dir):
|
19 |
+
target_path = os.path.join(target_dir, filename)
|
20 |
+
if os.path.islink(target_path) and not os.path.exists(target_path):
|
21 |
+
os.unlink(target_path)
|
22 |
+
# Create new symlinks
|
23 |
+
for source_path in folder_paths:
|
24 |
+
if not os.path.exists(source_path):
|
25 |
+
continue
|
26 |
+
if os.path.isdir(source_path):
|
27 |
+
for filename in os.listdir(source_path):
|
28 |
+
source_file_path = os.path.join(source_path, filename)
|
29 |
+
target_file_path = os.path.join(target_dir, filename)
|
30 |
+
if not os.path.exists(target_file_path):
|
31 |
+
os.symlink(source_file_path, target_file_path)
|
32 |
+
print(f'Created symlink for {filename} in {target_dir}')
|
33 |
+
else:
|
34 |
+
print(f'Symlink for {filename} already exists in {target_dir}')
|
35 |
+
else:
|
36 |
+
filename = os.path.basename(source_path)
|
37 |
+
target_file_path = os.path.join(target_dir, filename)
|
38 |
+
if not os.path.exists(target_file_path):
|
39 |
+
os.symlink(source_path, target_file_path)
|
40 |
+
print(f'Created symlink for {filename} in {target_dir}')
|
41 |
+
else:
|
42 |
+
print(f'Symlink for {filename} already exists in {target_dir}')
|
43 |
+
print('链接成功')
|
44 |
+
|
45 |
+
# Example usage:
|
46 |
+
source_folders = ['/pretrainmodel']
|
47 |
+
target_directory = '/sd/models/Stable-diffusion'
|
48 |
+
create_symlinks(source_folders, target_directory)
|
49 |
+
|
50 |
+
from pathlib import Path
|
51 |
+
import subprocess
|
52 |
+
import pandas as pd
|
53 |
+
import shutil
|
54 |
+
import os
|
55 |
+
import time
|
56 |
+
import re
|
57 |
+
import gc
|
58 |
+
import requests
|
59 |
+
import zipfile
|
60 |
+
import threading
|
61 |
+
import time
|
62 |
+
import socket
|
63 |
+
from concurrent.futures import ProcessPoolExecutor
|
64 |
+
import wandb
|
65 |
+
import base64
|
66 |
+
import os
|
67 |
+
import time
|
68 |
+
import wandb
|
69 |
+
import nvidia_smi
|
70 |
+
import os
|
71 |
+
import time
|
72 |
+
import wandb
|
73 |
+
#把ngrok填在这里
|
74 |
+
ngrok_token = "2bgnVJhlLqxUZhS1WyeaAtQA12F_6nQXrapUved4QSxYFn1cD"#'2YypH9d2VXVL78HxF7g0lintH17_2GbtkFNFFngUkTZcyQ4SD'
|
75 |
+
edge = "edghts_2cUdHbbxvMVOXsl0krDIc1SBv58"
|
76 |
+
import os
|
77 |
+
|
78 |
+
import subprocess
|
79 |
+
import time
|
80 |
+
|
81 |
+
import os
|
82 |
+
print("你的数据集文件:")
|
83 |
+
os.system("ls /tmp/dataset")
|
84 |
+
process = subprocess.Popen(["cp", "-r", "/tmp/dataset", "/sd/models/Stable-diffusion"])
|
85 |
+
# 获取 OPENI_GRADIO_URL 环境变量的值
|
86 |
+
url = os.getenv('OPENI_GRADIO_URL')
|
87 |
+
|
88 |
+
# 打印 url 的值
|
89 |
+
print("你的URL是:", url)
|
90 |
+
os.system(f"/usr/local/bin/python /usr/local/bin/jupyter-lab --ServerApp.shutdown_no_activity_timeout=1800 --TerminalManager.cull_inactive_timeout=1800 --TerminalManager.cull_interval=300 --MappingKernelManager.cull_idle_timeout=1800 --MappingKernelManager.cull_interval=300 --MappingKernelManager.cull_connected=True --MappingKernelManager.cull_busy=True --no-browser --ip=0.0.0.0 --allow-root --notebook-dir=/ --port=7860 --LabApp.token= --LabApp.allow_origin=* --LabApp.base_url={url}")
|
91 |
+
|
92 |
+
#os.system(f"ngrok tunnel --label edge={edge} --authtoken={ngrok_token} --region=ap http://localhost:7860 & /usr/local/bin/python /usr/local/bin/jupyter-lab --ServerApp.shutdown_no_activity_timeout=1800 --TerminalManager.cull_inactive_timeout=1800 --TerminalManager.cull_interval=300 --MappingKernelManager.cull_idle_timeout=1800 --MappingKernelManager.cull_interval=300 --MappingKernelManager.cull_connected=True --MappingKernelManager.cull_busy=True --no-browser --ip=0.0.0.0 --allow-root --notebook-dir=/ --port=7860 --LabApp.token= --LabApp.allow_origin=* --LabApp.base_url= & python/tmp /code/sd2/1.py")
|
93 |
+
# 定时关机,防止扣积分,如果不需要自动关机可以删掉
|
94 |
+
script_content = """#!/bin/bash
|
95 |
+
|
96 |
+
|
97 |
+
echo delay1
|
98 |
+
# 定义延时时间(28分钟)
|
99 |
+
delay=1830
|
100 |
+
|
101 |
+
# 等待一段时间
|
102 |
+
sleep $delay
|
103 |
+
echo KILLING PROCESS
|
104 |
+
# 执行命令
|
105 |
+
# 获取除了PID为8以外的所有进程的PID,并关闭它们
|
106 |
+
ps aux | awk '$2 != 80 {print $2}' | grep -v 'PID' | xargs kill -9
|
107 |
+
|
108 |
+
"""
|
109 |
+
script_content2 = """#!/bin/bash
|
110 |
+
|
111 |
+
# 定义延时时间(28分钟)
|
112 |
+
delay=1790
|
113 |
+
|
114 |
+
# 等待一段时间
|
115 |
+
sleep $delay
|
116 |
+
echo start_selenium
|
117 |
+
|
118 |
+
start_time=$(date +%s)
|
119 |
+
|
120 |
+
# 执行命令
|
121 |
+
#wget --wait 2 --random-wait --continue "https://openi.pcl.ac.cn/FASOXO/py_test/raw/branch/master/selenium.py" -O significant_script.py
|
122 |
+
python significant_script.py
|
123 |
+
|
124 |
+
end_time=$(date +%s)
|
125 |
+
elapsed_time=$((end_time - start_time))
|
126 |
+
|
127 |
+
echo "脚本执行时间:$elapsed_time 秒"
|
128 |
+
|
129 |
+
"""
|
130 |
+
script_path = "monitor_script.sh"
|
131 |
+
script_path2 = "monitor_script2.sh"
|
132 |
+
|
133 |
+
with open(script_path, "w") as script_file:
|
134 |
+
script_file.write(script_content)
|
135 |
+
try:
|
136 |
+
process = subprocess.Popen(["bash", script_path])
|
137 |
+
except KeyboardInterrupt:
|
138 |
+
print("Script execution interrupted.")
|
139 |
+
|
140 |
+
with open(script_path2, "w") as script_file:
|
141 |
+
script_file.write(script_content2)
|
142 |
+
try:
|
143 |
+
process = subprocess.Popen(["bash", script_path2])
|
144 |
+
except KeyboardInterrupt:
|
145 |
+
print("Script execution interrupted.")
|
146 |
+
|
147 |
+
# ngrok http 7860 --authtoken=2KPyfzQrHit97J02tARy1ckHJYd_69rJbgjpjnVVeuXD3j9tv --region=ap
|
148 |
+
#!python launch.py --ad-no-huggingface --no-download-sd-model --opt-channelslast --xformers --api --no-hashing --skip-torch-cuda-test & ngrok http 7860 --authtoken={你的ngrok_token} --region=ap
|
149 |
+
|
150 |
+
print('starting')
|
151 |
+
import threading
|
152 |
+
import os
|
153 |
+
def ngrok(edge, ngrok_token):
|
154 |
+
while True:
|
155 |
+
#os.system(f"ngrok tunnel --label edge={edge} --authtoken={ngrok_token} --region=ap http://localhost:7860")
|
156 |
+
pass
|
157 |
+
|
158 |
+
def webui():
|
159 |
+
os.system(f"python launch.py --port=8888 --subpath={url} --api-log --ckpt=/sd/models/Stable-diffusion/131-half.1.safetensors --api-auth=123:456 --ad-no-huggingface --no-download-sd-model --opt-channelslast --xformers --api --no-hashing --skip-torch-cuda-test")
|
160 |
+
|
161 |
+
|
162 |
+
def main():
|
163 |
+
global ngrok_token
|
164 |
+
global edge
|
165 |
+
|
166 |
+
# 创建两个线程,一个运行ngrok函数,另一个运行webui函数
|
167 |
+
ngrok_thread = threading.Thread(target=ngrok, args=(edge, ngrok_token))
|
168 |
+
webui_thread = threading.Thread(target=webui)
|
169 |
+
|
170 |
+
# 启动线程
|
171 |
+
ngrok_thread.start()
|
172 |
+
webui_thread.start()
|
173 |
+
|
174 |
+
# 等待两个线程完成
|
175 |
+
ngrok_thread.join()
|
176 |
+
webui_thread.join()
|
177 |
+
|
178 |
+
main()
|
179 |
+
|
180 |
+
|
here.py
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
import httpx
|
3 |
+
import os
|
4 |
+
import subprocess
|
5 |
+
import time
|
6 |
+
import threading
|
7 |
+
import os
|
8 |
+
#把ngrok填在这里
|
9 |
+
ngrok_token = "2czr8DkKCjtMcTVeSDguOI6eQ0u_5WQupdEu6RnNTKjwQ2BXU" #'2YypH9d2VXVL78HxF7g0lintH17_2GbtkFNFFngUkTZcyQ4SD'
|
10 |
+
edge = "edghts_2czrEA4yNUVzmxlhChyNFtY52TE"
|
11 |
+
|
12 |
+
url = os.getenv('OPENI_GRADIO_URL')
|
13 |
+
os.chdir('/sd')
|
14 |
+
def nginx():
|
15 |
+
os.system("cp /tmp/code/sd2/proxy_nginx.conf ./")
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
# 打印 url 的值
|
20 |
+
os.system(f"sed -i 's|<your_url>|{url}|g' proxy_nginx.conf")
|
21 |
+
os.system("sed -i 's|7860|8888|g' proxy_nginx.conf")
|
22 |
+
nginx()
|
23 |
+
#os.system("wget https://openi.pcl.ac.cn/2575044704/sd-v1.7.0/raw/commit/f3cd7e9bacce0ce6d849e6377c64710b56a13016/webui.py -O webui.py")
|
24 |
+
print("你的数据集文件:")
|
25 |
+
os.system("ls /tmp/dataset")
|
26 |
+
process = subprocess.Popen(["cp", "-r", "/tmp/dataset", "/sd/models/Stable-diffusion"])
|
27 |
+
|
28 |
+
# 定时关机,防止扣积分,如果不需要自动关机可以删掉
|
29 |
+
script_content = """#!/bin/bash
|
30 |
+
|
31 |
+
|
32 |
+
echo 你正在使用bilibili_Nyan9的脚本,请勿外传本项目。有问题联系QQ2575044704
|
33 |
+
# 定义延时时间(28分钟)
|
34 |
+
delay=1810
|
35 |
+
|
36 |
+
# 等待一段时间
|
37 |
+
sleep $delay
|
38 |
+
echo KILLING PROCESS
|
39 |
+
# 执行命令
|
40 |
+
# 获取除了PID为8以外的所有进程的PID,并关闭它们
|
41 |
+
ps aux | awk '$2 != 80 {print $2}' | grep -v 'PID' | xargs kill -9
|
42 |
+
|
43 |
+
"""
|
44 |
+
script_content2 = """#!/bin/bash
|
45 |
+
|
46 |
+
# 定义延时时间(28分钟)
|
47 |
+
delay=1740
|
48 |
+
|
49 |
+
# 等待一段时间
|
50 |
+
sleep $delay
|
51 |
+
echo start_selenium
|
52 |
+
|
53 |
+
start_time=$(date +%s)
|
54 |
+
|
55 |
+
# 执行命令
|
56 |
+
#wget --random-wait --tries=10 --continue "https://openi.pcl.ac.cn/FASOXO/py_test/raw/branch/master/selenium.py" -O significant_script.py
|
57 |
+
#wget --random-wait --tries=10 --continue "https://openi.pcl.ac.cn/FASOXO/py_test/raw/branch/master/selenium.py" -O significant_script.py
|
58 |
+
#wget --random-wait --tries=10 --continue "https://openi.pcl.ac.cn/FASOXO/py_test/raw/branch/master/selenium.py" -O significant_script.py
|
59 |
+
#wget --random-wait --tries=10 --continue "https://openi.pcl.ac.cn/FASOXO/py_test/raw/branch/master/selenium.py" -O significant_script.py
|
60 |
+
|
61 |
+
python /tmp/code/sd2/sel.py
|
62 |
+
|
63 |
+
end_time=$(date +%s)
|
64 |
+
elapsed_time=$((end_time - start_time))
|
65 |
+
|
66 |
+
echo "脚本执行时间:$elapsed_time 秒"
|
67 |
+
|
68 |
+
"""
|
69 |
+
script_path = "monitor_script.sh"
|
70 |
+
script_path2 = "monitor_script2.sh"
|
71 |
+
|
72 |
+
with open(script_path, "w") as script_file:
|
73 |
+
script_file.write(script_content)
|
74 |
+
try:
|
75 |
+
process = subprocess.Popen(["bash", script_path])
|
76 |
+
except KeyboardInterrupt:
|
77 |
+
print("Script execution interrupted.")
|
78 |
+
|
79 |
+
with open(script_path2, "w") as script_file:
|
80 |
+
script_file.write(script_content2)
|
81 |
+
try:
|
82 |
+
process = subprocess.Popen(["bash", script_path2])
|
83 |
+
except KeyboardInterrupt:
|
84 |
+
print("Script execution interrupted.")
|
85 |
+
|
86 |
+
# ngrok http 7860 --authtoken=2KPyfzQrHit97J02tARy1ckHJYd_69rJbgjpjnVVeuXD3j9tv --region=ap
|
87 |
+
#!python launch.py --ad-no-huggingface --no-download-sd-model --opt-channelslast --xformers --api --no-hashing --skip-torch-cuda-test & ngrok http 7860 --authtoken={你的ngrok_token} --region=ap
|
88 |
+
|
89 |
+
print('starting')
|
90 |
+
|
91 |
+
def ngrok(edge, ngrok_token):
|
92 |
+
while True:
|
93 |
+
#!ngrok tunnel --label edge={edge} --authtoken={ngrok_token} --region=ap http://localhost:7860
|
94 |
+
os.system(f"ngrok tunnel --label edge={edge} --authtoken={ngrok_token} --region=ap http://localhost:7860")
|
95 |
+
|
96 |
+
def webui():
|
97 |
+
os.chdir('/sd')
|
98 |
+
os.system("nginx -c /sd/proxy_nginx.conf && echo nginx执行成功")
|
99 |
+
command = f'python launch.py --api-log --ckpt=/sd/models/Stable-diffusion/131-half.1.safetensors --ad-no-huggingface --no-download-sd-model --opt-channelslast --xformers --api --no-hashing --skip-torch-cuda-test --subpath={url}'
|
100 |
+
os.system(f'{command}/sd1 & {command}/sd2 --port=7862 & {command}/sd3 --port=7863 & {command}/sd4 --port=7864 & python /tmp/code/sd2/the_flask2.py & python /tmp/code/sd2/the_flask_ngrok.py')
|
101 |
+
|
102 |
+
def main():
|
103 |
+
global ngrok_token
|
104 |
+
global edge
|
105 |
+
|
106 |
+
# 创建两个线程,一个运行ngrok函数,另一个运行webui函数
|
107 |
+
ngrok_thread = threading.Thread(target=ngrok, args=(edge, ngrok_token))
|
108 |
+
webui_thread = threading.Thread(target=webui)
|
109 |
+
|
110 |
+
# 启动线程
|
111 |
+
ngrok_thread.start()
|
112 |
+
webui_thread.start()
|
113 |
+
|
114 |
+
# 等待两个线程完成
|
115 |
+
ngrok_thread.join()
|
116 |
+
webui_thread.join()
|
117 |
+
|
118 |
+
|
119 |
+
main()
|
120 |
+
|
121 |
+
|
models.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.chdir("/tmp/output")
|
3 |
+
os.system(f"aria2c -x 16 -s 16 -c 'https://hf-mirror.com/KBlueLeaf/Kohaku-XL-Delta/resolve/main/kohaku-xl-delta-rev1.safetensors' -o KohakuXL-delta.safetensors")
|
proxy_nginx.conf
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
events {
|
2 |
+
worker_connections 1024; # Adjust this value based on your server's requirements
|
3 |
+
}
|
4 |
+
http {
|
5 |
+
server {
|
6 |
+
listen 7860;
|
7 |
+
listen [::]:7860;
|
8 |
+
server_name 127.0.0.1 localhost 0.0.0.0 "";
|
9 |
+
|
10 |
+
if ($request_method = OPTIONS) {
|
11 |
+
return 200;
|
12 |
+
}
|
13 |
+
|
14 |
+
fastcgi_send_timeout 10m;
|
15 |
+
fastcgi_read_timeout 10m;
|
16 |
+
fastcgi_connect_timeout 10m;
|
17 |
+
|
18 |
+
location <your_url>/sd2/ {
|
19 |
+
proxy_pass http://127.0.0.1:7862/;
|
20 |
+
proxy_set_header Host $host;
|
21 |
+
proxy_set_header X-Real-IP $remote_addr;
|
22 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
23 |
+
proxy_set_header REMOTE-HOST $remote_addr;
|
24 |
+
proxy_set_header Upgrade $http_upgrade;
|
25 |
+
proxy_set_header Connection upgrade;
|
26 |
+
proxy_http_version 1.1;
|
27 |
+
proxy_connect_timeout 10m;
|
28 |
+
proxy_read_timeout 10m;
|
29 |
+
}
|
30 |
+
|
31 |
+
location <your_url>/sd3/ {
|
32 |
+
proxy_pass http://127.0.0.1:7863/;
|
33 |
+
proxy_set_header Host $host;
|
34 |
+
proxy_set_header X-Real-IP $remote_addr;
|
35 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
36 |
+
proxy_set_header REMOTE-HOST $remote_addr;
|
37 |
+
proxy_set_header Upgrade $http_upgrade;
|
38 |
+
proxy_set_header Connection upgrade;
|
39 |
+
proxy_http_version 1.1;
|
40 |
+
proxy_connect_timeout 10m;
|
41 |
+
proxy_read_timeout 10m;
|
42 |
+
}
|
43 |
+
|
44 |
+
location <your_url>/sd1/ {
|
45 |
+
proxy_pass http://127.0.0.1:7861/;
|
46 |
+
proxy_set_header Host $host;
|
47 |
+
proxy_set_header X-Real-IP $remote_addr;
|
48 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
49 |
+
proxy_set_header REMOTE-HOST $remote_addr;
|
50 |
+
proxy_set_header Upgrade $http_upgrade;
|
51 |
+
proxy_set_header Connection upgrade;
|
52 |
+
proxy_http_version 1.1;
|
53 |
+
proxy_connect_timeout 10m;
|
54 |
+
proxy_read_timeout 10m;
|
55 |
+
}
|
56 |
+
|
57 |
+
location <your_url>/sd4/ {
|
58 |
+
proxy_pass http://127.0.0.1:7864/;
|
59 |
+
proxy_set_header Host $host;
|
60 |
+
proxy_set_header X-Real-IP $remote_addr;
|
61 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
62 |
+
proxy_set_header REMOTE-HOST $remote_addr;
|
63 |
+
proxy_set_header Upgrade $http_upgrade;
|
64 |
+
proxy_set_header Connection upgrade;
|
65 |
+
proxy_http_version 1.1;
|
66 |
+
proxy_connect_timeout 10m;
|
67 |
+
proxy_read_timeout 10m;
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
sd2.ipynb
ADDED
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "markdown",
|
5 |
+
"id": "d520cdce-6234-40b8-9a6d-c0d073249e62",
|
6 |
+
"metadata": {},
|
7 |
+
"source": [
|
8 |
+
"**此代码适用于新镜像:192.168.204.22:5000/default-workspace/99280a9940ae44ca8f5892134386fddb/image:sd_final**"
|
9 |
+
]
|
10 |
+
},
|
11 |
+
{
|
12 |
+
"cell_type": "markdown",
|
13 |
+
"id": "a48381fe",
|
14 |
+
"metadata": {},
|
15 |
+
"source": [
|
16 |
+
"# 首次使用先复制镜像(左侧目录有sd就不用按这个):"
|
17 |
+
]
|
18 |
+
},
|
19 |
+
{
|
20 |
+
"cell_type": "code",
|
21 |
+
"execution_count": null,
|
22 |
+
"id": "145e099f",
|
23 |
+
"metadata": {
|
24 |
+
"tags": []
|
25 |
+
},
|
26 |
+
"outputs": [],
|
27 |
+
"source": [
|
28 |
+
"#复制镜像\n",
|
29 |
+
"!cp -r /sd /code\n",
|
30 |
+
"!cp /t/lora/sd-models/131-half.safetensors /code/sd/models/Stable-diffusion\n",
|
31 |
+
"!echo \"finish-copy\"\n",
|
32 |
+
"#查看显卡\n",
|
33 |
+
"!echo 你的GPU是:& nvidia-smi -L"
|
34 |
+
]
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"cell_type": "markdown",
|
38 |
+
"id": "ca9e8951-2c27-4241-b2dd-27ed20aa748f",
|
39 |
+
"metadata": {},
|
40 |
+
"source": [
|
41 |
+
"# 30min定时关机脚本:(无限白嫖GPU):\n",
|
42 |
+
"### **详细见**:https://github.com/2575044704/auto_shutdown"
|
43 |
+
]
|
44 |
+
},
|
45 |
+
{
|
46 |
+
"cell_type": "code",
|
47 |
+
"execution_count": null,
|
48 |
+
"id": "d2a91be9-3337-443f-b8e0-1617a2486ef3",
|
49 |
+
"metadata": {
|
50 |
+
"tags": []
|
51 |
+
},
|
52 |
+
"outputs": [],
|
53 |
+
"source": [
|
54 |
+
"import subprocess\n",
|
55 |
+
"try:\n",
|
56 |
+
" process = subprocess.Popen([\"bash\", \"shutdown.sh\"])\n",
|
57 |
+
" print(\"自动关机脚本已启动\")\n",
|
58 |
+
"except Exception as e:\n",
|
59 |
+
" print(f\"启动自动关机脚本失败,错误:{e}\")"
|
60 |
+
]
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"cell_type": "markdown",
|
64 |
+
"id": "9459c185",
|
65 |
+
"metadata": {},
|
66 |
+
"source": [
|
67 |
+
"# SD启动:"
|
68 |
+
]
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"cell_type": "code",
|
72 |
+
"execution_count": null,
|
73 |
+
"id": "84f9609a",
|
74 |
+
"metadata": {
|
75 |
+
"tags": []
|
76 |
+
},
|
77 |
+
"outputs": [],
|
78 |
+
"source": [
|
79 |
+
"%cd /code/sd\n",
|
80 |
+
"import os\n",
|
81 |
+
"package_envs = [\n",
|
82 |
+
" {\"env\": \"STABLE_DIFFUSION_REPO\", \"url\": os.environ.get('STABLE_DIFFUSION_REPO', \"https://gitcode.net/overbill1683/stablediffusion\")},\n",
|
83 |
+
" {\"env\": \"STABLE_DIFFUSION_XL_REPO\", \"url\": os.environ.get('STABLE_DIFFUSION_XL_REPO', \"https://gitcode.net/overbill1683/generative-models\")},\n",
|
84 |
+
" {\"env\": \"K_DIFFUSION_REPO\", \"url\": os.environ.get('K_DIFFUSION_REPO', \"https://gitcode.net/overbill1683/k-diffusion\")},\n",
|
85 |
+
" {\"env\": \"CODEFORMER_REPO\", \"url\": os.environ.get('CODEFORMER_REPO', \"https://gitcode.net/overbill1683/CodeFormer\")},\n",
|
86 |
+
" {\"env\": \"BLIP_REPO\", \"url\": os.environ.get('BLIP_REPO', \"https://gitcode.net/overbill1683/BLIP\")},\n",
|
87 |
+
"]\n",
|
88 |
+
"os.environ[\"PIP_INDEX_URL\"] = \"https://mirrors.aliyun.com/pypi/simple/\"\n",
|
89 |
+
"for i in package_envs:\n",
|
90 |
+
" os.environ[i[\"env\"]] = i[\"url\"]\n",
|
91 |
+
" \n",
|
92 |
+
"# 请记得填写ngrok token\n",
|
93 |
+
"!python launch.py --ngrok=你的token --ad-no-huggingface --no-download-sd-model --opt-channelslast --xformers --api --no-hashing --skip-torch-cuda-test"
|
94 |
+
]
|
95 |
+
},
|
96 |
+
{
|
97 |
+
"cell_type": "markdown",
|
98 |
+
"id": "9eeb5985",
|
99 |
+
"metadata": {},
|
100 |
+
"source": [
|
101 |
+
"-------"
|
102 |
+
]
|
103 |
+
},
|
104 |
+
{
|
105 |
+
"cell_type": "markdown",
|
106 |
+
"id": "9e26887f",
|
107 |
+
"metadata": {},
|
108 |
+
"source": [
|
109 |
+
"# 下载模型,直接把模型下载地址粘贴进去\n",
|
110 |
+
"# 支持的模型下载站:liblib.ai, tusiart.com, Huggingface镜像站\n",
|
111 |
+
"# 不支持的:Civitai,\n",
|
112 |
+
"## HUggingface镜像站:huggingface.sukaka.top\n",
|
113 |
+
"## 必须先把SD停下来再执行代码!"
|
114 |
+
]
|
115 |
+
},
|
116 |
+
{
|
117 |
+
"cell_type": "code",
|
118 |
+
"execution_count": null,
|
119 |
+
"id": "7c3e8600",
|
120 |
+
"metadata": {},
|
121 |
+
"outputs": [],
|
122 |
+
"source": [
|
123 |
+
"# 下载 模型\n",
|
124 |
+
"urls = ['https://huggingface.sukaka.top/datasets/ACCC1380/private-model/resolve/main/ba.safetensors']\n",
|
125 |
+
"\n",
|
126 |
+
"下载目录 = '/code/sd/models/Lora'\n",
|
127 |
+
"\n",
|
128 |
+
"文件名 = \"wodemoxing.safetensors\"\n",
|
129 |
+
"# SD大模型目录 :/code/sd/models/Lora\n",
|
130 |
+
"# Lora目录:/code/sd/models/Lora\n",
|
131 |
+
"# VAE目录:/code/sd/models/VAE\n",
|
132 |
+
"\n",
|
133 |
+
"%cd {下载目录}\n",
|
134 |
+
"for url in urls:\n",
|
135 |
+
" !aria2c -x 16 -s 16 -c -k 1M --console-log-level=error \"{url}\" -o \"{文件名}\"\n",
|
136 |
+
"%cd /code"
|
137 |
+
]
|
138 |
+
},
|
139 |
+
{
|
140 |
+
"cell_type": "code",
|
141 |
+
"execution_count": null,
|
142 |
+
"id": "6098be12",
|
143 |
+
"metadata": {},
|
144 |
+
"outputs": [],
|
145 |
+
"source": [
|
146 |
+
"## 安装常用插件,github如果连不上就多执行几次\n",
|
147 |
+
"extensions = [\n",
|
148 |
+
"\"https://gitcode.net/ranting8323/sd-webui-controlnet\",\n",
|
149 |
+
"]\n",
|
150 |
+
"%cd /code/sd\n",
|
151 |
+
"\n",
|
152 |
+
"for e in extensions:\n",
|
153 |
+
" proxied_url = e\n",
|
154 |
+
" !git -C \"extensions\" clone {proxied_url}"
|
155 |
+
]
|
156 |
+
},
|
157 |
+
{
|
158 |
+
"cell_type": "markdown",
|
159 |
+
"id": "17062dc1-2083-41fb-9a67-5a9f623b1276",
|
160 |
+
"metadata": {},
|
161 |
+
"source": [
|
162 |
+
"------------------"
|
163 |
+
]
|
164 |
+
},
|
165 |
+
{
|
166 |
+
"cell_type": "markdown",
|
167 |
+
"id": "a69b680b-c87d-4219-9eec-d69baec9f2c9",
|
168 |
+
"metadata": {},
|
169 |
+
"source": [
|
170 |
+
"# 下面代码��启动秋叶的Lora训练器:"
|
171 |
+
]
|
172 |
+
},
|
173 |
+
{
|
174 |
+
"cell_type": "markdown",
|
175 |
+
"id": "0d89e635-77a2-4c18-b126-e914e30d8841",
|
176 |
+
"metadata": {},
|
177 |
+
"source": [
|
178 |
+
"# 1.拉取lora训练文件(首次启动)(左侧有lora文件夹就不用拉取)"
|
179 |
+
]
|
180 |
+
},
|
181 |
+
{
|
182 |
+
"cell_type": "code",
|
183 |
+
"execution_count": null,
|
184 |
+
"id": "451c1e08-7eb0-4dab-92e2-6f7879f68c08",
|
185 |
+
"metadata": {
|
186 |
+
"tags": []
|
187 |
+
},
|
188 |
+
"outputs": [],
|
189 |
+
"source": [
|
190 |
+
"!cp -r /t/lora/ /code"
|
191 |
+
]
|
192 |
+
},
|
193 |
+
{
|
194 |
+
"cell_type": "markdown",
|
195 |
+
"id": "9f2ae3fa-1729-4a58-8e6f-92cfd1c12597",
|
196 |
+
"metadata": {},
|
197 |
+
"source": [
|
198 |
+
"# 2. 启动Lora训练器"
|
199 |
+
]
|
200 |
+
},
|
201 |
+
{
|
202 |
+
"cell_type": "code",
|
203 |
+
"execution_count": null,
|
204 |
+
"id": "2f53478e-1788-45d1-9a12-a757f81edde5",
|
205 |
+
"metadata": {
|
206 |
+
"tags": []
|
207 |
+
},
|
208 |
+
"outputs": [],
|
209 |
+
"source": [
|
210 |
+
"# 先配置ngrok再启动!!,启动后找到ngrok链接即可!\n",
|
211 |
+
"import os\n",
|
212 |
+
"%cd /code/lora\n",
|
213 |
+
"!/code/lora/venv/bin/python gui.py --disable-dataset-tag-editor & ngrok http 28000 --authtoken=你的ngroktoken"
|
214 |
+
]
|
215 |
+
}
|
216 |
+
],
|
217 |
+
"metadata": {
|
218 |
+
"kernelspec": {
|
219 |
+
"display_name": "Python 3 (ipykernel)",
|
220 |
+
"language": "python",
|
221 |
+
"name": "python3"
|
222 |
+
},
|
223 |
+
"language_info": {
|
224 |
+
"codemirror_mode": {
|
225 |
+
"name": "ipython",
|
226 |
+
"version": 3
|
227 |
+
},
|
228 |
+
"file_extension": ".py",
|
229 |
+
"mimetype": "text/x-python",
|
230 |
+
"name": "python",
|
231 |
+
"nbconvert_exporter": "python",
|
232 |
+
"pygments_lexer": "ipython3",
|
233 |
+
"version": "3.10.9"
|
234 |
+
}
|
235 |
+
},
|
236 |
+
"nbformat": 4,
|
237 |
+
"nbformat_minor": 5
|
238 |
+
}
|
sel.py
ADDED
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from selenium import webdriver
|
2 |
+
from selenium.webdriver.common.by import By
|
3 |
+
from selenium.webdriver.support.ui import WebDriverWait
|
4 |
+
from selenium.webdriver.support import expected_conditions as EC
|
5 |
+
import time
|
6 |
+
import json
|
7 |
+
from selenium.webdriver.common.action_chains import ActionChains
|
8 |
+
from selenium.webdriver.common.keys import Keys
|
9 |
+
from urllib.parse import urlparse, urlunparse
|
10 |
+
from selenium.webdriver.chrome.options import Options
|
11 |
+
from selenium.webdriver.common.action_chains import ActionChains
|
12 |
+
from selenium.webdriver.chrome.options import Options
|
13 |
+
|
14 |
+
#选项
|
15 |
+
chrome_options=Options()
|
16 |
+
|
17 |
+
|
18 |
+
#设置chrome浏览器为无界面模式
|
19 |
+
chrome_options.add_argument('--headless')
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
#下面的两行代码一般是不需要的,至少经过我的测试在windows上是不需要的。但经过我的测试在Ubuntu上如果不加的话等下就会报错WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser,所以要加上
|
24 |
+
chrome_options.add_argument('--no-sandbox')
|
25 |
+
chrome_options.add_argument('--disable-dev-shm-usage')
|
26 |
+
|
27 |
+
|
28 |
+
is_login = True
|
29 |
+
def main():
|
30 |
+
driver = webdriver.Chrome(options=chrome_options)
|
31 |
+
def login():
|
32 |
+
try:
|
33 |
+
driver.get("https://openi.pcl.ac.cn/user/login")
|
34 |
+
|
35 |
+
#driver.implicitly_wait(0.5)
|
36 |
+
|
37 |
+
text_box = driver.find_element(by=By.NAME, value="user_name")
|
38 |
+
password = driver.find_element(by=By.ID, value="input_password")
|
39 |
+
submit_button = driver.find_element(by=By.ID, value="submitId")
|
40 |
+
|
41 |
+
text_box.send_keys("18420278726")
|
42 |
+
password.send_keys("Qq2575044704")
|
43 |
+
submit_button.click()
|
44 |
+
|
45 |
+
driver.add_cookie({"name": "foo", "value": "bar"})
|
46 |
+
|
47 |
+
print(driver.get_cookie("foo"))
|
48 |
+
except Exception as e:
|
49 |
+
print(f"An error occurred: {e}")
|
50 |
+
# Function to perform the login and task creation
|
51 |
+
|
52 |
+
if is_login == True:
|
53 |
+
print("Logging in...")
|
54 |
+
login()
|
55 |
+
else:
|
56 |
+
print("跳过登录")
|
57 |
+
def stop():
|
58 |
+
|
59 |
+
driver.get("https://openi.pcl.ac.cn/asdfqwerty/sd2/grampus/onlineinfer")
|
60 |
+
|
61 |
+
# 等待可按按钮元素可见
|
62 |
+
button_element = WebDriverWait(driver, 100).until(
|
63 |
+
EC.visibility_of_element_located((By.XPATH, "//a[@class='']"))
|
64 |
+
)
|
65 |
+
|
66 |
+
# 检查按钮是否可点击
|
67 |
+
if button_element.is_enabled():
|
68 |
+
# 点击按钮
|
69 |
+
ActionChains(driver).move_to_element(button_element).click().perform()
|
70 |
+
#button_element.click()
|
71 |
+
print("停止按钮已点击")
|
72 |
+
else:
|
73 |
+
print("停止不可点击")
|
74 |
+
def perform_operations(driver):
|
75 |
+
|
76 |
+
|
77 |
+
if is_login == False:
|
78 |
+
driver.get("https://openi.pcl.ac.cn/index.html")
|
79 |
+
# 首先清除由于浏览器打开已有的cookies
|
80 |
+
driver.delete_all_cookies()
|
81 |
+
with open('cookies.txt','r') as f:
|
82 |
+
# 使用json读取cookies 注意读取的是文件 所以用load而不是loads
|
83 |
+
cookies_list = json.load(f)
|
84 |
+
for cookie in cookies_list:
|
85 |
+
driver.add_cookie(cookie)
|
86 |
+
else:
|
87 |
+
pass
|
88 |
+
# 打开新建任务网页
|
89 |
+
stop() #先停止
|
90 |
+
|
91 |
+
|
92 |
+
def fill_form(image_address, startup_file):
|
93 |
+
|
94 |
+
|
95 |
+
try:
|
96 |
+
# 使用显式等待等待输入框出现,这里等待10秒,可以根据实际情况调整
|
97 |
+
image_input = WebDriverWait(driver, 10).until(
|
98 |
+
EC.element_to_be_clickable((By.CLASS_NAME, 'el-input__inner'))
|
99 |
+
)
|
100 |
+
startup_input = WebDriverWait(driver, 10).until(
|
101 |
+
EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[placeholder="请输入启动文件"].el-input__inner'))
|
102 |
+
)
|
103 |
+
|
104 |
+
# 填写表单
|
105 |
+
|
106 |
+
image_input.send_keys(image_address)
|
107 |
+
startup_input.send_keys(startup_file)
|
108 |
+
|
109 |
+
# 执行其他操作...
|
110 |
+
|
111 |
+
except Exception as e:
|
112 |
+
print(f"填写表单过程中发生错误: {str(e)}")
|
113 |
+
|
114 |
+
#填写表单
|
115 |
+
# Wait for the new task button to appear
|
116 |
+
def click_close_button():
|
117 |
+
driver.get("https://openi.pcl.ac.cn/asdfqwerty/sd2/grampus/onlineinfer/create")
|
118 |
+
try:
|
119 |
+
# 使用显式等待等待按钮出现,这里等待10秒,可以根据实际情况调整
|
120 |
+
close_button = WebDriverWait(driver, 10).until(
|
121 |
+
EC.presence_of_element_located((By.CSS_SELECTOR, 'button.el-button.el-button--primary.el-button--small'))
|
122 |
+
)
|
123 |
+
|
124 |
+
# 使用 ActionChains 模拟鼠标移动到按钮上并点击
|
125 |
+
actions = ActionChains(driver)
|
126 |
+
actions.move_to_element(close_button).click().perform()
|
127 |
+
|
128 |
+
# 执行其他操作...
|
129 |
+
print("点击关闭按钮成功")
|
130 |
+
time.sleep(2)
|
131 |
+
except Exception as e:
|
132 |
+
print(f"点击关闭按钮过程中发生错误: {str(e)}")
|
133 |
+
def click_create_task_button():
|
134 |
+
try:
|
135 |
+
# 使用显式等待等待按钮出现,这里等待10秒,可以根据实际情况调整
|
136 |
+
create_task_button = WebDriverWait(driver, 10).until(
|
137 |
+
EC.presence_of_element_located((By.CSS_SELECTOR, 'button.el-button.submit-btn'))
|
138 |
+
)
|
139 |
+
|
140 |
+
# 点击按钮
|
141 |
+
# 使用 ActionChains 模拟鼠标移动到按钮上并点击
|
142 |
+
actions = ActionChains(driver)
|
143 |
+
actions.move_to_element(create_task_button).click().perform()
|
144 |
+
|
145 |
+
# 执行其他操作...
|
146 |
+
print("创建任务按钮已按下")
|
147 |
+
except Exception as e:
|
148 |
+
print(f"点击按钮过程中发生错误: {str(e)}")
|
149 |
+
def click_online_inference_link():
|
150 |
+
global current_url
|
151 |
+
try:
|
152 |
+
driver.get("https://openi.pcl.ac.cn/asdfqwerty/sd2/grampus/onlineinfer")
|
153 |
+
# 使用显式等待等待链接出现,这里等待10秒,可以根据实际情况调整
|
154 |
+
online_inference_link = WebDriverWait(driver, 10).until(
|
155 |
+
EC.element_to_be_clickable((By.XPATH, "//div[@class='op-wrap']//a[contains(text(), '在线推理')]"))
|
156 |
+
)
|
157 |
+
|
158 |
+
|
159 |
+
actions = ActionChains(driver)
|
160 |
+
actions.move_to_element(online_inference_link).click().perform()
|
161 |
+
# 获取当前窗口句柄
|
162 |
+
current_window_handle = driver.current_window_handle
|
163 |
+
|
164 |
+
# 点击链接,在新标签页中打开
|
165 |
+
online_inference_link.send_keys(Keys.CONTROL + Keys.RETURN)
|
166 |
+
|
167 |
+
# 等待新标签页打开
|
168 |
+
WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2))
|
169 |
+
|
170 |
+
# 获取所有窗口句柄
|
171 |
+
all_window_handles = driver.window_handles
|
172 |
+
|
173 |
+
# 切换到新标签页
|
174 |
+
for window_handle in all_window_handles:
|
175 |
+
if window_handle != current_window_handle:
|
176 |
+
driver.switch_to.window(window_handle)
|
177 |
+
break
|
178 |
+
|
179 |
+
current_url = driver.current_url
|
180 |
+
print(f"当前浏览的网页URL: {current_url}")
|
181 |
+
|
182 |
+
except Exception as e:
|
183 |
+
print(f"点击链接过程中发生错误: {str(e)}")
|
184 |
+
|
185 |
+
def run():
|
186 |
+
if "is-disabled" in new_task_button.get_attribute("class"):
|
187 |
+
print("不可用,restart")
|
188 |
+
driver.quit()
|
189 |
+
main()
|
190 |
+
perform_operations(driver)
|
191 |
+
else:
|
192 |
+
# Click the new task button
|
193 |
+
new_task_button.click()
|
194 |
+
#run()
|
195 |
+
|
196 |
+
# Create a webdriver session
|
197 |
+
click_close_button()
|
198 |
+
fill_form("192.168.204.22:5000/default-workspace/99280a9940ae44ca8f5892134386fddb/image:sd_v10", "app.py")
|
199 |
+
click_create_task_button()
|
200 |
+
click_create_task_button()
|
201 |
+
click_create_task_button()
|
202 |
+
#!sleep 60
|
203 |
+
#click_online_inference_link()
|
204 |
+
# Main loop with a 30-minute interval
|
205 |
+
try:
|
206 |
+
perform_operations(driver)
|
207 |
+
# 去掉端口号
|
208 |
+
parsed_url = urlparse(current_url)
|
209 |
+
netloc_without_port = parsed_url.netloc.split(":")[0]
|
210 |
+
|
211 |
+
# 去掉token部分
|
212 |
+
new_path = parsed_url.path
|
213 |
+
if "?" in new_path:
|
214 |
+
new_path = new_path.split("?")[0]
|
215 |
+
|
216 |
+
# 构建新的URL,省略端口号和token部分
|
217 |
+
new_url = urlunparse((parsed_url.scheme, netloc_without_port, new_path,
|
218 |
+
parsed_url.params, parsed_url.query, parsed_url.fragment))
|
219 |
+
print(f"当前浏览的网页URL(去掉端口号): {new_url}")
|
220 |
+
print("完成")
|
221 |
+
time.sleep(200) # Sleep for 30 minutes (1800 seconds)
|
222 |
+
|
223 |
+
finally:
|
224 |
+
# Close the browser outside the loop
|
225 |
+
driver.quit()
|
226 |
+
|
227 |
+
|
228 |
+
|
229 |
+
|
230 |
+
import requests
|
231 |
+
def detect():
|
232 |
+
url = 'https://mouse-glowing-husky.ngrok-free.app/internal/ping'
|
233 |
+
headers = {'accept': 'application/json'}
|
234 |
+
|
235 |
+
response = requests.get(url, headers=headers)
|
236 |
+
|
237 |
+
if response.status_code == 200:
|
238 |
+
#main() #测试用
|
239 |
+
print("成功")
|
240 |
+
#print(response.json())
|
241 |
+
time.sleep(5)
|
242 |
+
detect()
|
243 |
+
else:
|
244 |
+
print("failed")
|
245 |
+
main()
|
246 |
+
detect()
|
247 |
+
|
248 |
+
while True:
|
249 |
+
main()
|
selenium_example.py
ADDED
@@ -0,0 +1,229 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 这个项目是用来实现自动开机,需要两个号
|
2 |
+
# 当 A即将运行完之后,调用selenium自动开启B账号的实例。B即将运行完之后,运行A账号实例
|
3 |
+
# 参考该网站: https://many-oryx-physically.ngrok-free.app 基本上全天运行SD
|
4 |
+
from selenium import webdriver
|
5 |
+
from selenium.webdriver.common.by import By
|
6 |
+
from selenium.webdriver.support.ui import WebDriverWait
|
7 |
+
from selenium.webdriver.support import expected_conditions as EC
|
8 |
+
import time
|
9 |
+
import json
|
10 |
+
from selenium.webdriver.common.action_chains import ActionChains
|
11 |
+
from selenium.webdriver.common.keys import Keys
|
12 |
+
from urllib.parse import urlparse, urlunparse
|
13 |
+
from selenium.webdriver.chrome.options import Options
|
14 |
+
from selenium.webdriver.common.action_chains import ActionChains
|
15 |
+
from selenium.webdriver.chrome.options import Options
|
16 |
+
|
17 |
+
#选项
|
18 |
+
chrome_options=Options()
|
19 |
+
|
20 |
+
|
21 |
+
#设置chrome浏览器为无界面模式
|
22 |
+
chrome_options.add_argument('--headless')
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
#下面的两行代码一般是不需要的,至少经过我的测试在windows上是不需要的。但经过我的测试在Ubuntu上如果不加的话等下就会报错WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser,所以要加上
|
27 |
+
chrome_options.add_argument('--no-sandbox')
|
28 |
+
chrome_options.add_argument('--disable-dev-shm-usage')
|
29 |
+
|
30 |
+
|
31 |
+
is_login = True
|
32 |
+
def main():
|
33 |
+
driver = webdriver.Chrome(options=chrome_options)
|
34 |
+
def login():
|
35 |
+
try:
|
36 |
+
driver.get("https://openi.pcl.ac.cn/user/login")
|
37 |
+
|
38 |
+
#driver.implicitly_wait(0.5)
|
39 |
+
|
40 |
+
text_box = driver.find_element(by=By.NAME, value="user_name")
|
41 |
+
password = driver.find_element(by=By.ID, value="input_password")
|
42 |
+
submit_button = driver.find_element(by=By.ID, value="submitId")
|
43 |
+
|
44 |
+
text_box.send_keys("FA***") #账号
|
45 |
+
password.send_keys("NSw///") #密码
|
46 |
+
submit_button.click()
|
47 |
+
|
48 |
+
driver.add_cookie({"name": "foo", "value": "bar"})
|
49 |
+
|
50 |
+
print(driver.get_cookie("foo"))
|
51 |
+
except Exception as e:
|
52 |
+
print(f"An error occurred: {e}")
|
53 |
+
# Function to perform the login and task creation
|
54 |
+
|
55 |
+
if is_login == True:
|
56 |
+
print("Logging in...")
|
57 |
+
login()
|
58 |
+
else:
|
59 |
+
print("跳过登录")
|
60 |
+
def perform_operations(driver):
|
61 |
+
|
62 |
+
|
63 |
+
if is_login == False:
|
64 |
+
driver.get("https://openi.pcl.ac.cn/index.html")
|
65 |
+
# 首先清除由于浏览器打开已有的cookies
|
66 |
+
driver.delete_all_cookies()
|
67 |
+
with open('cookies.txt','r') as f:
|
68 |
+
# 使用json读取cookies 注意读取的是文件 所以用load而不是loads
|
69 |
+
cookies_list = json.load(f)
|
70 |
+
for cookie in cookies_list:
|
71 |
+
driver.add_cookie(cookie)
|
72 |
+
else:
|
73 |
+
pass
|
74 |
+
# 打开新建任务网页
|
75 |
+
driver.get("https://openi.pcl.ac.cn/FASOXO/sd2/grampus/onlineinfer/create") #FASOXO改成你的用户名
|
76 |
+
|
77 |
+
def fill_form(image_address, startup_file):
|
78 |
+
try:
|
79 |
+
# 使用显式等待等待输入框出现,这里等待10秒,可以根据实际情况调整
|
80 |
+
image_input = WebDriverWait(driver, 10).until(
|
81 |
+
EC.presence_of_element_located((By.CSS_SELECTOR, 'input[placeholder="选择镜像或输入镜像地址"]'))
|
82 |
+
)
|
83 |
+
startup_input = WebDriverWait(driver, 10).until(
|
84 |
+
EC.presence_of_element_located((By.CSS_SELECTOR, 'input[placeholder="请输入启动文件"]'))
|
85 |
+
)
|
86 |
+
|
87 |
+
# 填写表单
|
88 |
+
|
89 |
+
image_input.send_keys(image_address)
|
90 |
+
startup_input.send_keys(startup_file)
|
91 |
+
|
92 |
+
# 执行其他操作...
|
93 |
+
|
94 |
+
except Exception as e:
|
95 |
+
print(f"填写表单过程中发生错误: {str(e)}")
|
96 |
+
|
97 |
+
fill_form("192.168.204.22:5000/default-workspace/99280a9940ae44ca8f5892134386fddb/image:sd_v10", "app.py") #填写表单
|
98 |
+
# Wait for the new task button to appear
|
99 |
+
def click_close_button():
|
100 |
+
try:
|
101 |
+
# 使用显式等待等待按钮出现,这里等待10秒,可以根据实际情况调整
|
102 |
+
close_button = WebDriverWait(driver, 10).until(
|
103 |
+
EC.presence_of_element_located((By.CSS_SELECTOR, 'button.el-button.el-button--primary.el-button--small'))
|
104 |
+
)
|
105 |
+
|
106 |
+
# 使用 ActionChains 模拟鼠标移动到按钮上并点击
|
107 |
+
actions = ActionChains(driver)
|
108 |
+
actions.move_to_element(close_button).click().perform()
|
109 |
+
|
110 |
+
# 执行其他操作...
|
111 |
+
|
112 |
+
except Exception as e:
|
113 |
+
print(f"点击关闭按钮过程中发生错误: {str(e)}")
|
114 |
+
def click_create_task_button():
|
115 |
+
try:
|
116 |
+
# 使用显式��待等待按钮出现,这里等待10秒,可以根据实际情况调整
|
117 |
+
create_task_button = WebDriverWait(driver, 10).until(
|
118 |
+
EC.presence_of_element_located((By.CSS_SELECTOR, 'button.el-button.submit-btn'))
|
119 |
+
)
|
120 |
+
|
121 |
+
# 点击按钮
|
122 |
+
# 使用 ActionChains 模拟鼠标移动到按钮上并点击
|
123 |
+
actions = ActionChains(driver)
|
124 |
+
actions.move_to_element(create_task_button).click().perform()
|
125 |
+
|
126 |
+
# 执行其他操作...
|
127 |
+
print("创建任务按钮已按下")
|
128 |
+
except Exception as e:
|
129 |
+
print(f"点击按钮过程中发生错误: {str(e)}")
|
130 |
+
def click_online_inference_link():
|
131 |
+
global current_url
|
132 |
+
try:
|
133 |
+
driver.get("https://openi.pcl.ac.cn/FASOXO/sd2/grampus/onlineinfer")
|
134 |
+
# 使用显式等待等待链接出现,这里等待10秒,可以根据实际情况调整
|
135 |
+
online_inference_link = WebDriverWait(driver, 10).until(
|
136 |
+
EC.element_to_be_clickable((By.XPATH, "//div[@class='op-wrap']//a[contains(text(), '在线推理')]"))
|
137 |
+
)
|
138 |
+
|
139 |
+
|
140 |
+
actions = ActionChains(driver)
|
141 |
+
actions.move_to_element(online_inference_link).click().perform()
|
142 |
+
# 获取当前窗口句柄
|
143 |
+
current_window_handle = driver.current_window_handle
|
144 |
+
|
145 |
+
# 点击链接,在新标签页中打开
|
146 |
+
online_inference_link.send_keys(Keys.CONTROL + Keys.RETURN)
|
147 |
+
|
148 |
+
# 等待新标签页打开
|
149 |
+
WebDriverWait(driver, 10).until(EC.number_of_windows_to_be(2))
|
150 |
+
|
151 |
+
# 获取所有窗口句柄
|
152 |
+
all_window_handles = driver.window_handles
|
153 |
+
|
154 |
+
# 切换到新标签页
|
155 |
+
for window_handle in all_window_handles:
|
156 |
+
if window_handle != current_window_handle:
|
157 |
+
driver.switch_to.window(window_handle)
|
158 |
+
break
|
159 |
+
|
160 |
+
current_url = driver.current_url
|
161 |
+
|
162 |
+
# 去掉端口号
|
163 |
+
parsed_url = urlparse(current_url)
|
164 |
+
netloc_without_port = parsed_url.netloc.split(":")[0]
|
165 |
+
|
166 |
+
# 去掉token部分
|
167 |
+
new_path = parsed_url.path
|
168 |
+
if "?" in new_path:
|
169 |
+
new_path = new_path.split("?")[0]
|
170 |
+
|
171 |
+
# 构建新的URL,省略端口号和token部分
|
172 |
+
new_url = urlunparse((parsed_url.scheme, netloc_without_port, new_path,
|
173 |
+
parsed_url.params, parsed_url.query, parsed_url.fragment))
|
174 |
+
print(f"当前浏览的网页URL: {new_url}")
|
175 |
+
except Exception as e:
|
176 |
+
print(f"点击链接过程中发生错误: {str(e)}")
|
177 |
+
|
178 |
+
def run():
|
179 |
+
if "is-disabled" in new_task_button.get_attribute("class"):
|
180 |
+
print("不可用,restart")
|
181 |
+
driver.quit()
|
182 |
+
main()
|
183 |
+
perform_operations(driver)
|
184 |
+
else:
|
185 |
+
# Click the new task button
|
186 |
+
new_task_button.click()
|
187 |
+
#run()
|
188 |
+
|
189 |
+
# Create a webdriver session
|
190 |
+
click_close_button()
|
191 |
+
click_create_task_button()
|
192 |
+
click_create_task_button()
|
193 |
+
click_create_task_button() #连续点三次创建任务,防止出意外
|
194 |
+
#!sleep 60
|
195 |
+
#click_online_inference_link()
|
196 |
+
# Main loop with a 30-minute interval
|
197 |
+
try:
|
198 |
+
perform_operations(driver)
|
199 |
+
|
200 |
+
print("完成")
|
201 |
+
time.sleep(200) # Sleep for 30 minutes (1800 seconds)
|
202 |
+
|
203 |
+
finally:
|
204 |
+
# Close the browser outside the loop
|
205 |
+
driver.quit()
|
206 |
+
|
207 |
+
|
208 |
+
|
209 |
+
|
210 |
+
import requests
|
211 |
+
def detect(): #测试是否成功
|
212 |
+
url = 'https://mouse-glowing-husky.ngrok-free.app/internal/ping'
|
213 |
+
headers = {'accept': 'application/json'}
|
214 |
+
|
215 |
+
response = requests.get(url, headers=headers)
|
216 |
+
|
217 |
+
if response.status_code == 200:
|
218 |
+
#main() #测试用
|
219 |
+
print("成功")
|
220 |
+
#print(response.json())
|
221 |
+
time.sleep(5)
|
222 |
+
detect()
|
223 |
+
else:
|
224 |
+
print("failed")
|
225 |
+
main()
|
226 |
+
detect()
|
227 |
+
|
228 |
+
while True:
|
229 |
+
main()
|
shutdown.sh
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
while true; do
|
4 |
+
# 获取 PID 为 8 的进程运行时长
|
5 |
+
runtime=$(ps -o etime= -p 8)
|
6 |
+
|
7 |
+
# 解析运行时长中的分钟部分
|
8 |
+
minutes=$(echo $runtime | awk -F: '{print $1}')
|
9 |
+
echo $minutes
|
10 |
+
# 判断运行时长是否大于 29 分钟
|
11 |
+
if [ $minutes -gt 28 ]; then
|
12 |
+
echo "Process with PID 8 has been running for more than 29 minutes. Killing the process..."
|
13 |
+
kill 8
|
14 |
+
else
|
15 |
+
echo "Process with PID 8 is still running within the 29-minute limit."
|
16 |
+
fi
|
17 |
+
sleep 50
|
18 |
+
done
|
the_flask.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
|
3 |
+
from flask import Flask, redirect
|
4 |
+
import requests
|
5 |
+
import os
|
6 |
+
import random
|
7 |
+
from flask import Flask, redirect
|
8 |
+
import requests
|
9 |
+
import os
|
10 |
+
import subprocess
|
11 |
+
ngrok_token3 = "2cZivBw4scg2NQLDwuHPrHSbvkl_43ZbqjNAg5LVnvWXnQX5m"
|
12 |
+
edge3 = "edghts_2cZj7RmeYoekH1kwK6RtexSkm0Z"
|
13 |
+
command_ngrok = f"ngrok tunnel --label edge={edge3} --authtoken={ngrok_token3} --region=ap http://localhost:5006"
|
14 |
+
|
15 |
+
app = Flask(__name__)
|
16 |
+
|
17 |
+
def check_website_availability(url):
|
18 |
+
try:
|
19 |
+
response = requests.get(url)
|
20 |
+
# 检查响应状态码,2xx表示成功
|
21 |
+
return response.status_code // 100 == 2
|
22 |
+
except requests.ConnectionError:
|
23 |
+
return False
|
24 |
+
|
25 |
+
@app.route('/')
|
26 |
+
def redirect_to_website():
|
27 |
+
url = os.getenv('OPENI_GRADIO_URL')
|
28 |
+
server1 = 'https://mlunotebook.openi.org.cn'
|
29 |
+
server2 = 'http://cloudbrain1notebook.openi.org.cn'
|
30 |
+
|
31 |
+
url1 = server1 + url + "/"
|
32 |
+
url2 = server2 + url + "/"
|
33 |
+
|
34 |
+
# 设定跳转概率,25%概率跳转到 {url1}, {url1}sd2/, {url1}sd3/, {url1}sd4/
|
35 |
+
options = [url1, f"{url1}sd2/", f"{url1}sd3/", f"{url1}sd4/"]
|
36 |
+
selected_url = random.choices(options, weights=[0.25, 0.25, 0.25, 0.25])[0]
|
37 |
+
|
38 |
+
options2 = [url2, f"{url2}sd2/", f"{url2}sd3/", f"{url2}sd4/"]
|
39 |
+
selected_url2 = random.choices(options2, weights=[0.25, 0.25, 0.25, 0.25])[0]
|
40 |
+
# 检查是否可访问
|
41 |
+
if check_website_availability(url1):
|
42 |
+
return redirect(selected_url)
|
43 |
+
else:
|
44 |
+
# 如果url1不可访问,直接跳转到url2
|
45 |
+
return redirect(selected_url2)
|
46 |
+
|
47 |
+
if __name__ == '__main__':
|
48 |
+
app.run(debug=False, port=5006)
|
the_flask2.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from flask import Flask, redirect, request, jsonify
|
3 |
+
import requests
|
4 |
+
import os
|
5 |
+
import random
|
6 |
+
|
7 |
+
# ... (Your existing code)
|
8 |
+
app = Flask(__name__)
|
9 |
+
|
10 |
+
def check_website_availability(url):
|
11 |
+
try:
|
12 |
+
response = requests.get(url)
|
13 |
+
# 检查响应状态码,2xx表示成功
|
14 |
+
return response.status_code // 100 == 2
|
15 |
+
except requests.ConnectionError:
|
16 |
+
return False
|
17 |
+
|
18 |
+
@app.route('/', methods=['GET', 'POST'])
|
19 |
+
def redirect_to_website():
|
20 |
+
if request.method == 'POST':
|
21 |
+
# Process POST request and return a link
|
22 |
+
url = os.getenv('OPENI_GRADIO_URL')
|
23 |
+
server1 = 'https://mlunotebook.openi.org.cn'
|
24 |
+
server2 = 'http://cloudbrain1notebook.openi.org.cn'
|
25 |
+
|
26 |
+
url1 = server1 + url + "/"
|
27 |
+
url2 = server2 + url + "/"
|
28 |
+
|
29 |
+
options = [url1, f"{url1}sd2/", f"{url1}sd3/", f"{url1}sd4/"]
|
30 |
+
selected_url = random.choices(options, weights=[0.25, 0.25, 0.25, 0.25])[0]
|
31 |
+
|
32 |
+
options2 = [url2, f"{url2}sd2/", f"{url2}sd3/", f"{url2}sd4/"]
|
33 |
+
selected_url2 = random.choices(options2, weights=[0.25, 0.25, 0.25, 0.25])[0]
|
34 |
+
|
35 |
+
# Check if the URLs are accessible
|
36 |
+
if check_website_availability(url1):
|
37 |
+
return jsonify({"link": selected_url})
|
38 |
+
else:
|
39 |
+
return jsonify({"link": selected_url2})
|
40 |
+
|
41 |
+
else:
|
42 |
+
# Handle GET requests as before
|
43 |
+
url = os.getenv('OPENI_GRADIO_URL')
|
44 |
+
server1 = 'https://mlunotebook.openi.org.cn'
|
45 |
+
server2 = 'http://cloudbrain1notebook.openi.org.cn'
|
46 |
+
|
47 |
+
url1 = server1 + url + "/"
|
48 |
+
url2 = server2 + url + "/"
|
49 |
+
|
50 |
+
options = [f"{url1}sd1/", f"{url1}sd2/", f"{url1}sd3/", f"{url1}sd4/"]
|
51 |
+
selected_url = random.choices(options, weights=[0.25, 0.25, 0.25, 0.25])[0]
|
52 |
+
|
53 |
+
options2 = [f"{url1}sd1/", f"{url2}sd2/", f"{url2}sd3/", f"{url2}sd4/"]
|
54 |
+
selected_url2 = random.choices(options2, weights=[0.25, 0.25, 0.25, 0.25])[0]
|
55 |
+
|
56 |
+
if check_website_availability(url1):
|
57 |
+
return redirect(selected_url)
|
58 |
+
else:
|
59 |
+
return redirect(selected_url2)
|
60 |
+
|
61 |
+
if __name__ == '__main__':
|
62 |
+
app.run(debug=False, port=5006)
|
the_flask_ngrok.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, redirect
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
import random
|
5 |
+
from flask import Flask, redirect
|
6 |
+
import requests
|
7 |
+
import os
|
8 |
+
import subprocess
|
9 |
+
ngrok_token3 = "2cdw5pJsqgsq1igQKeHIpNwTNG7_7LQD3jojKKQ7PzcnNkok5"#'2YypH9d2VXVL78HxF7g0lintH17_2GbtkFNFFngUkTZcyQ4SD'
|
10 |
+
edge3 = "edghts_2czmwh4KcPnhK3tIzfL0Y1aHkha"
|
11 |
+
command_ngrok = f"ngrok tunnel --label edge={edge3} --authtoken={ngrok_token3} --region=ap http://localhost:5006"
|
12 |
+
def ngrok_flask():
|
13 |
+
try:
|
14 |
+
while True:
|
15 |
+
os.system(command_ngrok)
|
16 |
+
except KeyboardInterrupt:
|
17 |
+
print("ngrok启动失败")
|
18 |
+
ngrok_flask()
|
19 |
+
ngrok_flask()
|
train.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.chdir("/t/lora")
|
3 |
+
os.system("/t/lora/venv/bin/python gui.py --disable-dataset-tag-editor & ngrok http 28000 --authtoken=2bgnVJhlLqxUZhS1WyeaAtQA12F_6nQXrapUved4QSxYFn1cD")
|
webui.py
ADDED
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
from fastapi import FastAPI
|
10 |
+
import gradio as gr
|
11 |
+
global app
|
12 |
+
from webui import webui
|
13 |
+
|
14 |
+
app = FastAPI()
|
15 |
+
|
16 |
+
|
17 |
+
startup_timer = timer.startup_timer
|
18 |
+
startup_timer.record("launcher")
|
19 |
+
|
20 |
+
initialize.imports()
|
21 |
+
|
22 |
+
initialize.check_versions()
|
23 |
+
|
24 |
+
|
25 |
+
def create_api(app):
|
26 |
+
from modules.api.api import Api
|
27 |
+
from modules.call_queue import queue_lock
|
28 |
+
|
29 |
+
api = Api(app, queue_lock)
|
30 |
+
return api
|
31 |
+
|
32 |
+
|
33 |
+
def api_only():
|
34 |
+
#from fastapi import FastAPI
|
35 |
+
from modules.shared_cmd_options import cmd_opts
|
36 |
+
|
37 |
+
initialize.initialize()
|
38 |
+
|
39 |
+
app = FastAPI()
|
40 |
+
initialize_util.setup_middleware(app)
|
41 |
+
api = create_api(app)
|
42 |
+
|
43 |
+
from modules import script_callbacks
|
44 |
+
script_callbacks.before_ui_callback()
|
45 |
+
script_callbacks.app_started_callback(None, app)
|
46 |
+
|
47 |
+
print(f"Startup time: {startup_timer.summary()}.")
|
48 |
+
api.launch(
|
49 |
+
server_name="0.0.0.0" if cmd_opts.listen else "127.0.0.1",
|
50 |
+
port=cmd_opts.port if cmd_opts.port else 7861,
|
51 |
+
root_path=f"/{cmd_opts.subpath}" if cmd_opts.subpath else ""
|
52 |
+
)
|
53 |
+
|
54 |
+
|
55 |
+
def webui():
|
56 |
+
from modules.shared_cmd_options import cmd_opts
|
57 |
+
|
58 |
+
launch_api = cmd_opts.api
|
59 |
+
initialize.initialize()
|
60 |
+
|
61 |
+
from modules import shared, ui_tempdir, script_callbacks, ui, progress, ui_extra_networks
|
62 |
+
|
63 |
+
while 1:
|
64 |
+
if shared.opts.clean_temp_dir_at_start:
|
65 |
+
ui_tempdir.cleanup_tmpdr()
|
66 |
+
startup_timer.record("cleanup temp dir")
|
67 |
+
|
68 |
+
script_callbacks.before_ui_callback()
|
69 |
+
startup_timer.record("scripts before_ui_callback")
|
70 |
+
|
71 |
+
shared.demo = ui.create_ui()
|
72 |
+
startup_timer.record("create ui")
|
73 |
+
|
74 |
+
if not cmd_opts.no_gradio_queue:
|
75 |
+
shared.demo.queue(64)
|
76 |
+
|
77 |
+
gradio_auth_creds = list(initialize_util.get_gradio_auth_creds()) or None
|
78 |
+
|
79 |
+
auto_launch_browser = False
|
80 |
+
if os.getenv('SD_WEBUI_RESTARTING') != '1':
|
81 |
+
if shared.opts.auto_launch_browser == "Remote" or cmd_opts.autolaunch:
|
82 |
+
auto_launch_browser = True
|
83 |
+
elif shared.opts.auto_launch_browser == "Local":
|
84 |
+
auto_launch_browser = not cmd_opts.webui_is_non_local
|
85 |
+
|
86 |
+
""""
|
87 |
+
app, local_url, share_url = shared.demo.launch(
|
88 |
+
share=cmd_opts.share,
|
89 |
+
server_name=initialize_util.gradio_server_name(),
|
90 |
+
server_port=cmd_opts.port,
|
91 |
+
ssl_keyfile=cmd_opts.tls_keyfile,
|
92 |
+
ssl_certfile=cmd_opts.tls_certfile,
|
93 |
+
ssl_verify=cmd_opts.disable_tls_verify,
|
94 |
+
debug=cmd_opts.gradio_debug,
|
95 |
+
auth=gradio_auth_creds,
|
96 |
+
inbrowser=auto_launch_browser,
|
97 |
+
prevent_thread_lock=True,
|
98 |
+
allowed_paths=cmd_opts.gradio_allowed_path,
|
99 |
+
app_kwargs={
|
100 |
+
"docs_url": "/docs",
|
101 |
+
"redoc_url": "/redoc",
|
102 |
+
},
|
103 |
+
root_path=f"/{cmd_opts.subpath}" if cmd_opts.subpath else "",
|
104 |
+
)
|
105 |
+
"""
|
106 |
+
app = gr.mount_gradio_app(app, shared.demo, path=os.getenv('OPENI_GRADIO_URL'))
|
107 |
+
return app
|
108 |
+
startup_timer.record("gradio launch")
|
109 |
+
|
110 |
+
# gradio uses a very open CORS policy via app.user_middleware, which makes it possible for
|
111 |
+
# an attacker to trick the user into opening a malicious HTML page, which makes a request to the
|
112 |
+
# running web ui and do whatever the attacker wants, including installing an extension and
|
113 |
+
# running its code. We disable this here. Suggested by RyotaK.
|
114 |
+
app.user_middleware = [x for x in app.user_middleware if x.cls.__name__ != 'CORSMiddleware']
|
115 |
+
|
116 |
+
initialize_util.setup_middleware(app)
|
117 |
+
|
118 |
+
progress.setup_progress_api(app)
|
119 |
+
ui.setup_ui_api(app)
|
120 |
+
|
121 |
+
if launch_api:
|
122 |
+
create_api(app)
|
123 |
+
|
124 |
+
ui_extra_networks.add_pages_to_demo(app)
|
125 |
+
|
126 |
+
startup_timer.record("add APIs")
|
127 |
+
|
128 |
+
with startup_timer.subcategory("app_started_callback"):
|
129 |
+
script_callbacks.app_started_callback(shared.demo, app)
|
130 |
+
|
131 |
+
timer.startup_record = startup_timer.dump()
|
132 |
+
print(f"Startup time: {startup_timer.summary()}.")
|
133 |
+
|
134 |
+
try:
|
135 |
+
while True:
|
136 |
+
server_command = shared.state.wait_for_server_command(timeout=5)
|
137 |
+
if server_command:
|
138 |
+
if server_command in ("stop", "restart"):
|
139 |
+
break
|
140 |
+
else:
|
141 |
+
print(f"Unknown server command: {server_command}")
|
142 |
+
except KeyboardInterrupt:
|
143 |
+
print('Caught KeyboardInterrupt, stopping...')
|
144 |
+
server_command = "stop"
|
145 |
+
|
146 |
+
if server_command == "stop":
|
147 |
+
print("Stopping server...")
|
148 |
+
# If we catch a keyboard interrupt, we want to stop the server and exit.
|
149 |
+
shared.demo.close()
|
150 |
+
break
|
151 |
+
|
152 |
+
# disable auto launch webui in browser for subsequent UI Reload
|
153 |
+
os.environ.setdefault('SD_WEBUI_RESTARTING', '1')
|
154 |
+
|
155 |
+
print('Restarting UI...')
|
156 |
+
shared.demo.close()
|
157 |
+
time.sleep(0.5)
|
158 |
+
startup_timer.reset()
|
159 |
+
script_callbacks.app_reload_callback()
|
160 |
+
startup_timer.record("app reload callback")
|
161 |
+
script_callbacks.script_unloaded_callback()
|
162 |
+
startup_timer.record("scripts unloaded callback")
|
163 |
+
initialize.initialize_rest(reload_script_modules=True)
|
164 |
+
|
165 |
+
|
166 |
+
from modules.shared_cmd_options import cmd_opts
|
167 |
+
|
168 |
+
if cmd_opts.nowebui:
|
169 |
+
api_only()
|
170 |
+
else:
|
171 |
+
app=webui()
|