Spaces:
Running
Running
admin
commited on
Commit
·
0a7ac7a
1
Parent(s):
34ec6a0
hftk
Browse files- app.py +2 -2
- modules/restart.py +7 -14
- utils.py +1 -5
app.py
CHANGED
@@ -57,7 +57,7 @@ if __name__ == "__main__":
|
|
57 |
task_btn = gr.Button("See current task status")
|
58 |
once_btn = gr.Button("Trigger once manually")
|
59 |
smtp_btn = gr.Button("SMTP test")
|
60 |
-
with gr.Tab("HF
|
61 |
hf_txt = gr.Textbox(
|
62 |
label="Restart a space with permissions",
|
63 |
placeholder="username/repo",
|
@@ -65,7 +65,7 @@ if __name__ == "__main__":
|
|
65 |
)
|
66 |
with gr.Row():
|
67 |
clhf_btn = gr.Button("Clear")
|
68 |
-
hf_btn = gr.Button("Restart to test
|
69 |
|
70 |
with gr.Tab("MS cookie test"):
|
71 |
ms_txt = gr.Textbox(
|
|
|
57 |
task_btn = gr.Button("See current task status")
|
58 |
once_btn = gr.Button("Trigger once manually")
|
59 |
smtp_btn = gr.Button("SMTP test")
|
60 |
+
with gr.Tab("HF token test"):
|
61 |
hf_txt = gr.Textbox(
|
62 |
label="Restart a space with permissions",
|
63 |
placeholder="username/repo",
|
|
|
65 |
)
|
66 |
with gr.Row():
|
67 |
clhf_btn = gr.Button("Clear")
|
68 |
+
hf_btn = gr.Button("Restart to test token validity")
|
69 |
|
70 |
with gr.Tab("MS cookie test"):
|
71 |
ms_txt = gr.Textbox(
|
modules/restart.py
CHANGED
@@ -1,15 +1,18 @@
|
|
1 |
import requests
|
|
|
2 |
from modules.smtp import send_email
|
3 |
from utils import (
|
4 |
HF_DOMAIN,
|
5 |
MS_DOMAIN,
|
6 |
-
|
7 |
MS_HEADER,
|
8 |
TIMEOUT,
|
9 |
PUB_REPOS,
|
10 |
PRI_REPOS,
|
11 |
)
|
12 |
|
|
|
|
|
13 |
|
14 |
def restart_private_studio(repo: str):
|
15 |
response = requests.put(
|
@@ -21,16 +24,6 @@ def restart_private_studio(repo: str):
|
|
21 |
return f"\n{response.text}\n"
|
22 |
|
23 |
|
24 |
-
def restart_private_space(repo: str):
|
25 |
-
response = requests.post(
|
26 |
-
f"{HF_DOMAIN}/api/spaces/{repo}/restart",
|
27 |
-
headers=HF_HEADER,
|
28 |
-
timeout=TIMEOUT,
|
29 |
-
)
|
30 |
-
response.raise_for_status()
|
31 |
-
return f"\n{response.text}\n"
|
32 |
-
|
33 |
-
|
34 |
def restart_repos():
|
35 |
if PUB_REPOS:
|
36 |
repos = PUB_REPOS.split(";")
|
@@ -38,7 +31,7 @@ def restart_repos():
|
|
38 |
private_repo = repo.strip()
|
39 |
print(f"Restarting {private_repo} space & studio...")
|
40 |
restart_private_studio(private_repo)
|
41 |
-
|
42 |
|
43 |
|
44 |
def self_restart():
|
@@ -46,7 +39,7 @@ def self_restart():
|
|
46 |
if PRI_REPOS:
|
47 |
repos = PRI_REPOS.split(";")
|
48 |
for repo in repos:
|
49 |
-
|
50 |
|
51 |
except Exception as e:
|
52 |
send_email(f"Failed to self-restart: {e}")
|
@@ -64,7 +57,7 @@ def test_hf_restart(repo: str):
|
|
64 |
repo = repo.split("/spaces/")[1].split("/")[:2]
|
65 |
repo = "/".join(repo)
|
66 |
|
67 |
-
logs =
|
68 |
logs += f"\nSuccessfully restart {HF_DOMAIN}/spaces/{repo}\n"
|
69 |
|
70 |
except Exception as e:
|
|
|
1 |
import requests
|
2 |
+
from huggingface_hub import HfApi
|
3 |
from modules.smtp import send_email
|
4 |
from utils import (
|
5 |
HF_DOMAIN,
|
6 |
MS_DOMAIN,
|
7 |
+
HF_TK,
|
8 |
MS_HEADER,
|
9 |
TIMEOUT,
|
10 |
PUB_REPOS,
|
11 |
PRI_REPOS,
|
12 |
)
|
13 |
|
14 |
+
HF_API = HfApi(token=HF_TK)
|
15 |
+
|
16 |
|
17 |
def restart_private_studio(repo: str):
|
18 |
response = requests.put(
|
|
|
24 |
return f"\n{response.text}\n"
|
25 |
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
def restart_repos():
|
28 |
if PUB_REPOS:
|
29 |
repos = PUB_REPOS.split(";")
|
|
|
31 |
private_repo = repo.strip()
|
32 |
print(f"Restarting {private_repo} space & studio...")
|
33 |
restart_private_studio(private_repo)
|
34 |
+
HF_API.restart_space(private_repo)
|
35 |
|
36 |
|
37 |
def self_restart():
|
|
|
39 |
if PRI_REPOS:
|
40 |
repos = PRI_REPOS.split(";")
|
41 |
for repo in repos:
|
42 |
+
HF_API.restart_space(repo)
|
43 |
|
44 |
except Exception as e:
|
45 |
send_email(f"Failed to self-restart: {e}")
|
|
|
57 |
repo = repo.split("/spaces/")[1].split("/")[:2]
|
58 |
repo = "/".join(repo)
|
59 |
|
60 |
+
logs = HF_API.restart_space(repo)
|
61 |
logs += f"\nSuccessfully restart {HF_DOMAIN}/spaces/{repo}\n"
|
62 |
|
63 |
except Exception as e:
|
utils.py
CHANGED
@@ -7,7 +7,7 @@ PRI_REPOS = os.getenv("pri_repos")
|
|
7 |
API = os.getenv("api")
|
8 |
EMAIL = os.getenv("email")
|
9 |
SMTP = os.getenv("smtp")
|
10 |
-
|
11 |
MS_CK = os.getenv("msck")
|
12 |
TAG = os.getenv("target")
|
13 |
if not TAG:
|
@@ -29,10 +29,6 @@ MS_DOMAIN = "https://www.modelscope.cn"
|
|
29 |
HEADER = {
|
30 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537"
|
31 |
}
|
32 |
-
HF_HEADER = {
|
33 |
-
"User-Agent": HEADER["User-Agent"],
|
34 |
-
"Cookie": HF_CK,
|
35 |
-
}
|
36 |
MS_HEADER = {
|
37 |
"User-Agent": HEADER["User-Agent"],
|
38 |
"Cookie": MS_CK,
|
|
|
7 |
API = os.getenv("api")
|
8 |
EMAIL = os.getenv("email")
|
9 |
SMTP = os.getenv("smtp")
|
10 |
+
HF_TK = os.getenv("hftk")
|
11 |
MS_CK = os.getenv("msck")
|
12 |
TAG = os.getenv("target")
|
13 |
if not TAG:
|
|
|
29 |
HEADER = {
|
30 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537"
|
31 |
}
|
|
|
|
|
|
|
|
|
32 |
MS_HEADER = {
|
33 |
"User-Agent": HEADER["User-Agent"],
|
34 |
"Cookie": MS_CK,
|