#!/usr/bin/env bash # Deploy demo_2026_07 to Hugging Face Space beanbagdzf/SciPaths-Demo set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" SPACE_ID="${SPACE_ID:-Beanbagdzf/SciPaths-Demo}" cd "$ROOT" if [[ -z "${HF_TOKEN:-}" ]]; then echo "Set HF_TOKEN to a Hugging Face write token for Beanbagdzf, then re-run." echo "Create one at: https://huggingface.co/settings/tokens" exit 1 fi export HUGGINGFACE_HUB_TOKEN="$HF_TOKEN" export SPACE_ID PY="${ROOT}/.venv/bin/python" if [[ ! -x "$PY" ]]; then PY="$(command -v python3)"; fi "$PY" - <<'PY' import os from pathlib import Path from huggingface_hub import HfApi, login token = os.environ["HF_TOKEN"] login(token=token, add_to_git_credential=False) api = HfApi(token=token) who = api.whoami() print("logged_in_as", who.get("name")) space_id = os.environ.get("SPACE_ID", "Beanbagdzf/SciPaths-Demo") url = api.create_repo(repo_id=space_id, repo_type="space", space_sdk="docker", exist_ok=True, private=False) print("space", url) # Upload folder (respects .gitignore / skips secrets) api.upload_folder( folder_path=".", repo_id=space_id, repo_type="space", ignore_patterns=[ ".git*", ".venv/**", ".env", ".playwright/**", "hf_space/runs/**", "runs/**", ".streamlit/secrets.toml", "**/__pycache__/**", "*.pyc", ".DS_Store", ], ) print("uploaded") # Space secret for Gemini (from local .env) env = Path(".env") gemini = "" if env.exists(): for line in env.read_text().splitlines(): line=line.strip() if not line or line.startswith("#") or "=" not in line: continue k,v = line.split("=",1) if k.strip() in {"GEMINI_API_KEY","GOOGLE_GENAI_API_KEY","GOOGLE_API_KEY"} and v.strip(): gemini = v.strip().strip('"').strip("'") break if gemini: api.add_space_secret(space_id, "GEMINI_API_KEY", gemini) api.add_space_secret(space_id, "GOOGLE_GENAI_API_KEY", gemini) api.add_space_secret(space_id, "GOOGLE_API_KEY", gemini) print("secrets_set GEMINI_API_KEY") else: print("WARN: no GEMINI key found in .env — set Space secret manually") print(f"URL: https://huggingface.co/spaces/{space_id}") PY