| #!/bin/bash |
| set -e |
|
|
| MODEL_DIR="/app/models" |
| MODEL_FILE="$MODEL_DIR/sam2.1_hiera_large.pt" |
|
|
| mkdir -p "$MODEL_DIR" |
|
|
| if [ ! -f "$MODEL_FILE" ]; then |
| echo "[entrypoint] SAM2 model not found. Downloading from HuggingFace (~900MB)..." |
| python - <<'EOF' |
| from huggingface_hub import hf_hub_download |
| path = hf_hub_download( |
| repo_id="facebook/sam2.1-hiera-large", |
| filename="sam2.1_hiera_large.pt", |
| local_dir="/app/models", |
| ) |
| print(f"[entrypoint] Model saved to {path}") |
| EOF |
| echo "[entrypoint] Download complete." |
| else |
| echo "[entrypoint] SAM2 model already present at $MODEL_FILE. Skipping download." |
| fi |
|
|
| exec uvicorn main:app --host 0.0.0.0 --port "${PORT:-8000}" |
|
|