#!/usr/bin/env bash # 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 " 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 - <