| #!/bin/bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| set -e |
|
|
| GREEN='\033[0;32m' |
| YELLOW='\033[1;33m' |
| RED='\033[0;31m' |
| NC='\033[0m' |
|
|
| |
| 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 "" |
|
|
| |
| 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 |
|
|
| |
| 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 "" |
|
|
| |
| 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 |
| " |
|
|
| |
| 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") |
|
|
| |
| uploads = [] |
|
|
| |
| for root, dirs, files in os.walk("td_lang"): |
| |
| 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) |
|
|
| |
| 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) |
|
|
| |
| 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 "===========================================" |
|
|