File size: 2,215 Bytes
3ac20c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
# Deploy this static Space to Hugging Face.
#
#   ./deploy.sh <hf-username> <space-name>
#
# Example:
#   ./deploy.sh swnesbitt us-tornado-density
#
# Create the Space first at https://huggingface.co/new-space with SDK: Static.
# When git asks for a password, paste a WRITE token from
# https://huggingface.co/settings/tokens (not your account password).

set -euo pipefail

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

if [[ -z "$HF_USER" || -z "$HF_SPACE" ]]; then
  echo "usage: ./deploy.sh <hf-username> <space-name>" >&2
  exit 1
fi

cd "$(dirname "$0")"
echo "==> Deploying $(pwd)"
echo "    to https://huggingface.co/spaces/$HF_USER/$HF_SPACE"
echo

# A previous attempt left a half-initialized repo that git cannot reuse, and any
# earlier commit still contains the binaries Hugging Face rejected. Start clean.
if [[ -d .git ]]; then
  echo "==> Removing existing .git (starting from a clean history)"
  rm -rf .git
fi

echo "==> Building the commit"
git init -q
git add -A
git -c user.email="${GIT_AUTHOR_EMAIL:-$(git config --global user.email || echo you@example.com)}" \
    -c user.name="${GIT_AUTHOR_NAME:-$(git config --global user.name || echo deploy)}" \
    commit -q -m "Annual tornado density browser, 1950-2026"
git branch -M main

# Guard: nothing binary should reach Hugging Face's pre-receive hook.
echo "==> Checking for files HF would reject"
if git ls-files | grep -qE '\.u8$|\.u16$'; then
  echo "    ERROR: raw binary arrays are staged; check .gitignore" >&2
  exit 1
fi
BIN=0
while IFS= read -r f; do
  if LC_ALL=C grep -qI . "$f" 2>/dev/null; then :; else BIN=$((BIN+1)); echo "    binary: $f"; fi
done < <(git ls-files)
echo "    $(git ls-files | wc -l | tr -d ' ') files staged, $BIN binary"
if [[ $BIN -gt 0 ]]; then
  echo "    WARNING: binary files present. If the push is rejected, either run" >&2
  echo "    'git lfs install' and re-run, or add them to .gitignore." >&2
fi

echo "==> Pushing"
git remote remove hf 2>/dev/null || true
git remote add hf "https://huggingface.co/spaces/$HF_USER/$HF_SPACE"
git push hf main --force

echo
echo "==> Done. Open https://huggingface.co/spaces/$HF_USER/$HF_SPACE"
echo "    Hard-refresh with Cmd-Shift-R if it looks stale."