|
|
|
""" |
|
Script to upload the current directory to a Hugging Face Space |
|
""" |
|
|
|
import os |
|
import sys |
|
from huggingface_hub import HfApi, create_repo |
|
|
|
|
|
SPACE_NAME = "mknolan/cursor_slides" |
|
TOKEN = input("Enter your Hugging Face token (with WRITE access): ") |
|
|
|
|
|
api = HfApi(token=TOKEN) |
|
|
|
def upload_directory(): |
|
"""Upload all files in the current directory to HF Space""" |
|
print("Uploading to Space: {}".format(SPACE_NAME)) |
|
|
|
|
|
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))) |
|
|
|
|
|
files_to_upload = [] |
|
for root, _, files in os.walk("."): |
|
|
|
if "/.git" in root or "/.__pycache__" in root: |
|
continue |
|
|
|
for file in files: |
|
|
|
if file.startswith(".git") or file.startswith("."): |
|
continue |
|
|
|
path = os.path.join(root, file) |
|
|
|
if path == "./upload_to_hf.py": |
|
continue |
|
|
|
files_to_upload.append(path) |
|
|
|
print("Found {} files to upload".format(len(files_to_upload))) |
|
|
|
|
|
for i, path in enumerate(files_to_upload): |
|
print("[{}/{}] Uploading {}...".format(i+1, len(files_to_upload), path)) |
|
try: |
|
|
|
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() |