seriffic Claude Opus 4.7 (1M context) commited on
Commit
f9e2ab8
·
1 Parent(s): 316a4cd

fix(redeploy): use cached huggingface-cli login by default

Browse files

HF_TOKEN was a hard requirement; HfApi() falls back to the
~/.cache/huggingface/token written by 'huggingface-cli login' so the
env var is unnecessary when the user is already authed.

- update_hf_env.sh: HfApi(token=os.environ.get('HF_TOKEN')) — None
routes to cached login.
- redeploy.sh: replace the HF_TOKEN guard with a real auth probe via
HfApi().whoami(); exits early with a clear hint if neither path is
authed.
- runbook: drop the HF_TOKEN= prefix from the quick-redeploy snippet.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

docs/DROPLET-RUNBOOK.md CHANGED
@@ -2,12 +2,13 @@
2
 
3
  _Last verified: 2026-05-09 (terramind synthesis + LoRA adapters confirmed firing live)_
4
 
5
- > **Quick redeploy:** `HF_TOKEN=<write-token> scripts/redeploy.sh <new-droplet-ip>`
6
  > generates a fresh bearer token, builds + brings up vLLM + riprap-models, updates
7
  > the HF Space env vars, restarts the Space, and runs the end-to-end probe.
8
- > Source-committed fixes (e.g. the May 9 terramind chip-tensor + synthesis
9
- > patches) are inherited automatically because `deploy_droplet.sh` tars
10
- > `services/riprap-models/` from this repo at run time.
 
11
 
12
  ## Spec
13
 
 
2
 
3
  _Last verified: 2026-05-09 (terramind synthesis + LoRA adapters confirmed firing live)_
4
 
5
+ > **Quick redeploy:** `scripts/redeploy.sh <new-droplet-ip>`
6
  > generates a fresh bearer token, builds + brings up vLLM + riprap-models, updates
7
  > the HF Space env vars, restarts the Space, and runs the end-to-end probe.
8
+ > HF auth comes from `huggingface-cli login` (cached) `HF_TOKEN` env override
9
+ > is supported but not required. Source-committed fixes (e.g. the May 9
10
+ > terramind chip-tensor + synthesis patches) are inherited automatically because
11
+ > `deploy_droplet.sh` tars `services/riprap-models/` from this repo at run time.
12
 
13
  ## Spec
14
 
scripts/redeploy.sh CHANGED
@@ -9,7 +9,7 @@
9
  # Usage: scripts/redeploy.sh <droplet-ip>
10
  #
11
  # Requires:
12
- # HF_TOKEN env var with write access to the HF Space
13
  # .venv Python virtual environment with probe_addresses.py deps
14
  # SSH access to the droplet (ssh-agent or SSH_KEY env var)
15
  #
@@ -27,8 +27,20 @@ fi
27
 
28
  IP="$1"
29
 
30
- if [ -z "${HF_TOKEN:-}" ]; then
31
- echo "Error: HF_TOKEN env var is required (write access to the HF Space)" >&2
 
 
 
 
 
 
 
 
 
 
 
 
32
  exit 1
33
  fi
34
 
 
9
  # Usage: scripts/redeploy.sh <droplet-ip>
10
  #
11
  # Requires:
12
+ # HF auth either `huggingface-cli login` (preferred) or HF_TOKEN env var
13
  # .venv Python virtual environment with probe_addresses.py deps
14
  # SSH access to the droplet (ssh-agent or SSH_KEY env var)
15
  #
 
27
 
28
  IP="$1"
29
 
30
+ # Verify HF auth is available before doing the long droplet build.
31
+ # Either HF_TOKEN env or a cached CLI login works HfApi() picks up
32
+ # whichever is set.
33
+ if ! python3 -c "
34
+ import sys
35
+ from huggingface_hub import HfApi
36
+ try:
37
+ HfApi().whoami()
38
+ except Exception as e:
39
+ print(f'HF auth check failed: {e}', file=sys.stderr)
40
+ print('Run: huggingface-cli login (or: export HF_TOKEN=...)',
41
+ file=sys.stderr)
42
+ sys.exit(1)
43
+ " >/dev/null; then
44
  exit 1
45
  fi
46
 
scripts/update_hf_env.sh CHANGED
@@ -5,9 +5,12 @@
5
  # Usage: scripts/update_hf_env.sh <droplet-ip> <bearer-token>
6
  #
7
  # Requires:
8
- # HF_TOKEN env var with write access to the Space
9
  # huggingface_hub >= 0.36 installed (provides the Python API used below;
10
  # note: 'huggingface-cli space variables' does not exist in this version)
 
 
 
 
11
  #
12
  # Space slug: lablab-ai-amd-developer-hackathon/riprap-nyc
13
  # Variables set (from docs/DROPLET-RUNBOOK.md §Required secrets):
@@ -17,6 +20,7 @@
17
  # RIPRAP_ML_BACKEND remote
18
  # RIPRAP_ML_BASE_URL http://<ip>:7860
19
  # RIPRAP_ML_API_KEY <token>
 
20
  set -euo pipefail
21
 
22
  if [ "$#" -ne 2 ]; then
@@ -27,11 +31,6 @@ fi
27
  IP="$1"
28
  TOKEN="$2"
29
 
30
- if [ -z "${HF_TOKEN:-}" ]; then
31
- echo "Error: HF_TOKEN env var is required (write access to the Space)" >&2
32
- exit 1
33
- fi
34
-
35
  SPACE_ID="lablab-ai-amd-developer-hackathon/riprap-nyc"
36
  SPACE_URL="https://lablab-ai-amd-developer-hackathon-riprap-nyc.hf.space"
37
  VLLM_PORT=8001
@@ -55,7 +54,7 @@ except ImportError:
55
  print('Error: huggingface_hub not installed', file=sys.stderr)
56
  sys.exit(1)
57
 
58
- api = HfApi(token=os.environ['HF_TOKEN'])
59
  space_id = '${SPACE_ID}'
60
  ip = '${IP}'
61
  token = '${TOKEN}'
@@ -90,7 +89,7 @@ echo "==> Restarting HF Space"
90
  python3 -c "
91
  import os
92
  from huggingface_hub import HfApi
93
- api = HfApi(token=os.environ['HF_TOKEN'])
94
  rt = api.restart_space(repo_id='${SPACE_ID}')
95
  print(f' stage after restart request: {rt.stage}')
96
  "
 
5
  # Usage: scripts/update_hf_env.sh <droplet-ip> <bearer-token>
6
  #
7
  # Requires:
 
8
  # huggingface_hub >= 0.36 installed (provides the Python API used below;
9
  # note: 'huggingface-cli space variables' does not exist in this version)
10
+ # Either:
11
+ # - `huggingface-cli login` cached token (preferred), OR
12
+ # - HF_TOKEN env var
13
+ # HfApi() picks up the cached login automatically; HF_TOKEN overrides.
14
  #
15
  # Space slug: lablab-ai-amd-developer-hackathon/riprap-nyc
16
  # Variables set (from docs/DROPLET-RUNBOOK.md §Required secrets):
 
20
  # RIPRAP_ML_BACKEND remote
21
  # RIPRAP_ML_BASE_URL http://<ip>:7860
22
  # RIPRAP_ML_API_KEY <token>
23
+ # RIPRAP_NYCHA_REGISTERS 1
24
  set -euo pipefail
25
 
26
  if [ "$#" -ne 2 ]; then
 
31
  IP="$1"
32
  TOKEN="$2"
33
 
 
 
 
 
 
34
  SPACE_ID="lablab-ai-amd-developer-hackathon/riprap-nyc"
35
  SPACE_URL="https://lablab-ai-amd-developer-hackathon-riprap-nyc.hf.space"
36
  VLLM_PORT=8001
 
54
  print('Error: huggingface_hub not installed', file=sys.stderr)
55
  sys.exit(1)
56
 
57
+ api = HfApi(token=os.environ.get('HF_TOKEN')) # None → cached CLI login
58
  space_id = '${SPACE_ID}'
59
  ip = '${IP}'
60
  token = '${TOKEN}'
 
89
  python3 -c "
90
  import os
91
  from huggingface_hub import HfApi
92
+ api = HfApi(token=os.environ.get('HF_TOKEN')) # None → cached CLI login
93
  rt = api.restart_space(repo_id='${SPACE_ID}')
94
  print(f' stage after restart request: {rt.stage}')
95
  "