Spaces:
Sleeping
Sleeping
File size: 1,374 Bytes
7964128 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import os
from pathlib import Path
from huggingface_hub import hf_hub_download
import shutil
HF_REPO_ID = "nice-bill/book-recommender-artifacts"
REPO_TYPE = "dataset"
DATA_DIR = Path("data")
CATALOG_DIR = DATA_DIR / "catalog"
INDEX_DIR = DATA_DIR / "index"
FILES_TO_DOWNLOAD = {
"books_catalog.csv": CATALOG_DIR,
"embeddings_cache.npy": DATA_DIR,
"optimized.index": INDEX_DIR
}
def main():
print(f"--- Checking artifacts from {HF_REPO_ID} ---")
for dir_path in [DATA_DIR, CATALOG_DIR, INDEX_DIR]:
dir_path.mkdir(parents=True, exist_ok=True)
for filename, dest_dir in FILES_TO_DOWNLOAD.items():
dest_path = dest_dir / filename
if dest_path.exists():
print(f"Found {filename}")
continue
print(f"Downloading {filename}...")
try:
cached_path = hf_hub_download(
repo_id=HF_REPO_ID,
filename=filename,
repo_type=REPO_TYPE
)
shutil.copy(cached_path, dest_path)
print(f" Saved to {dest_path}")
except Exception as e:
print(f"Failed to download {filename}: {e}")
print(" (Did you create the HF repo and upload the files?)")
print("\nArtifact setup complete.")
if __name__ == "__main__":
main()
|