File size: 1,699 Bytes
c977e4a
 
 
 
 
4d4462c
 
c977e4a
 
4d4462c
 
 
c977e4a
 
4d4462c
c977e4a
4d4462c
c977e4a
4d4462c
 
 
 
 
 
 
c977e4a
 
4d4462c
 
c977e4a
 
4d4462c
c977e4a
 
4d4462c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c977e4a
 
 
4d4462c
 
c977e4a
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
52
53
54
55
56
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)