Valmbd commited on
Commit
a8f58a6
·
verified ·
1 Parent(s): c131b3a

Fix: use direct HTTP requests for predictions.zip to avoid hf_hub_download locking on LFS pointer

Browse files
Files changed (1) hide show
  1. app/utils/download.py +16 -33
app/utils/download.py CHANGED
@@ -44,41 +44,24 @@ def ensure_predictions_zip(root: str) -> str | None:
44
  if os.path.exists(zip_path) and os.path.getsize(zip_path) > 10000:
45
  return zip_path
46
 
47
- # Download from HuggingFace repo
48
- print("⬇️ Downloading predictions.zip from HuggingFace...")
49
- logger.info("Downloading predictions.zip from HuggingFace...")
 
 
50
  try:
51
- from huggingface_hub import hf_hub_download
52
- # First try downloading to root dir
53
- downloaded = hf_hub_download(
54
- repo_id=HF_REPO,
55
- filename="predictions.zip",
56
- repo_type="space",
57
- local_dir=root,
58
- )
59
- sz = os.path.getsize(downloaded)
60
- print(f"✅ Downloaded predictions.zip: {sz / 1e6:.0f} MB")
61
- logger.info(f"Downloaded predictions.zip: {sz} bytes → {downloaded}")
62
- return downloaded
63
- except Exception as e:
64
- logger.warning(f"HF download (local_dir) failed: {e}")
65
- print(f"⚠️ Download to local_dir failed: {e}")
66
-
67
- # Fallback: download to HF cache (always works)
68
- try:
69
- from huggingface_hub import hf_hub_download
70
- downloaded = hf_hub_download(
71
- repo_id=HF_REPO,
72
- filename="predictions.zip",
73
- repo_type="space",
74
- )
75
- sz = os.path.getsize(downloaded)
76
- print(f"✅ Downloaded predictions.zip (cache): {sz / 1e6:.0f} MB")
77
- logger.info(f"Downloaded predictions.zip (cache): {sz} bytes → {downloaded}")
78
- return downloaded
79
  except Exception as e:
80
- logger.error(f"HF download (cache) failed: {e}")
81
- print(f" Download failed: {e}")
82
 
83
  return None
84
 
 
44
  if os.path.exists(zip_path) and os.path.getsize(zip_path) > 10000:
45
  return zip_path
46
 
47
+ # Download from HuggingFace repo via direct HTTP (bypasses LFS/cache issues)
48
+ url = f"https://huggingface.co/spaces/{HF_REPO}/resolve/main/predictions.zip"
49
+ print(f"⬇️ Downloading predictions.zip from {url}...")
50
+ logger.info(f"Downloading predictions.zip from HuggingFace via HTTP")
51
+
52
  try:
53
+ # Overwrite the LFS pointer file directly
54
+ if download_file(url, zip_path, "predictions.zip"):
55
+ sz = os.path.getsize(zip_path)
56
+ print(f"✅ Downloaded predictions.zip: {sz / 1e6:.0f} MB")
57
+ logger.info(f"Downloaded predictions.zip: {sz} bytes → {zip_path}")
58
+ return zip_path
59
+ else:
60
+ print(f"⚠️ HTTP download_file returned False for {url}")
61
+ logger.warning("HTTP download_file returned False.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  except Exception as e:
63
+ print(f" Exception downloading predictions.zip: {e}")
64
+ logger.error(f"Exception downloading predictions.zip: {e}")
65
 
66
  return None
67