Spaces:
Sleeping
Sleeping
| # upload_to_hf.sh | |
| # ---------------- | |
| # Upload the pipeline/ folder to a HuggingFace Space. | |
| # | |
| # Usage: | |
| # ./upload_to_hf.sh [HF_SPACE] | |
| # | |
| # Examples: | |
| # ./upload_to_hf.sh your-username/SpatialBench | |
| # HF_TOKEN=hf_xxx ./upload_to_hf.sh your-username/SpatialBench | |
| # | |
| # The script uploads only the files needed to run the Space: | |
| # app.py, pipeline/, configs/, requirements.txt, README.md | |
| # It never uploads .env, __pycache__, or result/log directories. | |
| # | |
| # Requirements: | |
| # pip install huggingface_hub | |
| set -euo pipefail | |
| # --------------------------------------------------------------------------- | |
| # Configuration | |
| # --------------------------------------------------------------------------- | |
| HF_SPACE="${1:-}" | |
| if [[ -z "$HF_SPACE" ]]; then | |
| echo "Usage: $0 <your-username/SpaceName>" | |
| echo "Example: $0 weijiang/SpatialBench" | |
| exit 1 | |
| fi | |
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| # --------------------------------------------------------------------------- | |
| # Auth | |
| # --------------------------------------------------------------------------- | |
| if [[ -z "${HF_TOKEN:-}" ]]; then | |
| # Try reading from huggingface-cli login cache | |
| HF_TOKEN_FILE="${HOME}/.cache/huggingface/token" | |
| if [[ -f "$HF_TOKEN_FILE" ]]; then | |
| HF_TOKEN="$(cat "$HF_TOKEN_FILE")" | |
| export HF_TOKEN | |
| fi | |
| fi | |
| if [[ -z "${HF_TOKEN:-}" ]]; then | |
| echo "No HuggingFace token found." | |
| echo "Either:" | |
| echo " 1. Run: huggingface-cli login" | |
| echo " 2. Set: export HF_TOKEN=hf_xxx" | |
| exit 1 | |
| fi | |
| echo "Uploading to HuggingFace Space: $HF_SPACE" | |
| echo "Source directory: $SCRIPT_DIR" | |
| echo "" | |
| # --------------------------------------------------------------------------- | |
| # Upload via Python (huggingface_hub) | |
| # --------------------------------------------------------------------------- | |
| python - <<PYEOF | |
| import os | |
| import sys | |
| from pathlib import Path | |
| from huggingface_hub import HfApi, upload_folder | |
| api = HfApi(token=os.environ["HF_TOKEN"]) | |
| space_id = "$HF_SPACE" | |
| local_dir = Path("$SCRIPT_DIR") | |
| # Ensure the Space exists (type=gradio); if it already exists this is a no-op. | |
| try: | |
| api.create_repo( | |
| repo_id=space_id, | |
| repo_type="space", | |
| space_sdk="gradio", | |
| exist_ok=True, | |
| private=True, | |
| ) | |
| print(f"Space ready: https://huggingface.co/spaces/{space_id}") | |
| except Exception as e: | |
| print(f"[WARN] Could not create/verify Space: {e}") | |
| print("Proceeding with upload anyway...") | |
| # Files/dirs to ignore (never upload secrets, cache, or large result dirs) | |
| IGNORE_PATTERNS = [ | |
| ".env", | |
| "*.pyc", | |
| "__pycache__", | |
| "*.egg-info", | |
| ".git", | |
| ".gitignore", | |
| # Large result/log directories that live outside pipeline/ anyway | |
| "spatial-reasoning-results*", | |
| "spatial_reasoning_logs", | |
| "llm-maze-evaluation-results", | |
| "eval_llm_logs", | |
| ] | |
| print(f"\nUploading files from: {local_dir}") | |
| print("Ignoring: " + ", ".join(IGNORE_PATTERNS)) | |
| print("") | |
| url = upload_folder( | |
| repo_id=space_id, | |
| repo_type="space", | |
| folder_path=str(local_dir), | |
| path_in_repo=".", | |
| ignore_patterns=IGNORE_PATTERNS, | |
| commit_message="Update SpatialBench pipeline", | |
| token=os.environ["HF_TOKEN"], | |
| ) | |
| print(f"\nUpload complete!") | |
| print(f"Space URL: https://huggingface.co/spaces/{space_id}") | |
| PYEOF | |