Spaces:
Running
Running
UI: add Broadcast — run a command on the given session across all online clients
Browse files
app.py
CHANGED
|
@@ -274,6 +274,31 @@ def ui_send(client_label: str, session: str, command: str, timeout: int):
|
|
| 274 |
return f"➡️ sent to `{cid}` [{session}]", ""
|
| 275 |
|
| 276 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
def ui_put_file(client_label: str, fileobj, dest: str):
|
| 278 |
"""Queue a push: send an uploaded file to the selected container."""
|
| 279 |
cid = _strip_dot(client_label)
|
|
@@ -416,6 +441,7 @@ with gr.Blocks(title="NII Relay", analytics_enabled=False) as demo:
|
|
| 416 |
placeholder="nvidia-smi | cd /mnt/data && ls -la | tail -n 50 train.log")
|
| 417 |
with gr.Row():
|
| 418 |
send_btn = gr.Button("Run ▶", variant="primary")
|
|
|
|
| 419 |
send_status = gr.Markdown("")
|
| 420 |
|
| 421 |
history_md = gr.Markdown("_Select a container to see its command history._")
|
|
@@ -450,6 +476,8 @@ with gr.Blocks(title="NII Relay", analytics_enabled=False) as demo:
|
|
| 450 |
[send_status, command_tb])
|
| 451 |
command_tb.submit(ui_send, [client_dd, session_tb, command_tb, timeout_nb],
|
| 452 |
[send_status, command_tb])
|
|
|
|
|
|
|
| 453 |
refresh_btn.click(ui_refresh, [client_dd], [client_dd, history_md])
|
| 454 |
client_dd.change(ui_history, [client_dd], history_md)
|
| 455 |
client_dd.change(_fetched_files, [client_dd], downloads)
|
|
|
|
| 274 |
return f"➡️ sent to `{cid}` [{session}]", ""
|
| 275 |
|
| 276 |
|
| 277 |
+
def ui_broadcast(session: str, command: str, timeout: int):
|
| 278 |
+
"""Queue the same command on the given session for every online container."""
|
| 279 |
+
if not command.strip():
|
| 280 |
+
return "⚠️ empty command", command
|
| 281 |
+
session = (session or "main").strip()
|
| 282 |
+
now = _now()
|
| 283 |
+
sent = []
|
| 284 |
+
with LOCK:
|
| 285 |
+
online = [cid for cid, c in CLIENTS.items()
|
| 286 |
+
if now - c.get("last_seen", 0) < CLIENT_STALE_AFTER]
|
| 287 |
+
for cid in online:
|
| 288 |
+
cmd_id = uuid.uuid4().hex
|
| 289 |
+
COMMANDS[cmd_id] = {
|
| 290 |
+
"id": cmd_id, "client_id": cid, "session": session,
|
| 291 |
+
"command": command, "timeout": int(timeout),
|
| 292 |
+
"status": "pending", "created": now,
|
| 293 |
+
}
|
| 294 |
+
_append_and_trim(cid, cmd_id)
|
| 295 |
+
sent.append(cid)
|
| 296 |
+
if not sent:
|
| 297 |
+
return "⚠️ no online containers to broadcast to", command
|
| 298 |
+
return (f"📡 broadcast to {len(sent)} container(s) [{session}]: "
|
| 299 |
+
+ ", ".join(f"`{c}`" for c in sent), "")
|
| 300 |
+
|
| 301 |
+
|
| 302 |
def ui_put_file(client_label: str, fileobj, dest: str):
|
| 303 |
"""Queue a push: send an uploaded file to the selected container."""
|
| 304 |
cid = _strip_dot(client_label)
|
|
|
|
| 441 |
placeholder="nvidia-smi | cd /mnt/data && ls -la | tail -n 50 train.log")
|
| 442 |
with gr.Row():
|
| 443 |
send_btn = gr.Button("Run ▶", variant="primary")
|
| 444 |
+
broadcast_btn = gr.Button("📡 Broadcast to all online", variant="secondary")
|
| 445 |
send_status = gr.Markdown("")
|
| 446 |
|
| 447 |
history_md = gr.Markdown("_Select a container to see its command history._")
|
|
|
|
| 476 |
[send_status, command_tb])
|
| 477 |
command_tb.submit(ui_send, [client_dd, session_tb, command_tb, timeout_nb],
|
| 478 |
[send_status, command_tb])
|
| 479 |
+
broadcast_btn.click(ui_broadcast, [session_tb, command_tb, timeout_nb],
|
| 480 |
+
[send_status, command_tb])
|
| 481 |
refresh_btn.click(ui_refresh, [client_dd], [client_dd, history_md])
|
| 482 |
client_dd.change(ui_history, [client_dd], history_md)
|
| 483 |
client_dd.change(_fetched_files, [client_dd], downloads)
|