Spaces:
Sleeping
Sleeping
Delete ui/statusui.py
Browse files- ui/statusui.py +0 -68
ui/statusui.py
DELETED
|
@@ -1,68 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
|
| 3 |
-
class StatusUI:
|
| 4 |
-
"""
|
| 5 |
-
A Gradio-based status logger with gr.update().
|
| 6 |
-
Use `append(msg)` to update the log,
|
| 7 |
-
and `shutdown()` to close out the session.
|
| 8 |
-
"""
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def __init__(self, title="🖥️ Status Monitor"):
|
| 12 |
-
self._log = ""
|
| 13 |
-
self._is_shutdown = False
|
| 14 |
-
|
| 15 |
-
with gr.Blocks() as self._ui:
|
| 16 |
-
gr.Markdown(f"## {title}")
|
| 17 |
-
|
| 18 |
-
self._log_output = gr.TextArea(
|
| 19 |
-
label="Log Output", value="(log starts here)", lines=12, interactive=False
|
| 20 |
-
)
|
| 21 |
-
self._state = gr.State(self._log)
|
| 22 |
-
|
| 23 |
-
self._shutdown_btn = gr.Button("Shutdown")
|
| 24 |
-
self._shutdown_btn.click(
|
| 25 |
-
fn=self._on_shutdown,
|
| 26 |
-
inputs=self._state,
|
| 27 |
-
outputs=[self._log_output, self._state]
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
def append(self, message: str):
|
| 32 |
-
|
| 33 |
-
print(message)
|
| 34 |
-
if not self._is_shutdown:
|
| 35 |
-
# Add message + force UI update
|
| 36 |
-
self._log += f"\n {message}"
|
| 37 |
-
self._log_output = gr.TextArea.update(
|
| 38 |
-
value=self._log,
|
| 39 |
-
# Optional: Ensure visual consistency
|
| 40 |
-
interactive=False,
|
| 41 |
-
autoscroll=True
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
def shutdown(self):
|
| 45 |
-
"""Trigger the shutdown sequence manually."""
|
| 46 |
-
self._on_shutdown(self._log)
|
| 47 |
-
|
| 48 |
-
def launch(self, **kwargs):
|
| 49 |
-
"""Launch the UI."""
|
| 50 |
-
self._ui.launch(**kwargs)
|
| 51 |
-
|
| 52 |
-
def _on_shutdown(self, current_log):
|
| 53 |
-
"""Internal shutdown logic."""
|
| 54 |
-
if not self._is_shutdown:
|
| 55 |
-
self._is_shutdown = True
|
| 56 |
-
current_log += "\n🛑 Shutdown requested."
|
| 57 |
-
return gr.update(value=current_log), current_log
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
# Usage
|
| 61 |
-
#ui = StatusUI("🚦 Endpoint Logger")
|
| 62 |
-
#ui.launch()
|
| 63 |
-
|
| 64 |
-
# Elsewhere in your code:
|
| 65 |
-
#ui.append("Checking endpoint…")
|
| 66 |
-
#ui.append("✅ Model responded OK.")
|
| 67 |
-
#ui.shutdown()
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|