| #!/usr/bin/env bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| set -euo pipefail |
|
|
| cd "$(dirname "$0")/.." |
|
|
| HACKATHON_OWNER="${FORMSCOUT_HF_HACKATHON_OWNER:-build-small-hackathon}" |
| REPO_NAME="small-functional-movement-screening" |
| SPACE_REPO="spaces/$HACKATHON_OWNER/$REPO_NAME" |
| MSG="${1:-$(git log -1 --pretty=%s)}" |
| LARGE_THRESHOLD="${FORMSCOUT_HF_LARGE_THRESHOLD:-500}" |
|
|
| |
| |
| PATTERNS=( |
| "*.pdf" |
| "**/node_modules/**" |
| ".cache/**" |
| ) |
|
|
| |
| |
| |
| while IFS= read -r line; do |
| line="${line%%#*}" |
| line="${line#"${line%%[![:space:]]*}"}" |
| line="${line%"${line##*[![:space:]]}"}" |
| [[ -z "$line" ]] && continue |
| if [[ "$line" == */ ]]; then |
| PATTERNS+=("${line}**" "**/${line}**") |
| else |
| PATTERNS+=("$line" "**/$line") |
| fi |
| done < .hfignore |
|
|
| EXCLUDES=() |
| for p in "${PATTERNS[@]}"; do |
| EXCLUDES+=(--exclude="$p") |
| done |
|
|
| |
| |
| N_FILES=$(python3 - "${PATTERNS[@]}" <<'EOF' |
| import sys |
| from pathlib import Path |
| from huggingface_hub.utils import filter_repo_objects |
|
|
| patterns = sys.argv[1:] |
| files = ( |
| str(p) for p in Path(".").rglob("*") |
| if p.is_file() and p.parts[0] != ".git" |
| ) |
| print(len(list(filter_repo_objects(files, ignore_patterns=patterns)))) |
| EOF |
| ) |
| echo "ββ $N_FILES files to upload after .hfignore filtering" |
|
|
| if (( N_FILES == 0 )); then |
| echo "β nothing to upload β check .hfignore" >&2 |
| exit 1 |
| fi |
|
|
| if (( N_FILES > LARGE_THRESHOLD )); then |
| echo "ββ $SPACE_REPO: $N_FILES files > $LARGE_THRESHOLD, using upload-large-folder" |
| echo " (resumable; commits directly to main β no PR, no custom message)" |
| hf upload-large-folder "$SPACE_REPO" . "${EXCLUDES[@]}" |
| else |
| echo "ββ uploading (PR) to: $SPACE_REPO" |
| hf upload "$SPACE_REPO" . . "${EXCLUDES[@]}" --create-pr --commit-message="$MSG" |
| fi |
|
|
| echo "β done β PR opened on $SPACE_REPO (review & merge in the HF UI)" |
|
|