File size: 1,393 Bytes
9146d63
d46bde8
9146d63
 
d46bde8
9146d63
d46bde8
9146d63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# Deploy hf_staging/ to Hugging Face Spaces (default: kinaar111/staging)
set -euo pipefail

SPACE_ID="${HF_SPACE_ID:-kinaar111/staging}"
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
COMMIT_MSG="${1:-Update 6-string optimizer staging Space}"

cd "$ROOT"

if ! command -v hf &>/dev/null; then
  echo "hf CLI not found. Install: curl -LsSf https://hf.co/cli/install.sh | bash"
  exit 1
fi

if ! hf auth whoami &>/dev/null; then
  echo "Not logged in. Run: hf auth login"
  exit 1
fi

COMMIT_HASH="local"
if git -C "$(dirname "$ROOT")" rev-parse --short HEAD &>/dev/null 2>&1; then
  COMMIT_HASH="$(git -C "$(dirname "$ROOT")" rev-parse --short HEAD)"
fi
UTC_NOW="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"

cat > "$ROOT/build_info.py" <<EOF
"""Auto-generated by scripts/deploy_hf_space.sh — do not edit by hand."""

BUILD_COMMIT = "${COMMIT_HASH}"
BUILD_UPDATED_UTC = "${UTC_NOW}"
EOF

echo "Ensuring Space exists: ${SPACE_ID}..."
if ! hf spaces info "$SPACE_ID" &>/dev/null; then
  hf repos create "$SPACE_ID" \
    --type space \
    --space-sdk gradio \
    --public \
    --exist-ok
fi

echo "Deploying to ${SPACE_ID}..."
hf upload "$SPACE_ID" "$ROOT" . \
  --repo-type space \
  --commit-message "$COMMIT_MSG" \
  --exclude ".cache/**" \
  --exclude "**/__pycache__/**" \
  --exclude "**/*.pyc" \
  --exclude ".venv/**"

echo "Done. Space: https://huggingface.co/spaces/${SPACE_ID}"