Nicholas Bumgarner commited on
Commit
3aec1bb
·
1 Parent(s): a53b1da

Cache binary download (no force_download); fix indentation

Browse files
Files changed (1) hide show
  1. app.py +26 -28
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", "Downloading phoenix binary from Hub...")
121
- # Always re-download to ensure we get the latest binary
122
- if os.path.exists(PHOENIX_BIN):
123
- os.unlink(PHOENIX_BIN)
124
- try:
125
- hf_hub_download(
126
- repo_id=MODEL_REPO,
127
- filename="phoenix",
128
- local_dir=SPACE_DIR,
129
- local_dir_use_symlinks=False,
130
- force_download=True,
131
- force_filename="phoenix",
132
- )
133
- os.chmod(PHOENIX_BIN, 0o755)
134
- except Exception as e:
135
- # Fallback: compile from source
136
- _update_boot("build", f"Binary download failed, compiling... ({e})")
137
- src_path = os.path.join(SPACE_DIR, "phoenix_brain.c")
138
- if os.path.exists(src_path):
139
- cc = os.environ.get("CC", "cc")
140
- cmd = [cc, "-O3", "-std=c11", "-march=native", "-fopenmp",
141
- src_path, "-o", PHOENIX_BIN, "-lm"]
142
- result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
143
- if result.returncode != 0:
144
- _update_boot("build", f"Build FAILED: {result.stderr[:500]}")
 
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