#!/usr/bin/env bash
# entrypoint.sh — pre-warm OmniVoice weights (k2-fsa/OmniVoice) into the
# persistent HF cache on first run, then exec the Gradio demo.
#
# The demo also auto-downloads on first synth, so the pre-warm is
# best-effort (NON-FATAL): it just makes the first generation fast +
# deterministic and lets the healthcheck come up against a ready model.
set -e

: "${HF_HOME:=/app/hf_cache}"
export HF_HOME
mkdir -p "${HF_HOME}"

MARKER="${HF_HOME}/.omnivoice-prewarmed"
if [ ! -f "${MARKER}" ]; then
    echo "[omnivoice] pre-warming k2-fsa/OmniVoice weights into ${HF_HOME} (one-time)…"
    if python3 - <<'EOF'
from huggingface_hub import snapshot_download
snapshot_download(repo_id="k2-fsa/OmniVoice")
print("[omnivoice] pre-warm complete")
EOF
    then
        touch "${MARKER}"
    else
        echo "[omnivoice] pre-warm failed (non-fatal) — demo will download on first synth"
    fi
fi

exec "$@"
