levineuwirth.org/tools/download-model.sh

39 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# download-model.sh — Download the quantized ONNX model for client-side semantic search.
#
# Downloads Xenova/all-MiniLM-L6-v2 (quantized ONNX, ~22 MB total) from HuggingFace
# into static/models/all-MiniLM-L6-v2/ so it can be served same-origin, keeping the
# nginx CSP to 'self' for connect-src.
#
# Run once before deploying. Files are gitignored (binary artifacts).
# Re-running is safe — existing files are skipped.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
MODEL_DIR="$REPO_ROOT/static/models/all-MiniLM-L6-v2"
BASE_URL="https://huggingface.co/Xenova/all-MiniLM-L6-v2/resolve/main"
mkdir -p "$MODEL_DIR/onnx"
fetch() {
local src="$1" dst="$2"
if [ -f "$dst" ]; then
echo " skip $src (already present)"
return
fi
echo " fetch $src"
curl -fsSL --progress-bar "$BASE_URL/$src" -o "$dst"
}
echo "Downloading all-MiniLM-L6-v2 to $MODEL_DIR ..."
fetch "config.json" "$MODEL_DIR/config.json"
fetch "tokenizer.json" "$MODEL_DIR/tokenizer.json"
fetch "tokenizer_config.json" "$MODEL_DIR/tokenizer_config.json"
fetch "special_tokens_map.json" "$MODEL_DIR/special_tokens_map.json"
fetch "onnx/model_quantized.onnx" "$MODEL_DIR/onnx/model_quantized.onnx"
echo "Done. static/models/all-MiniLM-L6-v2/ is ready."
echo "Run 'make build' to copy the model files into _site/."