sig / _requests /[no_use]restart_vits_server.py
Evilmass
new build
65d3d39
raw
history blame
1.82 kB
# coding:utf-8
import os
import re
import requests
from os.path import abspath, dirname, join
# conf
title = "Huggingface"
session = requests.Session()
# from utils import push_msg
def restart_vits_server():
headers = {
"authority": "huggingface.co",
"origin": "https://huggingface.co",
"referer": "https://huggingface.co/login",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
}
data = {
"username": os.environ.get("hf_username"),
"password": os.environ.get("hf_password"),
}
session.post("https://huggingface.co/login", headers=headers, data=data)
rsp = session.get(
"https://huggingface.co/spaces/evi0mo/vits-fastapi-server/settings"
)
csrf = re.findall(r"name=\"csrf\" value=\"(.*?)\">", rsp.text)[0]
res = "init"
restart_headers = {
"authority": "huggingface.co",
"origin": "https://huggingface.co",
"referer": "https://huggingface.co/spaces/evi0mo/vits-fastapi-server/settings",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
}
restart_data = {"csrf": csrf}
session.post(
"https://huggingface.co/spaces/evi0mo/vits-fastapi-server/restart?factory=false",
headers=restart_headers,
data=restart_data,
)
# check
check = session.get(
"https://huggingface.co/api/spaces/evi0mo/vits-fastapi-server/runtime"
)
if check.json()["stage"] == "RUNNING_BUILDING":
res = "success"
vits_logger.info(res)
else:
res = "failed"
vits_logger.error(res)
# push_msg(title, res)
if __name__ == "__main__":
restart_vits_server()