#!/usr/bin/env bash # Download a model file from Hugging Face into models/. # # ./get-model.sh list the .gguf files in the repo # ./get-model.sh 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 [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 " 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")"