Spaces:
Paused
Paused
Nicholas Bumgarner commited on
Commit ·
4eb0c7c
1
Parent(s): 9317c1d
Manual boot: tokenizer loads at startup, full boot on button click. Non-blocking stop_phoenix.
Browse files
app.py
CHANGED
|
@@ -227,22 +227,14 @@ def poll_predictions(timeout_s=CHAT_TIMEOUT_S):
|
|
| 227 |
|
| 228 |
|
| 229 |
def start_phoenix_manual():
|
| 230 |
-
"""Start phoenix
|
| 231 |
global _phoenix_proc
|
| 232 |
with _state_lock:
|
| 233 |
if _phoenix_proc and _phoenix_proc.poll() is None:
|
| 234 |
return "Already running"
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
return "Model not downloaded yet"
|
| 239 |
-
init_ring_buffers()
|
| 240 |
-
_phoenix_proc = subprocess.Popen(
|
| 241 |
-
[PHOENIX_BIN, MODEL_PATH, "--chat"],
|
| 242 |
-
stdout=open(STATE_LOG, 'a'),
|
| 243 |
-
stderr=subprocess.STDOUT,
|
| 244 |
-
)
|
| 245 |
-
return f"Started (PID {_phoenix_proc.pid})"
|
| 246 |
|
| 247 |
|
| 248 |
def stop_phoenix():
|
|
@@ -253,27 +245,17 @@ def stop_phoenix():
|
|
| 253 |
ring_push(_ring_in_mm, SENTINEL_QUIT)
|
| 254 |
except Exception:
|
| 255 |
pass
|
| 256 |
-
time.sleep(0.5)
|
| 257 |
-
|
| 258 |
if _phoenix_proc and _phoenix_proc.poll() is None:
|
| 259 |
_phoenix_proc.terminate()
|
| 260 |
-
|
| 261 |
-
_phoenix_proc.wait(timeout=10)
|
| 262 |
-
except subprocess.TimeoutExpired:
|
| 263 |
-
_phoenix_proc.kill()
|
| 264 |
-
|
| 265 |
if _ring_in_mm:
|
| 266 |
-
_ring_in_mm.close()
|
| 267 |
-
_ring_in_mm = None
|
| 268 |
if _ring_out_mm:
|
| 269 |
-
_ring_out_mm.close()
|
| 270 |
-
_ring_out_mm = None
|
| 271 |
if _ring_in_fd is not None:
|
| 272 |
-
os.close(_ring_in_fd)
|
| 273 |
-
_ring_in_fd = None
|
| 274 |
if _ring_out_fd is not None:
|
| 275 |
-
os.close(_ring_out_fd)
|
| 276 |
-
_ring_out_fd = None
|
| 277 |
return "Stopped"
|
| 278 |
|
| 279 |
|
|
@@ -350,21 +332,6 @@ with gr.Blocks(title="Phox — Wave-Rider Brain") as demo:
|
|
| 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)
|
|
@@ -373,10 +340,12 @@ with gr.Blocks(title="Phox — Wave-Rider Brain") as demo:
|
|
| 373 |
|
| 374 |
|
| 375 |
if __name__ == "__main__":
|
| 376 |
-
#
|
| 377 |
-
|
|
|
|
| 378 |
_boot_thread.start()
|
| 379 |
-
|
|
|
|
| 380 |
demo.queue().launch(
|
| 381 |
server_name="0.0.0.0",
|
| 382 |
server_port=int(os.environ.get("PORT", 7860)),
|
|
|
|
| 227 |
|
| 228 |
|
| 229 |
def start_phoenix_manual():
|
| 230 |
+
"""Start phoenix: download model, build binary, launch in chat mode."""
|
| 231 |
global _phoenix_proc
|
| 232 |
with _state_lock:
|
| 233 |
if _phoenix_proc and _phoenix_proc.poll() is None:
|
| 234 |
return "Already running"
|
| 235 |
+
# Run boot in a thread so the Gradio event loop isn't blocked
|
| 236 |
+
threading.Thread(target=boot_phoenix, daemon=True).start()
|
| 237 |
+
return " Booting... check Engine Status for progress"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
|
| 240 |
def stop_phoenix():
|
|
|
|
| 245 |
ring_push(_ring_in_mm, SENTINEL_QUIT)
|
| 246 |
except Exception:
|
| 247 |
pass
|
|
|
|
|
|
|
| 248 |
if _phoenix_proc and _phoenix_proc.poll() is None:
|
| 249 |
_phoenix_proc.terminate()
|
| 250 |
+
# Don't wait — let it terminate in background
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
if _ring_in_mm:
|
| 252 |
+
_ring_in_mm.close(); _ring_in_mm = None
|
|
|
|
| 253 |
if _ring_out_mm:
|
| 254 |
+
_ring_out_mm.close(); _ring_out_mm = None
|
|
|
|
| 255 |
if _ring_in_fd is not None:
|
| 256 |
+
os.close(_ring_in_fd); _ring_in_fd = None
|
|
|
|
| 257 |
if _ring_out_fd is not None:
|
| 258 |
+
os.close(_ring_out_fd); _ring_out_fd = None
|
|
|
|
| 259 |
return "Stopped"
|
| 260 |
|
| 261 |
|
|
|
|
| 332 |
|
| 333 |
# Periodic status refresh using gr.Timer (Gradio 6.x API)
|
| 334 |
def tick():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
return f"Phase: {_boot_status['phase']} | {_boot_status['message']}"
|
| 336 |
timer1 = gr.Timer(3, active=True)
|
| 337 |
timer1.tick(fn=get_boot_status, outputs=status_json)
|
|
|
|
| 340 |
|
| 341 |
|
| 342 |
if __name__ == "__main__":
|
| 343 |
+
# Load tokenizer at startup only (fast, ~32MB)
|
| 344 |
+
# Model download + binary build happen on button click
|
| 345 |
+
_boot_thread = threading.Thread(target=load_tokenizer, daemon=True)
|
| 346 |
_boot_thread.start()
|
| 347 |
+
# Don't auto-boot phoenix — user clicks "Start Engine"
|
| 348 |
+
_update_boot("idle", "Click 'Start Engine' to boot the BQSM wave-rider")
|
| 349 |
demo.queue().launch(
|
| 350 |
server_name="0.0.0.0",
|
| 351 |
server_port=int(os.environ.get("PORT", 7860)),
|