File size: 1,428 Bytes
9b2cded
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# Deploy training Space to Hugging Face.
# Usage: ./scripts/deploy_train_space.sh YOUR_HF_USERNAME/sql-error-classifier-train
set -euo pipefail

SPACE_ID="${1:-}"
if [[ -z "${SPACE_ID}" ]]; then
  echo "Usage: $0 YOUR_USERNAME/sql-error-classifier-train"
  exit 1
fi

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
TOKEN="${HF_TOKEN:-${HUGGING_FACE_HUB_TOKEN:-}}"

if [[ -z "${TOKEN}" ]]; then
  echo "Set HF_TOKEN before deploying."
  exit 1
fi

WORKDIR=$(mktemp -d)
trap 'rm -rf "${WORKDIR}"' EXIT

echo "==> Preparing Space files in ${WORKDIR}..."
rsync -a \
  --exclude '.venv' \
  --exclude 'models' \
  --exclude '__pycache__' \
  --exclude '.git' \
  "${ROOT}/" "${WORKDIR}/"

cp "${ROOT}/README_TRAIN_SPACE.md" "${WORKDIR}/README.md"

echo "==> Creating / updating Space ${SPACE_ID}..."
python - <<PY
from huggingface_hub import HfApi
api = HfApi(token="${TOKEN}")
api.create_repo("${SPACE_ID}", repo_type="space", space_sdk="gradio", exist_ok=True)
PY

echo "==> Uploading to Hugging Face Space..."
python - <<PY
from huggingface_hub import HfApi
api = HfApi(token="${TOKEN}")
api.upload_folder(
    folder_path="${WORKDIR}",
    repo_id="${SPACE_ID}",
    repo_type="space",
    commit_message="Deploy CodeBERT training Space",
)
PY

echo "==> Done: https://huggingface.co/spaces/${SPACE_ID}"
echo "Next: Space Settings → Hardware → GPU t4-small"
echo "      Space Settings → Secrets → HF_TOKEN"