Spaces:
Paused
Paused
Nicholas Bumgarner commited on
Commit ·
9317c1d
1
Parent(s): fdff78d
Remove blocking wait loop; tick() checks daemon log instead
Browse files
app.py
CHANGED
|
@@ -141,7 +141,6 @@ def boot_phoenix():
|
|
| 141 |
return
|
| 142 |
|
| 143 |
init_ring_buffers()
|
| 144 |
-
|
| 145 |
_phoenix_proc = subprocess.Popen(
|
| 146 |
[PHOENIX_BIN, MODEL_PATH, "--chat"],
|
| 147 |
stdout=open(STATE_LOG, 'a'),
|
|
@@ -149,28 +148,10 @@ def boot_phoenix():
|
|
| 149 |
)
|
| 150 |
_update_boot("start", f"Phoenix PID {_phoenix_proc.pid} — loading model (~40s)...")
|
| 151 |
|
| 152 |
-
#
|
| 153 |
-
# The
|
| 154 |
-
#
|
| 155 |
-
|
| 156 |
-
for i in range(120):
|
| 157 |
-
if _phoenix_proc.poll() is not None:
|
| 158 |
-
_update_boot("error", f"Phoenix exited early (code {_phoenix_proc.returncode})")
|
| 159 |
-
return
|
| 160 |
-
try:
|
| 161 |
-
with open(STATE_LOG, 'r') as f:
|
| 162 |
-
lines = f.readlines()[-20:] # only read last 20 lines
|
| 163 |
-
log = ''.join(lines)
|
| 164 |
-
if "Chat Mode" in log:
|
| 165 |
-
_update_boot("ready", "Phoenix ready!", ready=True)
|
| 166 |
-
return
|
| 167 |
-
if any("vocab" in l.lower() or "loaded" in l.lower() or "Loaded" in l for l in lines):
|
| 168 |
-
_update_boot("ready", f"Loading model... ({i}s)", ready=False)
|
| 169 |
-
except Exception:
|
| 170 |
-
pass
|
| 171 |
-
time.sleep(0.5)
|
| 172 |
-
|
| 173 |
-
_update_boot("ready", "Phoenix likely loaded — try chatting!", ready=True)
|
| 174 |
|
| 175 |
|
| 176 |
def init_ring_buffers():
|
|
@@ -369,6 +350,21 @@ with gr.Blocks(title="Phox — Wave-Rider Brain") as demo:
|
|
| 369 |
|
| 370 |
# Periodic status refresh using gr.Timer (Gradio 6.x API)
|
| 371 |
def tick():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
return f"Phase: {_boot_status['phase']} | {_boot_status['message']}"
|
| 373 |
timer1 = gr.Timer(3, active=True)
|
| 374 |
timer1.tick(fn=get_boot_status, outputs=status_json)
|
|
|
|
| 141 |
return
|
| 142 |
|
| 143 |
init_ring_buffers()
|
|
|
|
| 144 |
_phoenix_proc = subprocess.Popen(
|
| 145 |
[PHOENIX_BIN, MODEL_PATH, "--chat"],
|
| 146 |
stdout=open(STATE_LOG, 'a'),
|
|
|
|
| 148 |
)
|
| 149 |
_update_boot("start", f"Phoenix PID {_phoenix_proc.pid} — loading model (~40s)...")
|
| 150 |
|
| 151 |
+
# NO WAIT LOOP — let the tick() function check status
|
| 152 |
+
# The boot_phoenix thread returns immediately so it doesn't
|
| 153 |
+
# block the Gradio event loop.
|
| 154 |
+
# The phox_chat function will handle the case where phoenix isn't ready yet.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
|
| 157 |
def init_ring_buffers():
|
|
|
|
| 350 |
|
| 351 |
# Periodic status refresh using gr.Timer (Gradio 6.x API)
|
| 352 |
def tick():
|
| 353 |
+
# Also check daemon log for status updates
|
| 354 |
+
try:
|
| 355 |
+
with open(STATE_LOG, 'r') as f:
|
| 356 |
+
lines = f.readlines()[-5:]
|
| 357 |
+
log = ''.join(lines)
|
| 358 |
+
with _state_lock:
|
| 359 |
+
if "Chat Mode" in log and not _boot_status.get("ready"):
|
| 360 |
+
_boot_status["ready"] = True
|
| 361 |
+
_boot_status["phase"] = "ready"
|
| 362 |
+
_boot_status["message"] = "Phoenix ready!"
|
| 363 |
+
elif "vocab" in log.lower() and _boot_status["phase"] == "start":
|
| 364 |
+
_boot_status["phase"] = "start"
|
| 365 |
+
_boot_status["message"] = "Loading model..."
|
| 366 |
+
except Exception:
|
| 367 |
+
pass
|
| 368 |
return f"Phase: {_boot_status['phase']} | {_boot_status['message']}"
|
| 369 |
timer1 = gr.Timer(3, active=True)
|
| 370 |
timer1.tick(fn=get_boot_status, outputs=status_json)
|