File size: 1,028 Bytes
5850cd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
set -euo pipefail

if ! command -v git >/dev/null 2>&1; then
  echo "git is required"
  exit 1
fi
if ! command -v hf >/dev/null 2>&1; then
  echo "Install huggingface_hub CLI first: pip install -U huggingface_hub"
  exit 1
fi

HF_USER="${1:-}"
SPACE_NAME="${2:-}"

if [[ -z "${HF_USER}" || -z "${SPACE_NAME}" ]]; then
  echo "Usage: bash scripts/deploy_hf_space.sh <hf-username> <space-name>"
  exit 1
fi

SPACE_ID="${HF_USER}/${SPACE_NAME}"
SPACE_REMOTE_URL="https://huggingface.co/spaces/${SPACE_ID}"

echo "Creating Space (if it does not exist): ${SPACE_ID}"
hf repo create "${SPACE_ID}" --type space --space_sdk docker -y || true

if git remote | rg -x "hf-space" >/dev/null 2>&1; then
  git remote set-url hf-space "${SPACE_REMOTE_URL}"
else
  git remote add hf-space "${SPACE_REMOTE_URL}"
fi

echo "Pushing current branch to HF Space..."
git push hf-space HEAD:main

echo "Done."
echo "Space URL: https://huggingface.co/spaces/${SPACE_ID}"
echo "Runtime URL: https://${HF_USER}-${SPACE_NAME}.hf.space"