File size: 1,120 Bytes
cc8b90c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# push_to_hf.sh — Push current branch to Hugging Face Space main using HF_TOKEN.
#
# Usage:
#   bash scripts/push_to_hf.sh
#   HF_SPACE_REPO="spaces/ous-sow/sahel-agri-voice" bash scripts/push_to_hf.sh

set -euo pipefail

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

HF_SPACE_REPO="${HF_SPACE_REPO:-spaces/ous-sow/sahel-agri-voice}"
TARGET_BRANCH="${TARGET_BRANCH:-main}"

# Load .env if present and HF_TOKEN is not already exported.
if [[ -z "${HF_TOKEN:-}" && -f "$REPO_ROOT/.env" ]]; then
    set -a
    # shellcheck disable=SC1091
    source "$REPO_ROOT/.env"
    set +a
fi

if [[ -z "${HF_TOKEN:-}" ]]; then
    echo "HF_TOKEN is not set."
    echo "Set HF_TOKEN in your shell or in .env, then rerun."
    exit 1
fi

CURRENT_BRANCH="$(git branch --show-current)"
if [[ -z "$CURRENT_BRANCH" ]]; then
    echo "Could not detect current git branch."
    exit 1
fi

echo "Pushing '$CURRENT_BRANCH' to '$HF_SPACE_REPO' (remote branch: '$TARGET_BRANCH')..."
git push "https://__token__:${HF_TOKEN}@huggingface.co/${HF_SPACE_REPO}" "${CURRENT_BRANCH}:${TARGET_BRANCH}"
echo "Done."