Valmbd commited on
Commit
f431fcf
·
verified ·
1 Parent(s): 7bc226a

Fix: auto-download predictions.zip from HF if not found or LFS pointer

Browse files
Files changed (1) hide show
  1. app/utils/data_loader.py +20 -2
app/utils/data_loader.py CHANGED
@@ -24,9 +24,27 @@ def _get_zip_namelist(zip_path: str) -> list[str]:
24
 
25
 
26
  def get_predictions_zip(root: str) -> str | None:
27
- """Find predictions.zip in the root directory."""
 
 
 
28
  zip_path = os.path.join(root, "predictions.zip")
29
- return zip_path if os.path.exists(zip_path) else None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
 
32
  def find_predictions_dir(root: str) -> str | None:
 
24
 
25
 
26
  def get_predictions_zip(root: str) -> str | None:
27
+ """Find valid predictions.zip (not an LFS pointer) in the root directory.
28
+
29
+ If not found locally or is an LFS pointer, try to download from HF.
30
+ """
31
  zip_path = os.path.join(root, "predictions.zip")
32
+
33
+ # Check if it exists and is a real file (not LFS pointer ~134 bytes)
34
+ if os.path.exists(zip_path) and os.path.getsize(zip_path) > 10000:
35
+ return zip_path
36
+
37
+ # Try auto-downloading from HuggingFace
38
+ try:
39
+ from app.utils.download import ensure_predictions_zip
40
+ result = ensure_predictions_zip(root)
41
+ if result and os.path.exists(result) and os.path.getsize(result) > 10000:
42
+ logger.info(f"Auto-downloaded predictions.zip: {os.path.getsize(result)} bytes")
43
+ return result
44
+ except Exception as e:
45
+ logger.warning(f"Auto-download failed: {e}")
46
+
47
+ return None
48
 
49
 
50
  def find_predictions_dir(root: str) -> str | None: