-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·141 lines (123 loc) · 5.26 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·141 lines (123 loc) · 5.26 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env bash
# ImageForge — one-command bootstrap + launch
# ============================================
# A single entrypoint that gets the HTTP API (or MCP server) running:
# 1. verifies the SD venv exists,
# 2. installs the light HTTP/MCP layer (fastapi, uvicorn, mcp, pydantic*, httpx)
# into it if any piece is missing,
# 3. seeds a .env from .env.example on first run,
# 4. launches the chosen surface.
#
# It does NOT install the heavy SD stack (diffusers/torch/transformers/Pillow/
# accelerate) — those are large and live in the pre-provisioned venv-sd. If they
# are missing this script says so clearly and points at the README, rather than
# silently attempting a multi-GB install.
#
# Usage:
# ./start.sh # launch HTTP API (default, port 8765)
# ./start.sh api # same as above
# ./start.sh api --reload # HTTP API with hot-reload
# ./start.sh mcp # launch the MCP stdio server
# ./start.sh selftest # run the MCP self-test (no GPU, fast)
# ./start.sh check # bootstrap + dependency report, then exit
#
# Environment:
# IMAGEFORGE_VENV path to the SD venv (default: $HOME/.floor-voice-studio/venv-sd)
# HOST / PORT HTTP bind (default 127.0.0.1:8765; also read from .env)
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
VENV_DIR="${IMAGEFORGE_VENV:-$HOME/.floor-voice-studio/venv-sd}"
PYTHON="$VENV_DIR/bin/python"
PIP="$VENV_DIR/bin/pip"
# arch -arm64 keeps us on native Apple-Silicon wheels (matches run_api.sh).
PY=( "$PYTHON" )
if command -v arch >/dev/null 2>&1; then
PY=( arch -arm64 "$PYTHON" )
fi
echo "======================================================================"
echo " ImageForge — bootstrap + launch"
echo "======================================================================"
# ── 1. venv present? ──────────────────────────────────────────────────────────
if [ ! -x "$PYTHON" ]; then
cat >&2 <<EOF
ERROR: SD venv not found at: $VENV_DIR
ImageForge runs inside the shared Apple-Silicon SD venv (it ships with the heavy
diffusers/torch stack pre-installed). Create it, or point IMAGEFORGE_VENV at an
existing one, then re-run. See README.md "Quick start" for details.
EOF
exit 1
fi
# ── 2. light HTTP/MCP layer present? install if missing ───────────────────────
LIGHT_DEPS=(fastapi uvicorn mcp pydantic pydantic_settings httpx)
_have_light() {
"${PY[@]}" - "$@" <<'PYEOF' >/dev/null 2>&1
import importlib, sys
for mod in sys.argv[1:]:
importlib.import_module(mod)
PYEOF
}
if ! _have_light "${LIGHT_DEPS[@]}"; then
echo "==> Installing HTTP/MCP layer into the venv (one-time) ..."
"$PIP" install --quiet \
fastapi "uvicorn[standard]" mcp pydantic pydantic-settings httpx
fi
# ── 3. heavy SD stack present? (report only — never auto-install) ─────────────
HEAVY_OK=1
if ! "${PY[@]}" -c "import diffusers, torch" >/dev/null 2>&1; then
HEAVY_OK=0
fi
# ── 4. seed .env on first run ─────────────────────────────────────────────────
if [ ! -f .env ] && [ -f .env.example ]; then
cp .env.example .env
echo "==> Seeded .env from .env.example (defaults are M2-Pro-16GB-safe)."
fi
# ── Dependency report ─────────────────────────────────────────────────────────
echo " venv : $VENV_DIR"
if [ "$HEAVY_OK" -eq 1 ]; then
echo " SD stack : present (diffusers + torch)"
else
echo " SD stack : MISSING (diffusers/torch not importable)"
echo " /health will still answer, but generation will fail."
echo " Install the heavy stack into the venv per README.md."
fi
MODE="${1:-api}"
case "$MODE" in
check)
echo ""
echo "Bootstrap complete. (mode=check — not launching.)"
[ "$HEAVY_OK" -eq 1 ] && exit 0 || exit 2
;;
api)
shift || true
# Honor .env HOST/PORT, then env overrides.
if [ -f .env ]; then set -a; source .env; set +a; fi
HOST="${HOST:-127.0.0.1}"
PORT="${PORT:-8765}"
echo ""
echo "==> Launching HTTP API on http://${HOST}:${PORT}"
echo " Health : http://${HOST}:${PORT}/health"
echo " Docs : http://${HOST}:${PORT}/docs"
echo ""
exec "${PY[@]}" -m uvicorn imageforge.api.server:app \
--host "$HOST" --port "$PORT" --log-level info "$@"
;;
mcp)
shift || true
echo ""
echo "==> Launching MCP stdio server (imageforge.mcp_server)"
echo " stdout = protocol channel; logs go to stderr."
echo ""
exec "${PY[@]}" -m imageforge.mcp_server "$@"
;;
selftest)
shift || true
echo ""
echo "==> Running MCP self-test ..."
exec "${PY[@]}" -m imageforge.mcp_server --selftest "$@"
;;
*)
echo "ERROR: unknown mode '$MODE'. Use: api | mcp | selftest | check" >&2
exit 1
;;
esac