#!/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()