Spaces:
Build error
Build error
| set -euo pipefail | |
| # Run the Canada → US NWS recolor Gradio demo with minimal fuss. | |
| # | |
| # Usage: | |
| # bash scripts/run_demo.sh [--share] [--port <PORT|auto>] [--opencv] | |
| # | |
| # Examples: | |
| # bash scripts/run_demo.sh --port 7861 | |
| # bash scripts/run_demo.sh --share --port 7861 | |
| # bash scripts/run_demo.sh --opencv --port auto | |
| PORT="7861" | |
| SHARE="0" | |
| WITH_OPENCV="0" | |
| while [[ $# -gt 0 ]]; do | |
| case "$1" in | |
| --share) | |
| SHARE="1"; shift ;; | |
| --opencv) | |
| WITH_OPENCV="1"; shift ;; | |
| --port) | |
| PORT="${2:-7861}"; shift 2 ;; | |
| -h|--help) | |
| echo "Usage: $0 [--share] [--port <PORT|auto>] [--opencv]"; exit 0 ;; | |
| *) | |
| echo "Unknown arg: $1"; exit 1 ;; | |
| esac | |
| done | |
| # Resolve repo root (this script lives in scripts/) | |
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| REPO_ROOT="${SCRIPT_DIR%/scripts}" | |
| cd "$REPO_ROOT" | |
| # Pick Python | |
| if command -v python3 >/dev/null 2>&1; then | |
| PY=python3 | |
| else | |
| PY=python | |
| fi | |
| # Create venv if missing | |
| if [[ ! -d .venv ]]; then | |
| echo "[+] Creating virtualenv .venv" | |
| "$PY" -m venv .venv | |
| fi | |
| echo "[+] Activating venv" | |
| source .venv/bin/activate | |
| echo "[+] Upgrading pip" | |
| python -m pip install -U pip wheel setuptools >/dev/null | |
| if [[ "$WITH_OPENCV" == "1" ]]; then | |
| echo "[+] Installing package with OpenCV extras (for LAB precision)" | |
| pip install -e '.[opencv]' | |
| else | |
| echo "[+] Installing package" | |
| pip install -e . | |
| fi | |
| # Configure Gradio env | |
| if [[ "$PORT" != "auto" ]]; then | |
| export GRADIO_SERVER_PORT="$PORT" | |
| else | |
| # Let Gradio auto-pick a free port by not setting the env var | |
| unset GRADIO_SERVER_PORT 2>/dev/null || true | |
| fi | |
| export GRADIO_SHARE="$SHARE" | |
| echo "[+] Launching Gradio demo (share=$SHARE, port=${PORT})" | |
| echo " Press Ctrl+C to stop." | |
| # Try to open the local URL automatically if a fixed port is chosen | |
| if [[ "$SHARE" != "1" && "$PORT" != "auto" ]]; then | |
| LOCAL_URL="http://127.0.0.1:${PORT}" | |
| if command -v open >/dev/null 2>&1; then | |
| (sleep 2; open "$LOCAL_URL") & | |
| elif command -v xdg-open >/dev/null 2>&1; then | |
| (sleep 2; xdg-open "$LOCAL_URL") & | |
| fi | |
| echo " When ready, your browser should open ${LOCAL_URL}" | |
| fi | |
| python apps/canada_radar_gradio.py | |