#!/usr/bin/env bash # One-command setup: venv + deps + model weights (~1.8 GB from HuggingFace). # ./setup.sh modern GPU (sm_70+, CUDA 12.x) or CPU # ./setup.sh --pascal Pascal/Maxwell/Volta cards (GTX 9/10, TITAN, V100): # pins torch 2.6.0+cu124, the last wheels shipping # sm_61 kernels # ./setup.sh --skip-weights keep existing weights/ set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" PASCAL=0; SKIP_WEIGHTS=0; PYCAND="" while [[ $# -gt 0 ]]; do case "$1" in --pascal) PASCAL=1 ;; --skip-weights) SKIP_WEIGHTS=1 ;; --python) PYCAND="${2:?--python needs a path}"; shift ;; --python=*) PYCAND="${1#*=}" ;; *) echo "unknown flag: $1"; exit 1 ;; esac shift done command -v python3 >/dev/null || { echo "python3 required (3.10-3.12)"; exit 1; } echo "== venv" # numpy 1.26.4 / torch 2.6 ship cp310-cp312 wheels only: pick an interpreter # in range whose venv works (some distros ship python3 without ensurepip). [[ -z "$PYCAND" ]] || VENV_PY="$(command -v "$PYCAND" || echo "$PYCAND")" for cand in ${VENV_PY:-} python3.12 python3.11 python3.10 python3; do command -v "$cand" >/dev/null 2>&1 || [ -x "$cand" ] || continue "$cand" -c 'import sys; raise SystemExit(0 if (3,10) <= sys.version_info < (3,13) else 1)' 2>/dev/null || continue rm -rf .venv "$cand" -m venv .venv 2>/dev/null && [ -x .venv/bin/pip ] && break done if [ ! -x .venv/bin/pip ]; then rm -rf .venv echo "could not create a Python 3.10-3.12 venv. Fix either way:" echo " apt install python3-venv (Debian/Ubuntu)" echo " ./setup.sh --python /path/to/python3.12 (e.g. a conda interpreter)" exit 1 fi .venv/bin/pip install -q --upgrade pip echo "== torch" if [[ $PASCAL == 1 ]]; then .venv/bin/pip install -q torch==2.6.0 torchvision==0.21.0 \ --index-url https://download.pytorch.org/whl/cu124 else .venv/bin/pip install -q torch torchvision fi echo "== rest of requirements (a few minutes)" .venv/bin/pip install -q -r requirements.txt if [[ $SKIP_WEIGHTS == 0 && -f weights/icon_detect_v3/model.pt && -f weights/icon_caption_florence/model.safetensors ]]; then echo "== weights already present - skipping download" SKIP_WEIGHTS=1 fi if [[ $SKIP_WEIGHTS == 0 ]]; then echo "== weights (~1.8 GB from huggingface.co/microsoft/OmniParser-v2.0)" mkdir -p weights/icon_caption_florence weights/icon_detect_v3 base=https://huggingface.co/microsoft/OmniParser-v2.0/resolve/main curl -fSL --retry 3 -o weights/icon_caption_florence/config.json "$base/icon_caption/config.json" curl -fSL --retry 3 -o weights/icon_caption_florence/generation_config.json "$base/icon_caption/generation_config.json" curl -fSL --retry 3 -o weights/icon_caption_florence/model.safetensors "$base/icon_caption/model.safetensors" # YOLOv9-E icon detector (upstream recommends the icon_detect_v3 revision) curl -fSL --retry 3 -o weights/icon_detect_v3/model.pt \ "https://huggingface.co/microsoft/OmniParser-v2.0/resolve/refs%2Fpr%2F37/icon_detect_v3/model.pt" # fail at setup, not as a cryptic model-load crash at boot for f in weights/icon_caption_florence/model.safetensors weights/icon_detect_v3/model.pt; do [[ $(stat -c%s "$f" 2>/dev/null || echo 0) -gt 100000000 ]] || { echo "FAILED: $f missing or truncated (got $(stat -c%s "$f" 2>/dev/null || echo 0) bytes)" echo " (HTML error pages land here too - check network/HF status)"; exit 1; } done for f in weights/icon_caption_florence/config.json weights/icon_caption_florence/generation_config.json; do test -s "$f" || { echo "FAILED: $f empty"; exit 1; } done echo "== weights verified" fi .venv/bin/python - <<'EOF' import torch print(f"torch {torch.__version__} cuda={torch.cuda.is_available()}" + (f" device={torch.cuda.get_device_name(0)} arch={torch.cuda.get_device_capability(0)}" if torch.cuda.is_available() else " (CPU only - parses will be slow)")) EOF echo echo "done. next:" echo " ./start.sh # start the service (health-checked, self-tested)" echo " then register the MCP tool in your harness (README: 'MCP registration')"