Spaces:
Running
Running
admin
commited on
Commit
·
609a724
1
Parent(s):
78ecc48
add ms ck test
Browse files- app.py +32 -12
- modules/restart.py +32 -6
- utils.py +4 -0
app.py
CHANGED
@@ -6,8 +6,8 @@ from datetime import datetime
|
|
6 |
from modules.smtp import send_email
|
7 |
from modules.activate import trigger
|
8 |
from modules.times import fix_datetime, time_diff
|
9 |
-
from modules.restart import self_restart,
|
10 |
-
from utils import START_TIME,
|
11 |
|
12 |
|
13 |
def run_schedule():
|
@@ -51,18 +51,31 @@ def tasklst():
|
|
51 |
if __name__ == "__main__":
|
52 |
monitor()
|
53 |
with gr.Blocks() as demo:
|
54 |
-
gr.Markdown("# Keep Spaces Alive")
|
55 |
with gr.Row():
|
56 |
with gr.Column():
|
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 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
with gr.Column():
|
68 |
status_bar = gr.Textbox(label="Status", show_copy_button=True)
|
@@ -72,10 +85,17 @@ if __name__ == "__main__":
|
|
72 |
task_btn.click(fn=tasklst, outputs=[status_bar, logs_bar])
|
73 |
once_btn.click(fn=trigger, outputs=[status_bar, logs_bar])
|
74 |
smtp_btn.click(fn=send_email, outputs=[status_bar, logs_bar])
|
75 |
-
|
76 |
-
fn=
|
77 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
outputs=[status_bar, logs_bar],
|
79 |
)
|
|
|
80 |
|
81 |
demo.launch()
|
|
|
6 |
from modules.smtp import send_email
|
7 |
from modules.activate import trigger
|
8 |
from modules.times import fix_datetime, time_diff
|
9 |
+
from modules.restart import self_restart, test_hf_restart, test_ms_restart
|
10 |
+
from utils import START_TIME, PERIOD, DELAY
|
11 |
|
12 |
|
13 |
def run_schedule():
|
|
|
51 |
if __name__ == "__main__":
|
52 |
monitor()
|
53 |
with gr.Blocks() as demo:
|
54 |
+
gr.Markdown("# Keep Spaces/Studios Alive")
|
55 |
with gr.Row():
|
56 |
with gr.Column():
|
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 cookie test"):
|
61 |
+
hf_txt = gr.Textbox(
|
62 |
+
label="Restart a space with permissions",
|
63 |
+
placeholder="username/repo",
|
64 |
+
value="kakamond/cmd_inject",
|
65 |
+
)
|
66 |
+
with gr.Row():
|
67 |
+
clhf_btn = gr.Button("Clear")
|
68 |
+
hf_btn = gr.Button("Restart to test cookie validity")
|
69 |
+
|
70 |
+
with gr.Tab("MS cookie test"):
|
71 |
+
ms_txt = gr.Textbox(
|
72 |
+
label="Restart a studio with permissions",
|
73 |
+
placeholder="username/repo",
|
74 |
+
value="kakamond/cmd_inject",
|
75 |
+
)
|
76 |
+
with gr.Row():
|
77 |
+
clms_btn = gr.Button("Clear")
|
78 |
+
ms_btn = gr.Button("Restart to test cookie validity")
|
79 |
|
80 |
with gr.Column():
|
81 |
status_bar = gr.Textbox(label="Status", show_copy_button=True)
|
|
|
85 |
task_btn.click(fn=tasklst, outputs=[status_bar, logs_bar])
|
86 |
once_btn.click(fn=trigger, outputs=[status_bar, logs_bar])
|
87 |
smtp_btn.click(fn=send_email, outputs=[status_bar, logs_bar])
|
88 |
+
hf_btn.click(
|
89 |
+
fn=test_hf_restart,
|
90 |
+
inputs=[hf_txt],
|
91 |
+
outputs=[status_bar, logs_bar],
|
92 |
+
)
|
93 |
+
clhf_btn.click(fn=lambda: None, outputs=hf_txt)
|
94 |
+
ms_btn.click(
|
95 |
+
fn=test_ms_restart,
|
96 |
+
inputs=[ms_txt],
|
97 |
outputs=[status_bar, logs_bar],
|
98 |
)
|
99 |
+
clms_btn.click(fn=lambda: None, outputs=ms_txt)
|
100 |
|
101 |
demo.launch()
|
modules/restart.py
CHANGED
@@ -1,15 +1,22 @@
|
|
1 |
import requests
|
2 |
from modules.smtp import send_email
|
3 |
-
from utils import HF_DOMAIN,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
|
6 |
def restart_private_space(repo: str):
|
7 |
response = requests.post(
|
8 |
f"{HF_DOMAIN}/api/spaces/{repo}/restart",
|
9 |
-
headers=
|
10 |
-
"User-Agent": HEADER["User-Agent"],
|
11 |
-
"cookie": HF_CK,
|
12 |
-
},
|
13 |
timeout=TIMEOUT,
|
14 |
)
|
15 |
response.raise_for_status()
|
@@ -24,10 +31,13 @@ def self_restart():
|
|
24 |
|
25 |
|
26 |
# UI func
|
27 |
-
def
|
28 |
status = "Success"
|
29 |
logs = None
|
30 |
try:
|
|
|
|
|
|
|
31 |
logs = restart_private_space(repo)
|
32 |
logs += f"\nSuccessfully restart {HF_DOMAIN}/spaces/{repo}\n"
|
33 |
|
@@ -35,3 +45,19 @@ def test_restart(repo):
|
|
35 |
status = f"{e}"
|
36 |
|
37 |
return status, logs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import requests
|
2 |
from modules.smtp import send_email
|
3 |
+
from utils import HF_DOMAIN, MS_DOMAIN, HF_HEADER, MS_HEADER, TIMEOUT
|
4 |
+
|
5 |
+
|
6 |
+
def restart_private_studio(repo: str):
|
7 |
+
response = requests.put(
|
8 |
+
f"{MS_DOMAIN}/api/v1/studio/{repo}/reset_restart",
|
9 |
+
headers=MS_HEADER,
|
10 |
+
timeout=TIMEOUT,
|
11 |
+
)
|
12 |
+
response.raise_for_status()
|
13 |
+
return f"\n{response.text}\n"
|
14 |
|
15 |
|
16 |
def restart_private_space(repo: str):
|
17 |
response = requests.post(
|
18 |
f"{HF_DOMAIN}/api/spaces/{repo}/restart",
|
19 |
+
headers=HF_HEADER,
|
|
|
|
|
|
|
20 |
timeout=TIMEOUT,
|
21 |
)
|
22 |
response.raise_for_status()
|
|
|
31 |
|
32 |
|
33 |
# UI func
|
34 |
+
def test_hf_restart(repo):
|
35 |
status = "Success"
|
36 |
logs = None
|
37 |
try:
|
38 |
+
if not repo:
|
39 |
+
raise ValueError("Empty repo!")
|
40 |
+
|
41 |
logs = restart_private_space(repo)
|
42 |
logs += f"\nSuccessfully restart {HF_DOMAIN}/spaces/{repo}\n"
|
43 |
|
|
|
45 |
status = f"{e}"
|
46 |
|
47 |
return status, logs
|
48 |
+
|
49 |
+
|
50 |
+
def test_ms_restart(repo):
|
51 |
+
status = "Success"
|
52 |
+
logs = None
|
53 |
+
try:
|
54 |
+
if not repo:
|
55 |
+
raise ValueError("Empty repo!")
|
56 |
+
|
57 |
+
logs = restart_private_studio(repo)
|
58 |
+
logs += f"\nSuccessfully restart {MS_DOMAIN}/studios/{repo}\n"
|
59 |
+
|
60 |
+
except Exception as e:
|
61 |
+
status = f"{e}"
|
62 |
+
|
63 |
+
return status, logs
|
utils.py
CHANGED
@@ -27,6 +27,10 @@ MS_DOMAIN = "https://www.modelscope.cn"
|
|
27 |
HEADER = {
|
28 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537"
|
29 |
}
|
|
|
|
|
|
|
|
|
30 |
MS_HEADER = {
|
31 |
"User-Agent": HEADER["User-Agent"],
|
32 |
"Cookie": MS_CK,
|
|
|
27 |
HEADER = {
|
28 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537"
|
29 |
}
|
30 |
+
HF_HEADER = {
|
31 |
+
"User-Agent": HEADER["User-Agent"],
|
32 |
+
"Cookie": HF_CK,
|
33 |
+
}
|
34 |
MS_HEADER = {
|
35 |
"User-Agent": HEADER["User-Agent"],
|
36 |
"Cookie": MS_CK,
|