Spaces:
Sleeping
Sleeping
File size: 1,921 Bytes
f063646 79f58fb f063646 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #!/usr/bin/env bash
# One-click: venv -> install -> build SPA -> serve -> open browser.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
if command -v python3.11 >/dev/null 2>&1; then
PY=python3.11
elif command -v python3 >/dev/null 2>&1; then
PY=python3
else
echo "ERROR: python3.11 (or python3) not found." >&2
case "$(uname -s)" in
Darwin) echo " Install with: brew install python@3.11" >&2 ;;
Linux) echo " Install with your package manager, e.g.: sudo apt install python3.11 python3.11-venv" >&2 ;;
esac
exit 1
fi
if ! command -v npm >/dev/null 2>&1; then
echo "ERROR: npm not found." >&2
case "$(uname -s)" in
Darwin) echo " Install with: brew install node" >&2 ;;
Linux) echo " Install with your package manager, e.g.: sudo apt install nodejs npm" >&2 ;;
esac
exit 1
fi
if [ ! -d .venv ]; then
echo "==> Creating venv (.venv) with $PY"
"$PY" -m venv .venv
fi
# shellcheck source=/dev/null
. .venv/bin/activate
REQ_HASH=$(shasum requirements.txt | awk '{print $1}')
MARKER=".venv/.installed-marker"
if [ ! -f "$MARKER" ] || [ "$(cat "$MARKER")" != "$REQ_HASH" ]; then
echo "==> Installing python deps"
pip install --upgrade pip
pip install -r requirements.txt
echo "$REQ_HASH" > "$MARKER"
fi
if [ ! -d web/node_modules ]; then
echo "==> Installing web deps"
(cd web && npm ci)
fi
if [ ! -d server/static ] || [ ! -f web/dist/index.html ]; then
echo "==> Building web"
(cd web && npm run build)
rm -rf server/static
mkdir -p server/static
cp -R web/dist/* server/static/
fi
export PYTORCH_ENABLE_MPS_FALLBACK="${PYTORCH_ENABLE_MPS_FALLBACK:-1}"
HOST="${HOST:-127.0.0.1}"
PORT="${PORT:-7860}"
URL="http://$HOST:$PORT"
echo "==> Serving on $URL"
( sleep 2 && python -m webbrowser "$URL" ) &
exec uvicorn server.main:app --host "$HOST" --port "$PORT"
|