Spaces:
Sleeping
Sleeping
Nicholas Bumgarner commited on
Commit ·
3aec1bb
1
Parent(s): a53b1da
Cache binary download (no force_download); fix indentation
Browse files
app.py
CHANGED
|
@@ -117,35 +117,33 @@ def boot_phoenix():
|
|
| 117 |
return
|
| 118 |
|
| 119 |
# Phase 2: Download pre-built binary from HF Hub (avoids compilation on Space)
|
| 120 |
-
_update_boot("build", "
|
| 121 |
-
#
|
| 122 |
-
if os.path.exists(PHOENIX_BIN):
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
|
|
|
| 145 |
return
|
| 146 |
-
else:
|
| 147 |
-
_update_boot("build", "No binary or source found!")
|
| 148 |
-
return
|
| 149 |
_update_boot("build", "Binary ready")
|
| 150 |
|
| 151 |
# Phase 3: Start phoenix
|
|
|
|
| 117 |
return
|
| 118 |
|
| 119 |
# Phase 2: Download pre-built binary from HF Hub (avoids compilation on Space)
|
| 120 |
+
_update_boot("build", "Checking for phoenix binary...")
|
| 121 |
+
# Only download if binary doesn't exist (cached after first download)
|
| 122 |
+
if not os.path.exists(PHOENIX_BIN):
|
| 123 |
+
try:
|
| 124 |
+
_update_boot("build", "Downloading phoenix binary from Hub...")
|
| 125 |
+
hf_hub_download(
|
| 126 |
+
repo_id=MODEL_REPO,
|
| 127 |
+
filename="phoenix",
|
| 128 |
+
local_dir=SPACE_DIR,
|
| 129 |
+
local_dir_use_symlinks=False,
|
| 130 |
+
)
|
| 131 |
+
os.chmod(PHOENIX_BIN, 0o755)
|
| 132 |
+
except Exception as e:
|
| 133 |
+
# Fallback: compile from source
|
| 134 |
+
_update_boot("build", f"Binary download failed, compiling... ({e})")
|
| 135 |
+
src_path = os.path.join(SPACE_DIR, "phoenix_brain.c")
|
| 136 |
+
if os.path.exists(src_path):
|
| 137 |
+
cc = os.environ.get("CC", "cc")
|
| 138 |
+
cmd = [cc, "-O3", "-std=c11", "-march=native", "-fopenmp",
|
| 139 |
+
src_path, "-o", PHOENIX_BIN, "-lm"]
|
| 140 |
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
| 141 |
+
if result.returncode != 0:
|
| 142 |
+
_update_boot("build", f"Build FAILED: {result.stderr[:500]}")
|
| 143 |
+
return
|
| 144 |
+
else:
|
| 145 |
+
_update_boot("build", "No binary or source found!")
|
| 146 |
return
|
|
|
|
|
|
|
|
|
|
| 147 |
_update_boot("build", "Binary ready")
|
| 148 |
|
| 149 |
# Phase 3: Start phoenix
|