Spaces:
Paused
Paused
Nicholas Bumgarner commited on
Commit ·
488f97e
1
Parent(s): faa1f0b
Add phoenix daemon monitor thread + tick log display
Browse files
app.py
CHANGED
|
@@ -163,11 +163,28 @@ def boot_phoenix():
|
|
| 163 |
stderr=subprocess.STDOUT,
|
| 164 |
)
|
| 165 |
_update_boot("start", f"Phoenix PID {_phoenix_proc.pid} — loading model (~40s)...")
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
|
| 173 |
def init_ring_buffers():
|
|
@@ -352,7 +369,18 @@ with gr.Blocks(title="Phox — Wave-Rider Brain") as demo:
|
|
| 352 |
|
| 353 |
# Periodic status refresh using gr.Timer (Gradio 6.x API)
|
| 354 |
def tick():
|
| 355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
timer1 = gr.Timer(3, active=True)
|
| 357 |
timer1.tick(fn=get_boot_status, outputs=status_json)
|
| 358 |
timer2 = gr.Timer(2, active=True)
|
|
|
|
| 163 |
stderr=subprocess.STDOUT,
|
| 164 |
)
|
| 165 |
_update_boot("start", f"Phoenix PID {_phoenix_proc.pid} — loading model (~40s)...")
|
| 166 |
+
# Start a monitor thread to check when phoenix enters chat mode
|
| 167 |
+
threading.Thread(target=_monitor_phoenix, daemon=True).start()
|
| 168 |
+
|
| 169 |
+
def _monitor_phoenix():
|
| 170 |
+
"""Background thread: watches daemon log for 'Chat Mode', then sets ready."""
|
| 171 |
+
import time as _time
|
| 172 |
+
for _ in range(120): # Check for up to 2 minutes
|
| 173 |
+
_time.sleep(0.5)
|
| 174 |
+
try:
|
| 175 |
+
with open(STATE_LOG, 'r') as f:
|
| 176 |
+
log = f.read()
|
| 177 |
+
if "Chat Mode" in log or "ready" in log.lower():
|
| 178 |
+
_update_boot("ready", "Phoenix is ready to chat!")
|
| 179 |
+
return
|
| 180 |
+
# Check if process died
|
| 181 |
+
with _state_lock:
|
| 182 |
+
if _phoenix_proc and _phoenix_proc.poll() is not None:
|
| 183 |
+
_update_boot("error", f"Phoenix exited (code {_phoenix_proc.returncode})")
|
| 184 |
+
return
|
| 185 |
+
except (FileNotFoundError, PermissionError):
|
| 186 |
+
pass
|
| 187 |
+
_update_boot("ready", "Phoenix boot timed out — may still be initializing.")
|
| 188 |
|
| 189 |
|
| 190 |
def init_ring_buffers():
|
|
|
|
| 369 |
|
| 370 |
# Periodic status refresh using gr.Timer (Gradio 6.x API)
|
| 371 |
def tick():
|
| 372 |
+
base = f"Phase: {_boot_status['phase']} | {_boot_status['message']}"
|
| 373 |
+
# Show last line of daemon log if available
|
| 374 |
+
try:
|
| 375 |
+
with open(STATE_LOG, 'r') as f:
|
| 376 |
+
lines = f.readlines()
|
| 377 |
+
if lines:
|
| 378 |
+
last = lines[-1].strip()
|
| 379 |
+
if last:
|
| 380 |
+
base += f"\n[daemon] {last}"
|
| 381 |
+
except (FileNotFoundError, PermissionError):
|
| 382 |
+
pass
|
| 383 |
+
return base
|
| 384 |
timer1 = gr.Timer(3, active=True)
|
| 385 |
timer1.tick(fn=get_boot_status, outputs=status_json)
|
| 386 |
timer2 = gr.Timer(2, active=True)
|