File size: 2,355 Bytes
e59dc66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
"""
Script to upload the current directory to a Hugging Face Space
"""

import os
import sys
from huggingface_hub import HfApi, create_repo

# Configuration
SPACE_NAME = "mknolan/cursor_slides"  # Change this to your space name
TOKEN = input("Enter your Hugging Face token (with WRITE access): ")

# Initialize API
api = HfApi(token=TOKEN)

def upload_directory():
    """Upload all files in the current directory to HF Space"""
    print("Uploading to Space: {}".format(SPACE_NAME))

    # Create repo if it doesn't exist (this is idempotent)
    try:
        create_repo(
            repo_id=SPACE_NAME,
            token=TOKEN,
            repo_type="space",
            exist_ok=True,
            space_sdk="docker"
        )
        print("Repo {} ready".format(SPACE_NAME))
    except Exception as e:
        print("Note: Repo already exists or {}".format(str(e)))

    # Gather all files to upload
    files_to_upload = []
    for root, _, files in os.walk("."):
        # Skip .git directory and any other hidden directories
        if "/.git" in root or "/.__pycache__" in root:
            continue
            
        for file in files:
            # Skip hidden files and .git files
            if file.startswith(".git") or file.startswith("."):
                continue
                
            path = os.path.join(root, file)
            # Skip this upload script itself
            if path == "./upload_to_hf.py":
                continue
                
            files_to_upload.append(path)

    print("Found {} files to upload".format(len(files_to_upload)))
    
    # Upload each file
    for i, path in enumerate(files_to_upload):
        print("[{}/{}] Uploading {}...".format(i+1, len(files_to_upload), path))
        try:
            # Path in repo (remove leading ./)
            path_in_repo = path[2:] if path.startswith("./") else path
            api.upload_file(
                path_or_fileobj=path,
                path_in_repo=path_in_repo,
                repo_id=SPACE_NAME,
                repo_type="space"
            )
        except Exception as e:
            print("Error uploading {}: {}".format(path, str(e)))

    print("Upload completed!")
    print("Check your Space at: https://huggingface.co/spaces/{}".format(SPACE_NAME))

if __name__ == "__main__":
    upload_directory()