Spaces:
Paused
Paused
Nicholas Bumgarner commited on
Commit ·
adcbc7e
1
Parent(s): d0f24f6
Download pre-built phoenix binary from HF Hub instead of compiling on Space
Browse files
app.py
CHANGED
|
@@ -4,11 +4,10 @@ Phox on Hugging Face Spaces — BQSM Wave-Rider Inference Engine.
|
|
| 4 |
|
| 5 |
This app wraps the Phoenix Brain C inference binary in a Gradio interface.
|
| 6 |
At Space startup it:
|
| 7 |
-
1. Downloads the
|
| 8 |
-
2.
|
| 9 |
-
3.
|
| 10 |
-
4.
|
| 11 |
-
5. Provides a chat UI via Gradio
|
| 12 |
|
| 13 |
The phoenix binary runs on CPU (AVX2) — the wave-rider physics engine
|
| 14 |
doesn't use PyTorch, so ZeroGPU doesn't accelerate it directly.
|
|
@@ -117,22 +116,32 @@ def boot_phoenix():
|
|
| 117 |
_update_boot("download", f"Model download FAILED: {e}")
|
| 118 |
return
|
| 119 |
|
| 120 |
-
# Phase 2:
|
| 121 |
-
_update_boot("build", "
|
| 122 |
if not os.path.exists(PHOENIX_BIN):
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
return
|
| 133 |
-
else:
|
| 134 |
-
_update_boot("build", "No phoenix binary or source found!")
|
| 135 |
-
return
|
| 136 |
_update_boot("build", "Binary ready")
|
| 137 |
|
| 138 |
# Phase 3: Start phoenix
|
|
|
|
| 4 |
|
| 5 |
This app wraps the Phoenix Brain C inference binary in a Gradio interface.
|
| 6 |
At Space startup it:
|
| 7 |
+
1. Downloads the tokenizer from HF Hub (tokenizers lib, no PyTorch)
|
| 8 |
+
2. On button click: downloads pre-built phoenix binary + model from HF Hub
|
| 9 |
+
3. Starts phoenix in --chat mode with shared-memory ring buffers
|
| 10 |
+
4. Provides a chat UI via Gradio
|
|
|
|
| 11 |
|
| 12 |
The phoenix binary runs on CPU (AVX2) — the wave-rider physics engine
|
| 13 |
doesn't use PyTorch, so ZeroGPU doesn't accelerate it directly.
|
|
|
|
| 116 |
_update_boot("download", f"Model download FAILED: {e}")
|
| 117 |
return
|
| 118 |
|
| 119 |
+
# Phase 2: Download pre-built binary from HF Hub (avoids compilation on Space)
|
| 120 |
+
_update_boot("build", "Downloading phoenix binary from Hub...")
|
| 121 |
if not os.path.exists(PHOENIX_BIN):
|
| 122 |
+
try:
|
| 123 |
+
hf_hub_download(
|
| 124 |
+
repo_id=MODEL_REPO,
|
| 125 |
+
filename="phoenix",
|
| 126 |
+
local_dir=SPACE_DIR,
|
| 127 |
+
local_dir_use_symlinks=False,
|
| 128 |
+
)
|
| 129 |
+
os.chmod(PHOENIX_BIN, 0o755)
|
| 130 |
+
except Exception as e:
|
| 131 |
+
# Fallback: compile from source
|
| 132 |
+
_update_boot("build", f"Binary download failed, compiling... ({e})")
|
| 133 |
+
src_path = os.path.join(SPACE_DIR, "phoenix_brain.c")
|
| 134 |
+
if os.path.exists(src_path):
|
| 135 |
+
cc = os.environ.get("CC", "cc")
|
| 136 |
+
cmd = [cc, "-O3", "-std=c11", "-march=native", "-fopenmp",
|
| 137 |
+
src_path, "-o", PHOENIX_BIN, "-lm"]
|
| 138 |
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
| 139 |
+
if result.returncode != 0:
|
| 140 |
+
_update_boot("build", f"Build FAILED: {result.stderr[:500]}")
|
| 141 |
+
return
|
| 142 |
+
else:
|
| 143 |
+
_update_boot("build", "No binary or source found!")
|
| 144 |
return
|
|
|
|
|
|
|
|
|
|
| 145 |
_update_boot("build", "Binary ready")
|
| 146 |
|
| 147 |
# Phase 3: Start phoenix
|