Namhyun Kim commited on
Commit
7f30925
·
1 Parent(s): 818195e

Surface demo data download error in UI

Browse files
Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -201,11 +201,14 @@ def _ensure_local_file(local_path: Path, hub_filename: str) -> Optional[Path]:
201
  if local_path.exists() and not _is_git_lfs_pointer(local_path):
202
  return local_path
203
 
 
 
204
  # Prefer a stored token if present (Spaces sometimes have credentials available
205
  # even when HF_TOKEN env var is not explicitly set).
206
  token = HF_TOKEN or True
207
 
208
  # Try multiple repo types because the artifact may live under a model or dataset repo.
 
209
  for repo_type in ("model", "dataset"):
210
  try:
211
  cached = hf_hub_download(
@@ -234,6 +237,11 @@ def _ensure_local_file(local_path: Path, hub_filename: str) -> Optional[Path]:
234
  print(f"[INFO] Using cached Space file for {hub_filename}: {cached_path}")
235
  return cached_path
236
  except Exception as exc:
 
 
 
 
 
237
  print(
238
  f"[WARN] Could not download {hub_filename} from Hub ({last_exc}) or Space repo ({exc}); continuing without it."
239
  )
@@ -241,6 +249,7 @@ def _ensure_local_file(local_path: Path, hub_filename: str) -> Optional[Path]:
241
 
242
 
243
  USING_SYNTHETIC_DATA = False
 
244
 
245
 
246
  def load_augmented_samples() -> Tuple[List[Dict[str, object]], bool]:
@@ -915,6 +924,9 @@ DATASET_STATUS = (
915
  f"Demo repo: {HUB_REPO_ID}@{HUB_REVISION or 'main'}"
916
  )
917
 
 
 
 
918
  has_moe_column = df["moe_embedding"].apply(lambda x: x is not None)
919
  joint_eval_df = df[has_moe_column & df["joint_label_id"].notna()]
920
 
 
201
  if local_path.exists() and not _is_git_lfs_pointer(local_path):
202
  return local_path
203
 
204
+ global LAST_DEMO_DOWNLOAD_ERROR
205
+
206
  # Prefer a stored token if present (Spaces sometimes have credentials available
207
  # even when HF_TOKEN env var is not explicitly set).
208
  token = HF_TOKEN or True
209
 
210
  # Try multiple repo types because the artifact may live under a model or dataset repo.
211
+ last_exc: Exception | None = None
212
  for repo_type in ("model", "dataset"):
213
  try:
214
  cached = hf_hub_download(
 
237
  print(f"[INFO] Using cached Space file for {hub_filename}: {cached_path}")
238
  return cached_path
239
  except Exception as exc:
240
+ # Persist a short error string for the UI status line.
241
+ err = str(last_exc or exc)
242
+ if len(err) > 240:
243
+ err = err[:240] + "..."
244
+ LAST_DEMO_DOWNLOAD_ERROR = err
245
  print(
246
  f"[WARN] Could not download {hub_filename} from Hub ({last_exc}) or Space repo ({exc}); continuing without it."
247
  )
 
249
 
250
 
251
  USING_SYNTHETIC_DATA = False
252
+ LAST_DEMO_DOWNLOAD_ERROR: str | None = None
253
 
254
 
255
  def load_augmented_samples() -> Tuple[List[Dict[str, object]], bool]:
 
924
  f"Demo repo: {HUB_REPO_ID}@{HUB_REVISION or 'main'}"
925
  )
926
 
927
+ if LAST_DEMO_DOWNLOAD_ERROR:
928
+ DATASET_STATUS += f" | Download error: {LAST_DEMO_DOWNLOAD_ERROR}"
929
+
930
  has_moe_column = df["moe_embedding"].apply(lambda x: x is not None)
931
  joint_eval_df = df[has_moe_column & df["joint_label_id"].notna()]
932