Spaces:
Running on Zero
Running on Zero
| set -euo pipefail | |
| ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | |
| PYTHON_BIN="${PYTHON_BIN:-$ROOT_DIR/.venv/bin/python}" | |
| HOST="${HOST:-0.0.0.0}" | |
| REQUESTED_PORT="${PORT:-7860}" | |
| if [[ ! -x "$PYTHON_BIN" ]]; then | |
| PYTHON_BIN="${PYTHON_BIN_FALLBACK:-python3}" | |
| fi | |
| PORT="$("$PYTHON_BIN" - "$REQUESTED_PORT" "$HOST" <<'PY' | |
| import socket | |
| import sys | |
| start = int(sys.argv[1]) | |
| host = sys.argv[2] | |
| for port in range(start, start + 50): | |
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: | |
| sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
| try: | |
| sock.bind((host, port)) | |
| except OSError: | |
| continue | |
| print(port) | |
| break | |
| else: | |
| raise SystemExit(f"No free port found from {start} to {start + 49}") | |
| PY | |
| )" | |
| detect_lan_ip() { | |
| local ip="" | |
| if command -v ipconfig >/dev/null 2>&1; then | |
| ip="$(ipconfig getifaddr en0 2>/dev/null || true)" | |
| if [[ -z "$ip" ]]; then | |
| local iface | |
| iface="$(route get default 2>/dev/null | awk '/interface:/ {print $2; exit}' || true)" | |
| if [[ -n "$iface" ]]; then | |
| ip="$(ipconfig getifaddr "$iface" 2>/dev/null || true)" | |
| fi | |
| fi | |
| fi | |
| if [[ -z "$ip" ]] && command -v hostname >/dev/null 2>&1; then | |
| ip="$(hostname -I 2>/dev/null | awk '{print $1}' || true)" | |
| fi | |
| printf '%s' "$ip" | |
| } | |
| LAN_IP="${LAN_IP:-$(detect_lan_ip)}" | |
| export BUDDY_FORCE_FAKE_RUNTIME="${BUDDY_FORCE_FAKE_RUNTIME:-1}" | |
| export BUDDY_ASR_BACKEND="${BUDDY_ASR_BACKEND:-browser}" | |
| if [[ -n "$LAN_IP" ]]; then | |
| LAN_URL="http://$LAN_IP:$PORT" | |
| else | |
| LAN_URL="LAN IP not detected. Check your Wi-Fi IP and use http://<your-ip>:$PORT" | |
| fi | |
| LAN_WARNING="" | |
| case "$HOST" in | |
| 127.0.0.1|localhost|::1) | |
| LAN_WARNING="HOST=127.0.0.1 will block other devices. Use HOST=0.0.0.0 for iPad / LAN testing." | |
| ;; | |
| esac | |
| if [[ -n "$LAN_WARNING" ]]; then | |
| LAN_WARNING_LINE=" $LAN_WARNING" | |
| else | |
| LAN_WARNING_LINE="" | |
| fi | |
| cat <<EOF | |
| Build-a-Buddy local test server | |
| Local: | |
| http://127.0.0.1:$PORT | |
| iPad / Wi-Fi: | |
| Open this on iPad Safari while both devices are on the same Wi-Fi: | |
| $LAN_URL | |
| ${LAN_WARNING_LINE} | |
| Runtime: | |
| BUDDY_FORCE_FAKE_RUNTIME=$BUDDY_FORCE_FAKE_RUNTIME | |
| BUDDY_ASR_BACKEND=$BUDDY_ASR_BACKEND | |
| Tips: | |
| PORT=7861 scripts/start-local.sh | |
| scripts/start-local-real-model.sh | |
| Press Ctrl+C to stop. | |
| EOF | |
| cd "$ROOT_DIR" | |
| "$PYTHON_BIN" - "$HOST" "$PORT" <<'PY' | |
| from pathlib import Path | |
| import sys | |
| root = Path.cwd() | |
| sys.path.insert(0, str(root / "src")) | |
| from buddy_fusion.fusion_ui import CSS, FUSION_HEAD, build_app | |
| host = sys.argv[1] | |
| port = int(sys.argv[2]) | |
| demo = build_app() | |
| # Bind on `host` (0.0.0.0 by default, so iPad / LAN devices can reach it) but | |
| # show the loopback URL: Gradio's own banner would print the bound 0.0.0.0, | |
| # which is not a clickable address. quiet=True suppresses that banner. | |
| print(f"Running on local URL: http://127.0.0.1:{port}", flush=True) | |
| demo.launch(server_name=host, server_port=port, share=False, css=CSS, head=FUSION_HEAD, quiet=True) | |
| PY | |