File size: 1,363 Bytes
7acb327 | 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 | #!/usr/bin/env bash
# Download a model file from Hugging Face into models/.
#
# ./get-model.sh <repo> list the .gguf files in the repo
# ./get-model.sh <repo> <file> download one of them
#
# Private repos need a token: export HF_TOKEN=hf_... (huggingface.co -> Settings -> Access Tokens)
set -euo pipefail
HERE=$(cd "$(dirname "$0")" && pwd)
REPO=${1:?usage: ./get-model.sh <huggingface-repo> [file.gguf]}
FILE=${2:-}
AUTH=()
[[ -n "${HF_TOKEN:-}" ]] && AUTH=(-H "Authorization: Bearer $HF_TOKEN")
if [[ -z "$FILE" ]]; then
echo "GGUF files in $REPO:"
curl -fsSL ${AUTH[@]+"${AUTH[@]}"} "https://huggingface.co/api/models/$REPO" \
| grep -o '"rfilename":"[^"]*\.gguf"' | sed 's/"rfilename":"\(.*\)"/ \1/' \
|| { echo "Could not read $REPO. Check the name, and set HF_TOKEN if the repo is private."; exit 1; }
echo
echo "Download one with: ./get-model.sh $REPO <file>"
exit 0
fi
mkdir -p "$HERE/models"
OUT="$HERE/models/$(basename "$FILE")"
echo "Downloading $FILE to models/ (it resumes if interrupted)"
curl -fL -C - --progress-bar ${AUTH[@]+"${AUTH[@]}"} -o "$OUT" "https://huggingface.co/$REPO/resolve/main/$FILE" \
|| { echo "Download failed. Check the file name, and set HF_TOKEN if the repo is private."; exit 1; }
echo "Saved $OUT"
echo "Run it with: ./run.sh models/$(basename "$FILE")"
|