0f5277c22e
Pre-download via HF mirror scripts so inner-network deploys avoid Hub Network is unreachable errors. Co-authored-by: Cursor <cursoragent@cursor.com>
60 lines
1.8 KiB
Bash
60 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
# 预下载 Faster-Whisper 模型(HF 镜像,内网服务器离线可用)
|
|
# 用法: bash scripts/download_whisper_models.sh [tiny|base|small|medium|large-v3]
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
SIZE="${1:-small}"
|
|
VENV_PY="${ROOT}/venv/bin/python"
|
|
MODEL_DIR="${WHISPER_MODEL_DIR:-${ROOT}/models/whisper}/${SIZE}"
|
|
|
|
export HF_ENDPOINT="${HF_ENDPOINT:-https://hf-mirror.com}"
|
|
export HF_HUB_DOWNLOAD_TIMEOUT="${HF_HUB_DOWNLOAD_TIMEOUT:-600}"
|
|
export HF_HOME="${HF_HOME:-${ROOT}/models/hf_cache}"
|
|
export MODEL_DIR
|
|
export WHISPER_SIZE="${SIZE}"
|
|
|
|
echo "[INFO] Whisper 模型: ${SIZE}"
|
|
echo "[INFO] 保存目录: ${MODEL_DIR}"
|
|
echo "[INFO] HF 镜像: ${HF_ENDPOINT}"
|
|
|
|
if [[ ! -x "${VENV_PY}" ]]; then
|
|
echo "[ERROR] 未找到 venv,请先 bash deploy.sh deps"
|
|
exit 1
|
|
fi
|
|
|
|
"${VENV_PY}" -m pip install -q huggingface_hub
|
|
|
|
"${VENV_PY}" << 'PY'
|
|
import os
|
|
from pathlib import Path
|
|
from huggingface_hub import snapshot_download
|
|
|
|
size = os.environ["WHISPER_SIZE"]
|
|
repos = {
|
|
"tiny": "Systran/faster-whisper-tiny",
|
|
"base": "Systran/faster-whisper-base",
|
|
"small": "Systran/faster-whisper-small",
|
|
"medium": "Systran/faster-whisper-medium",
|
|
"large-v2": "Systran/faster-whisper-large-v2",
|
|
"large-v3": "Systran/faster-whisper-large-v3",
|
|
}
|
|
repo = repos.get(size)
|
|
if not repo:
|
|
raise SystemExit(f"未知模型尺寸: {size}, 可选: {list(repos)}")
|
|
|
|
target = Path(os.environ["MODEL_DIR"])
|
|
target.mkdir(parents=True, exist_ok=True)
|
|
|
|
print(f"[INFO] 正在下载 {repo} ...")
|
|
snapshot_download(repo_id=repo, local_dir=str(target), local_dir_use_symlinks=False)
|
|
|
|
if not (target / "model.bin").is_file():
|
|
raise SystemExit(f"[ERROR] 下载不完整,未找到 model.bin: {target}")
|
|
|
|
print(f"[OK] Whisper 模型就绪: {target}")
|
|
PY
|
|
|
|
echo ""
|
|
echo "[OK] 请执行: pm2 restart trading_studio"
|