yetessam commited on
Commit
3aef5a5
·
verified ·
1 Parent(s): a3ba8f9

Create check_gui.py

Browse files
Files changed (1) hide show
  1. checks/check_gui.py +58 -0
checks/check_gui.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ def __init__(self, title="🖥️ Status Monitor"):
11
+ self._log = ""
12
+ self._is_shutdown = False
13
+
14
+ with gr.Blocks() as self._ui:
15
+ gr.Markdown(f"## {title}")
16
+
17
+ self._log_output = gr.TextArea(
18
+ label="Log Output", value="(log starts here)", lines=12, interactive=False
19
+ )
20
+ self._state = gr.State(self._log)
21
+
22
+ self._shutdown_btn = gr.Button("Shutdown")
23
+ self._shutdown_btn.click(
24
+ fn=self._on_shutdown,
25
+ inputs=self._state,
26
+ outputs=[self._log_output, self._state]
27
+ )
28
+
29
+ def append(self, message: str):
30
+ """Append a message to the UI log."""
31
+ self._log += f"\n{message}"
32
+ self._log_output.update(value=self._log)
33
+
34
+ def shutdown(self):
35
+ """Trigger the shutdown sequence manually."""
36
+ self._on_shutdown(self._log)
37
+
38
+ def launch(self, **kwargs):
39
+ """Launch the UI."""
40
+ self._ui.launch(**kwargs)
41
+
42
+ def _on_shutdown(self, current_log):
43
+ """Internal shutdown logic."""
44
+ if not self._is_shutdown:
45
+ self._is_shutdown = True
46
+ current_log += "\n🛑 Shutdown requested."
47
+ return gr.update(value=current_log), current_log
48
+
49
+
50
+ # Usage
51
+ #ui = StatusUI("🚦 Endpoint Logger")
52
+ #ui.launch()
53
+
54
+ # Elsewhere in your code:
55
+ #ui.append("Checking endpoint…")
56
+ #ui.append("✅ Model responded OK.")
57
+ #ui.shutdown()
58
+