#!/bin/bash # upload_to_hf.sh — Push td_lang + td_fuse + .td files to a PRIVATE HuggingFace repo # # First time setup: # 1. Go to huggingface.co → Sign up (use any username you want, not your real name) # 2. Settings → Access Tokens → New Token → "Write" access # 3. Run: pip install huggingface_hub # 4. Run: huggingface-cli login (paste your token) # 5. Run: bash upload_to_hf.sh # # After first time, just run: bash upload_to_hf.sh # It updates the repo with any changes. set -e GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # ---- CHANGE THIS to your HuggingFace username ---- HF_USER="${HF_USER:-your_username_here}" REPO_NAME="td-toolkit" # --------------------------------------------------- REPO_ID="$HF_USER/$REPO_NAME" echo "" echo "===========================================" echo " TD Upload — Push to Private HuggingFace" echo "===========================================" echo "" # Check if huggingface-cli is available if ! command -v huggingface-cli &> /dev/null; then echo -e "${YELLOW}Installing huggingface_hub...${NC}" pip install huggingface_hub --quiet 2>/dev/null || pip install huggingface_hub --break-system-packages --quiet fi # Check login if ! huggingface-cli whoami &> /dev/null 2>&1; then echo -e "${YELLOW}Not logged in to HuggingFace.${NC}" echo "Run: huggingface-cli login" exit 1 fi CURRENT_USER=$(huggingface-cli whoami 2>/dev/null | head -1) echo -e "Logged in as: ${GREEN}$CURRENT_USER${NC}" if [ "$HF_USER" = "your_username_here" ]; then echo "" echo -e "${YELLOW}You need to set your HF username first.${NC}" echo "Either:" echo " 1. Edit this script and change HF_USER at the top" echo " 2. Or run: HF_USER=$CURRENT_USER bash upload_to_hf.sh" exit 1 fi echo "Repo: $REPO_ID (private)" echo "" # Create the repo if it doesn't exist (private by default) echo -e "${GREEN}[1/3]${NC} Creating/checking repo..." python3 -c " from huggingface_hub import HfApi api = HfApi() try: api.create_repo('$REPO_ID', repo_type='model', private=True) print(' Created new private repo: $REPO_ID') except Exception as e: if 'already' in str(e).lower() or '409' in str(e): print(' Repo exists: $REPO_ID') else: raise e " # Upload all the important files echo -e "${GREEN}[2/3]${NC} Uploading files..." python3 << 'PYEOF' from huggingface_hub import HfApi import os api = HfApi() repo_id = os.environ.get("REPO_ID", "REPO_ID_MISSING") # Files and folders to upload uploads = [] # td_lang package for root, dirs, files in os.walk("td_lang"): # Skip __pycache__ if "__pycache__" in root: continue for f in files: if f.endswith((".py", ".td", ".lark", ".md")): local = os.path.join(root, f) uploads.append(local) # td_fuse package (if it exists) if os.path.isdir("td_fuse"): for root, dirs, files in os.walk("td_fuse"): if "__pycache__" in root: continue for f in files: if f.endswith((".py", ".td", ".lark", ".md", ".json")): local = os.path.join(root, f) uploads.append(local) # Root-level .td files and deploy script for f in os.listdir("."): if f.endswith(".td") or f in ("deploy.sh", "QUICKSTART.md"): uploads.append(f) print(f" Uploading {len(uploads)} files...") for path in sorted(uploads): print(f" {path}") api.upload_file( path_or_fileobj=path, path_in_repo=path, repo_id=repo_id, repo_type="model", ) print(f"\n Done! {len(uploads)} files uploaded.") PYEOF echo "" echo -e "${GREEN}[3/3]${NC} Upload complete!" echo "" echo "===========================================" echo " Your private repo: https://huggingface.co/$REPO_ID" echo "" echo " On any GPU, download everything with:" echo " export HF_TOKEN=your_token" echo " git clone https://\$HF_TOKEN@huggingface.co/$REPO_ID td_toolkit" echo " cd td_toolkit && bash deploy.sh demo_autopilot.td" echo "==========================================="