Files
SR-Label-SamTool/sam2-backend/run.sh
2026-04-25 16:23:09 +05:30

33 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Convenience launcher for the SAM2 backend.
# Assumes a venv at ./.venv with requirements.txt + torch + sam2 installed.
# See README.md for install steps.
set -euo pipefail
cd "$(dirname "$0")"
if [ -d ".venv" ]; then
# shellcheck disable=SC1091
source .venv/bin/activate
fi
HOST="${HOST:-0.0.0.0}"
PORT="${PORT:-9090}"
DEVICE="${DEVICE:-auto}"
# Privacy: disable HF/transformers telemetry, and (after weights are cached)
# refuse any outbound calls to huggingface.co. Inference runs fully local
# regardless; these just stop the cosmetic pings on startup.
export HF_HUB_DISABLE_TELEMETRY="${HF_HUB_DISABLE_TELEMETRY:-1}"
export DO_NOT_TRACK="${DO_NOT_TRACK:-1}"
# Flip both OFFLINE flags to 1 once you've done the first `from_pretrained`
# and the weights are cached under ~/.cache/huggingface/. Leaving them 0
# the first time lets the model download. After that, set them 1 to fully
# air-gap and silence the HEAD-request revalidation pings on every startup.
# HF_HUB_OFFLINE — used by huggingface_hub
# TRANSFORMERS_OFFLINE — used by transformers itself (some legacy paths)
export HF_HUB_OFFLINE="${HF_HUB_OFFLINE:-0}"
export TRANSFORMERS_OFFLINE="${TRANSFORMERS_OFFLINE:-0}"
exec python server.py --host "$HOST" --port "$PORT" --device "$DEVICE" "$@"