Spaces:
Sleeping
Sleeping
| import os | |
| import sys | |
| from pathlib import Path | |
| from huggingface_hub import snapshot_download | |
| # Get PRIVATE Space 1 URL from environment (not Space 2!) | |
| PRIVATE_SPACE_URL = os.getenv("PRIVATE_SPACE_URL") # e.g., "username/private-space" | |
| HF_TOKEN = os.getenv("HF_TOKEN") | |
| if not PRIVATE_SPACE_URL or not HF_TOKEN: | |
| print("ERROR: PRIVATE_SPACE_URL and HF_TOKEN must be set") | |
| print("Add them as secrets in your Space settings") | |
| sys.exit(1) | |
| # Download files directly from the private Space 1 | |
| try: | |
| print(f"Downloading code from private space: {PRIVATE_SPACE_URL}") | |
| # Create /app/code directory | |
| code_dir = Path("/app/code") | |
| code_dir.mkdir(exist_ok=True, parents=True) | |
| # Download all files from Space 1 | |
| snapshot_download( | |
| repo_id=PRIVATE_SPACE_URL, | |
| repo_type="space", | |
| token=HF_TOKEN, | |
| local_dir=str(code_dir), | |
| local_dir_use_symlinks=False | |
| ) | |
| print("β Successfully downloaded code") | |
| # List files for verification | |
| files = [f for f in code_dir.rglob("*") if f.is_file()] | |
| print(f"Total files downloaded: {len(files)}") | |
| # Show first 20 files | |
| for i, f in enumerate(files[:20]): | |
| print(f" - {f.relative_to(code_dir)}") | |
| if len(files) > 20: | |
| print(f" ... and {len(files) - 20} more files") | |
| # Check for package.json | |
| package_json = code_dir / "package.json" | |
| if package_json.exists(): | |
| print("β Found package.json") | |
| else: | |
| print("β οΈ No package.json found - npm install will be skipped") | |
| except Exception as e: | |
| print(f"β Error downloading code: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| sys.exit(1) |