#!/usr/bin/env bash # Container entrypoint: ensures the model is present, then launches the Gradio app. # # Behavior: # - If MODEL_SKIP_DOWNLOAD=1, skip the download step (assume the model is # already mounted via a volume or baked into the image). # - Otherwise run download_model.py to fetch weights + config into MODEL_DIR. # - Then exec the Gradio app (default) or whatever command was passed. set -euo pipefail MODEL_DIR="${MODEL_DIR:-/data/model}" export MODEL_DIR echo "[entrypoint] MODEL_DIR=${MODEL_DIR}" echo "[entrypoint] DEVICE=$([[ -e /dev/nvidia0 ]] && echo cuda || echo cpu)" if [[ "${MODEL_SKIP_DOWNLOAD:-0}" != "1" ]]; then if [[ -f "${MODEL_DIR}/model.safetensors" && -f "${MODEL_DIR}/config.json" ]]; then echo "[entrypoint] model already present, skipping download" else echo "[entrypoint] downloading model artifacts..." python /app/download_model.py --model-dir "${MODEL_DIR}" fi else echo "[entrypoint] MODEL_SKIP_DOWNLOAD=1, skipping download" if [[ ! -f "${MODEL_DIR}/model.safetensors" ]]; then echo "[entrypoint] WARNING: ${MODEL_DIR}/model.safetensors missing — app will fail to load" >&2 fi fi if [[ $# -eq 0 ]]; then echo "[entrypoint] launching Gradio app on ${GRADIO_SERVER_NAME:-0.0.0.0}:${GRADIO_SERVER_PORT:-7860}" exec python /app/app.py fi exec "$@"