Spaces:
Running
Running
Commit
·
acec2fa
1
Parent(s):
d8e445d
Stop running jobs with `HF_WRITE_TOKEN` validation
Browse files- app_debug.py +44 -3
- run_jobs.py +11 -1
app_debug.py
CHANGED
|
@@ -6,6 +6,7 @@ import gradio as gr
|
|
| 6 |
import os
|
| 7 |
import pipe
|
| 8 |
from io_utils import get_logs_file
|
|
|
|
| 9 |
|
| 10 |
LOG_PATH = "./tmp"
|
| 11 |
CONFIG_PATH = "./cicd/configs/submitted/"
|
|
@@ -56,7 +57,11 @@ def get_log_files():
|
|
| 56 |
|
| 57 |
|
| 58 |
def get_jobs_info_in_queue():
|
| 59 |
-
return [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
def get_queue_status():
|
| 62 |
if len(pipe.jobs) > 0 or pipe.current is not None:
|
|
@@ -68,18 +73,54 @@ def get_queue_status():
|
|
| 68 |
return '<div style="padding-top: 5%">No jobs waiting, please submit an evaluation task from Text-Classification tab.</div>'
|
| 69 |
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
def get_demo():
|
| 72 |
if not os.path.exists(CONFIG_PATH):
|
| 73 |
os.makedirs(CONFIG_PATH)
|
| 74 |
with gr.Row():
|
| 75 |
-
gr.HTML(
|
| 76 |
value=get_queue_status,
|
| 77 |
every=5,
|
| 78 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
with gr.Accordion(label="Log Files", open=True):
|
| 80 |
with gr.Row():
|
| 81 |
gr.Textbox(
|
| 82 |
-
value=get_logs_file,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
)
|
| 84 |
with gr.Row():
|
| 85 |
gr.Files(value=get_log_files, label="Log Files", every=10)
|
|
|
|
| 6 |
import os
|
| 7 |
import pipe
|
| 8 |
from io_utils import get_logs_file
|
| 9 |
+
from app_env import HF_WRITE_TOKEN
|
| 10 |
|
| 11 |
LOG_PATH = "./tmp"
|
| 12 |
CONFIG_PATH = "./cicd/configs/submitted/"
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
def get_jobs_info_in_queue():
|
| 60 |
+
return [
|
| 61 |
+
f"⌛️job id {html.escape(job[0])}: {html.escape(job[2])}<br/>"
|
| 62 |
+
for job in pipe.jobs
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
|
| 66 |
def get_queue_status():
|
| 67 |
if len(pipe.jobs) > 0 or pipe.current is not None:
|
|
|
|
| 73 |
return '<div style="padding-top: 5%">No jobs waiting, please submit an evaluation task from Text-Classification tab.</div>'
|
| 74 |
|
| 75 |
|
| 76 |
+
def can_write_this_space(hf_token):
|
| 77 |
+
# Only the user owning `HF_WRITE_TOKEN` is able to manage this space
|
| 78 |
+
if hf_token == os.getenv(HF_WRITE_TOKEN, ""):
|
| 79 |
+
return True
|
| 80 |
+
return False
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def stop_current_job(hf_token):
|
| 84 |
+
if not can_write_this_space(hf_token):
|
| 85 |
+
gr.Warning(
|
| 86 |
+
"You cannot stop the current job, "
|
| 87 |
+
"because your token does not match `HF_WRITE_TOKEN` in this space."
|
| 88 |
+
)
|
| 89 |
+
return
|
| 90 |
+
|
| 91 |
+
task_uuid = pipe.current
|
| 92 |
+
if not task_uuid:
|
| 93 |
+
gr.Warning("No job in progress")
|
| 94 |
+
return
|
| 95 |
+
|
| 96 |
+
# Interrupt and stop the task
|
| 97 |
+
pipe.current = None
|
| 98 |
+
gr.Info(f"Job {task_uuid} interrupted and stopped by admin.")
|
| 99 |
+
|
| 100 |
+
|
| 101 |
def get_demo():
|
| 102 |
if not os.path.exists(CONFIG_PATH):
|
| 103 |
os.makedirs(CONFIG_PATH)
|
| 104 |
with gr.Row():
|
| 105 |
+
gr.HTML(
|
| 106 |
value=get_queue_status,
|
| 107 |
every=5,
|
| 108 |
)
|
| 109 |
+
with gr.Row():
|
| 110 |
+
hf_write_token_input = gr.Textbox(
|
| 111 |
+
label="HF write token", type="password", placeholder=""
|
| 112 |
+
)
|
| 113 |
+
gr.Button(
|
| 114 |
+
stop_current_job, value="Stop current job", inputs=hf_write_token_input
|
| 115 |
+
)
|
| 116 |
with gr.Accordion(label="Log Files", open=True):
|
| 117 |
with gr.Row():
|
| 118 |
gr.Textbox(
|
| 119 |
+
value=get_logs_file,
|
| 120 |
+
every=0.5,
|
| 121 |
+
lines=10,
|
| 122 |
+
visible=True,
|
| 123 |
+
label="Current Log File",
|
| 124 |
)
|
| 125 |
with gr.Row():
|
| 126 |
gr.Files(value=get_log_files, label="Log Files", every=10)
|
run_jobs.py
CHANGED
|
@@ -160,7 +160,17 @@ def pop_job_from_pipe():
|
|
| 160 |
|
| 161 |
with open(f"./tmp/{task_id}.log", "a") as log_file:
|
| 162 |
p = subprocess.Popen(command, stdout=log_file, stderr=subprocess.STDOUT)
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
pipe.current = None
|
| 165 |
|
| 166 |
|
|
|
|
| 160 |
|
| 161 |
with open(f"./tmp/{task_id}.log", "a") as log_file:
|
| 162 |
p = subprocess.Popen(command, stdout=log_file, stderr=subprocess.STDOUT)
|
| 163 |
+
while pipe.current:
|
| 164 |
+
# Wait for finishing
|
| 165 |
+
p.wait(timeout=1)
|
| 166 |
+
|
| 167 |
+
if not pipe.current:
|
| 168 |
+
# Job interrupted before finishing
|
| 169 |
+
p.terminate()
|
| 170 |
+
p.kill()
|
| 171 |
+
|
| 172 |
+
log_file.write(f"\nJob interrupted by admin at {time.asctime()}\n")
|
| 173 |
+
|
| 174 |
pipe.current = None
|
| 175 |
|
| 176 |
|