Update server.py
Browse files
server.py
CHANGED
|
@@ -46,6 +46,7 @@ def update():
|
|
| 46 |
# 安装 p7zip-full
|
| 47 |
os.system("sudo apt install p7zip-full -y")
|
| 48 |
os.system("pip install -U kaggle")
|
|
|
|
| 49 |
os.system("pip install ruamel.yaml") # install ruamel.yaml to solve the import issue
|
| 50 |
print('-----------更新软件包列表结束-------------')
|
| 51 |
update()
|
|
@@ -111,6 +112,59 @@ def ssh():
|
|
| 111 |
# ssh()
|
| 112 |
clear_output()
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
|
| 116 |
def frp():
|
|
@@ -124,9 +178,9 @@ def frp():
|
|
| 124 |
config_file.write(config_data)
|
| 125 |
# frpc 启动命令和参数
|
| 126 |
frpc_cmd = ['/content/frp/frpc', '-c', config_file_path]
|
| 127 |
-
subprocess.Popen(frpc_cmd)
|
| 128 |
print('-----------FPR结束-------------')
|
| 129 |
-
|
| 130 |
|
| 131 |
def SillyTavern():
|
| 132 |
print('-----------SillyTavern开始-------------')
|
|
@@ -156,11 +210,9 @@ def SillyTavern():
|
|
| 156 |
# !git clone https://github.com/SillyTavern/SillyTavern.git
|
| 157 |
# 强制替换掉备份
|
| 158 |
# !rsync -a --delete /SillyTavern/* /sillytavern/
|
| 159 |
-
|
| 160 |
-
|
| 161 |
# threading.Thread(target=repeat_task, daemon=True).start()
|
| 162 |
-
|
| 163 |
-
frp()
|
| 164 |
os.chdir('/sillytavern')
|
| 165 |
|
| 166 |
subprocess.run('yes | sh /sillytavern/start.sh', shell=True, check=True)
|
|
@@ -172,4 +224,5 @@ def SillyTavern():
|
|
| 172 |
# 'yes | sh start.sh -y'
|
| 173 |
# ]
|
| 174 |
# run_commands(commands)
|
| 175 |
-
SillyTavern()
|
|
|
|
|
|
| 46 |
# 安装 p7zip-full
|
| 47 |
os.system("sudo apt install p7zip-full -y")
|
| 48 |
os.system("pip install -U kaggle")
|
| 49 |
+
os.system("apt-get install inotify-tools")
|
| 50 |
os.system("pip install ruamel.yaml") # install ruamel.yaml to solve the import issue
|
| 51 |
print('-----------更新软件包列表结束-------------')
|
| 52 |
update()
|
|
|
|
| 112 |
# ssh()
|
| 113 |
clear_output()
|
| 114 |
|
| 115 |
+
def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None):
|
| 116 |
+
session = session or requests.Session()
|
| 117 |
+
retry = Retry(total=retries, backoff_factor=backoff_factor, status_forcelist=status_forcelist)
|
| 118 |
+
adapter = HTTPAdapter(max_retries=retry)
|
| 119 |
+
session.mount('http://', adapter)
|
| 120 |
+
session.mount('https://', adapter)
|
| 121 |
+
return session
|
| 122 |
+
def check_api1():
|
| 123 |
+
while True:
|
| 124 |
+
try:
|
| 125 |
+
url = "http://127.0.0.1:8000/v1"
|
| 126 |
+
response = requests.get(url, timeout=30)
|
| 127 |
+
try:
|
| 128 |
+
response_json = response.json()
|
| 129 |
+
if response_json.get("detail") in ("Forbidden", "Forbidden"):
|
| 130 |
+
print("SillyTavern已经启动")
|
| 131 |
+
break # 接口正常,退出循环
|
| 132 |
+
else:
|
| 133 |
+
print("SillyTavern未启动" )
|
| 134 |
+
except json.JSONDecodeError:
|
| 135 |
+
# 如果响应内容不是有效的 JSON,打印错误信息
|
| 136 |
+
print("SillyTavern未启动2")
|
| 137 |
+
except requests.exceptions.RequestException as e:
|
| 138 |
+
print("SillyTavern未启动3")
|
| 139 |
+
time.sleep(5)
|
| 140 |
+
|
| 141 |
+
# print('开始检测接口状态')
|
| 142 |
+
# while True:
|
| 143 |
+
# url = f"{sd_url}/sdapi/v1/txt2img"
|
| 144 |
+
# try:
|
| 145 |
+
# response = requests_retry_session().get(url, timeout=30)
|
| 146 |
+
# response.raise_for_status()
|
| 147 |
+
# response_json = response.json()
|
| 148 |
+
# if "detail" in response_json and response_json["detail"] in ("Method Not Allowed", "Not Found"):
|
| 149 |
+
# print("接口正常")
|
| 150 |
+
# else:
|
| 151 |
+
# print("接口返回信息:", response_json)
|
| 152 |
+
# except requests.exceptions.HTTPError as e:
|
| 153 |
+
# print("接口正常2")
|
| 154 |
+
# except requests.exceptions.ConnectionError as e:
|
| 155 |
+
# print(f"接口异常1: {e}")
|
| 156 |
+
# threading.Thread(target=Frpc, daemon=True).start()
|
| 157 |
+
# break
|
| 158 |
+
# except requests.exceptions.Timeout as e:
|
| 159 |
+
# print(f"接口异常2: {e}")
|
| 160 |
+
# threading.Thread(target=Frpc, daemon=True).start()
|
| 161 |
+
# break
|
| 162 |
+
|
| 163 |
+
# except requests.exceptions.RequestException as e:
|
| 164 |
+
# print(f"接口异常3: {e}")
|
| 165 |
+
# threading.Thread(target=Frpc, daemon=True).start()
|
| 166 |
+
# break
|
| 167 |
+
# time.sleep(5)
|
| 168 |
|
| 169 |
|
| 170 |
def frp():
|
|
|
|
| 178 |
config_file.write(config_data)
|
| 179 |
# frpc 启动命令和参数
|
| 180 |
frpc_cmd = ['/content/frp/frpc', '-c', config_file_path]
|
| 181 |
+
# subprocess.Popen(frpc_cmd)
|
| 182 |
print('-----------FPR结束-------------')
|
| 183 |
+
/content/frp/frpc -c /content/frp/frpc.ini
|
| 184 |
|
| 185 |
def SillyTavern():
|
| 186 |
print('-----------SillyTavern开始-------------')
|
|
|
|
| 210 |
# !git clone https://github.com/SillyTavern/SillyTavern.git
|
| 211 |
# 强制替换掉备份
|
| 212 |
# !rsync -a --delete /SillyTavern/* /sillytavern/
|
| 213 |
+
|
|
|
|
| 214 |
# threading.Thread(target=repeat_task, daemon=True).start()
|
| 215 |
+
threading.Thread(target=Oneapi, daemon=True).start()
|
|
|
|
| 216 |
os.chdir('/sillytavern')
|
| 217 |
|
| 218 |
subprocess.run('yes | sh /sillytavern/start.sh', shell=True, check=True)
|
|
|
|
| 224 |
# 'yes | sh start.sh -y'
|
| 225 |
# ]
|
| 226 |
# run_commands(commands)
|
| 227 |
+
threading.Thread(target=SillyTavern, daemon=True).start()
|
| 228 |
+
check_api1()
|