File size: 2,244 Bytes
f329675
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/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