#!/usr/bin/env bash # Start (or restart) the TinySOC Gradio app, detached from the shell session. set -eo pipefail cd "$(dirname "$0")" # Load local config if present (.env is gitignored; copy from .env.example). [ -f .env ] && { set -a; . ./.env; set +a; } PORT="${GRADIO_SERVER_PORT:-7860}" if pid=$(ss -ltnp 2>/dev/null | awk -v p=":$PORT" '$4 ~ p {print $0}' | grep -oP 'pid=\K[0-9]+' | head -1); then [ -n "${pid:-}" ] && { echo "Stopping existing instance (pid $pid)"; kill "$pid" 2>/dev/null || true; sleep 1; } fi PYTHON="${PYTHON:-python3}" [ -x .venv/bin/python ] && PYTHON=.venv/bin/python setsid "$PYTHON" app_tinysoc.py >> /tmp/tinysoc-app.log 2>&1 & echo "Started: http://0.0.0.0:$PORT"