File size: 1,315 Bytes
22a6915
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env bash
# Create HF Space FocusGuard/test_final (Docker) and push hugging_face_final -> main.
# Usage (in your terminal only — do not commit tokens):
#   export HF_TOKEN="hf_..."
#   ./scripts/push_hf_test_final.sh
#
# First push after HF creates the Space: remote `main` may have an initial README
# commit — we use --force so your branch replaces it. Set HF_PUSH_FORCE=0 to refuse
# overwriting if the remote already has your history.

set -euo pipefail
: "${HF_TOKEN:?Set HF_TOKEN (Hugging Face access token with write access)}"

ORG="FocusGuard"
SPACE="test_final"
REPO_ID="${ORG}/${SPACE}"
BRANCH="hugging_face_final"

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"

python3 -m pip install -q 'huggingface_hub>=0.20'

python3 -c "
from huggingface_hub import HfApi
import os
api = HfApi(token=os.environ['HF_TOKEN'])
api.create_repo(
    repo_id='${REPO_ID}',
    repo_type='space',
    space_sdk='docker',
    exist_ok=True,
)
print('Space ${REPO_ID}: OK')
"

command -v git-lfs >/dev/null 2>&1 && git lfs install >/dev/null || true

URL="https://oauth2:${HF_TOKEN}@huggingface.co/spaces/${REPO_ID}.git"
FORCE=(--force)
if [[ "${HF_PUSH_FORCE:-1}" == "0" ]]; then
  FORCE=()
fi
git push "${FORCE[@]}" "${URL}" "${BRANCH}:main"

echo "Done. Open: https://huggingface.co/spaces/${REPO_ID}"