pediatric-ai-scribe-v3/scripts/download-whisper-models.sh
ifedan-ed a528bcc283 FIX: Browser Whisper - 100% self-hosted, zero CDN dependencies
FINAL WORKING SOLUTION:

Previous attempts failed because:
- transformers.js v2.17.2 is ES module-only
- Module workers require complex CSP and external imports
- importScripts() doesn't work with ES modules

Solution:
- Use transformers.js v2.6.2 (has worker-compatible UMD build)
- Bundle library + models, serve entirely from our server
- Classic worker with importScripts() - no CSP issues

What's self-hosted:
-  transformers.min.js (760KB) - at /models/transformers.min.js
-  Whisper models (42MB) - at /models/Xenova/whisper-tiny.en/

Worker loads:
1. importScripts('/models/transformers.min.js') - OUR SERVER
2. Loads models from /models/ - OUR SERVER
3. ZERO external network calls
4. Works in any network (firewalled, air-gapped, etc.)

This is the production-ready, truly offline solution.
2026-03-31 23:12:21 +00:00

69 lines
2.7 KiB
Bash
Executable file

#!/bin/bash
# Download Browser Whisper models for local development
# These are bundled during Docker build, but need manual download for dev
set -e
cd "$(dirname "$0")/.."
MODELS_DIR="public/models"
echo "🎙️ Downloading Browser Whisper models..."
echo ""
# Create directories
mkdir -p "$MODELS_DIR/Xenova/whisper-tiny.en/onnx"
# Download transformers.js (worker-compatible build)
echo "📦 Downloading transformers.js..."
curl -L --progress-bar -o "$MODELS_DIR/transformers.min.js" \
"https://cdn.jsdelivr.net/npm/@xenova/transformers@2.6.2/dist/transformers.min.js"
echo "✅ transformers.min.js ($(du -h $MODELS_DIR/transformers.min.js | cut -f1))"
echo ""
# Download model config files
echo "📝 Downloading model configs..."
cd "$MODELS_DIR/Xenova/whisper-tiny.en"
curl -sL -o config.json \
"https://huggingface.co/Xenova/whisper-tiny.en/resolve/main/config.json"
echo "✅ config.json ($(du -h config.json | cut -f1))"
curl -sL -o tokenizer.json \
"https://huggingface.co/Xenova/whisper-tiny.en/resolve/main/tokenizer.json"
echo "✅ tokenizer.json ($(du -h tokenizer.json | cut -f1))"
curl -sL -o preprocessor_config.json \
"https://huggingface.co/Xenova/whisper-tiny.en/resolve/main/preprocessor_config.json"
echo "✅ preprocessor_config.json ($(du -h preprocessor_config.json | cut -f1))"
curl -sL -o generation_config.json \
"https://huggingface.co/Xenova/whisper-tiny.en/resolve/main/generation_config.json"
echo "✅ generation_config.json ($(du -h generation_config.json | cut -f1))"
echo ""
# Download ONNX models (large files)
echo "🧠 Downloading encoder model..."
curl -L --progress-bar -o onnx/encoder_model_quantized.onnx \
"https://huggingface.co/Xenova/whisper-tiny.en/resolve/main/onnx/encoder_model_quantized.onnx"
echo "✅ encoder_model_quantized.onnx ($(du -h onnx/encoder_model_quantized.onnx | cut -f1))"
echo ""
echo "🧠 Downloading decoder model..."
curl -L --progress-bar -o onnx/decoder_model_merged_quantized.onnx \
"https://huggingface.co/Xenova/whisper-tiny.en/resolve/main/onnx/decoder_model_merged_quantized.onnx"
echo "✅ decoder_model_merged_quantized.onnx ($(du -h onnx/decoder_model_merged_quantized.onnx | cut -f1))"
echo ""
# Show summary
cd - > /dev/null
echo "════════════════════════════════════════"
echo "✅ Browser Whisper models downloaded!"
echo "════════════════════════════════════════"
echo "Total size: $(du -sh $MODELS_DIR | cut -f1)"
echo ""
echo "Files:"
ls -lh "$MODELS_DIR/Xenova/whisper-tiny.en/" | tail -n +2
echo ""
ls -lh "$MODELS_DIR/Xenova/whisper-tiny.en/onnx/" | tail -n +2
echo ""
echo "Models are ready for use. Start server with: npm start"