-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·88 lines (74 loc) · 2.19 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·88 lines (74 loc) · 2.19 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
#!/usr/bin/env bash
set -euo pipefail
# Legal Matter & Spend Analytics Dashboard — one-command launcher
# Usage: ./start.sh
API_PORT=8000
FRONTEND_PORT=8501
API_PID=""
FRONTEND_PID=""
SHUTTING_DOWN=0
cleanup() {
# Guard against duplicate cleanup (trap can fire twice)
[ "$SHUTTING_DOWN" -eq 1 ] && return
SHUTTING_DOWN=1
echo ""
echo "Shutting down..."
[ -n "$FRONTEND_PID" ] && kill "$FRONTEND_PID" 2>/dev/null
[ -n "$API_PID" ] && kill "$API_PID" 2>/dev/null
wait 2>/dev/null
echo "Done."
exit 0
}
trap cleanup INT TERM
# Check Python version
if ! command -v python3 &>/dev/null; then
echo "Error: Python 3 is not installed."
echo "Install Python 3.11+ from https://www.python.org/downloads/"
exit 1
fi
PY_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.minor}")')
if [ "$PY_VERSION" -lt 11 ]; then
echo "Error: Python 3.11+ is required (found 3.$PY_VERSION)."
echo "Install Python 3.11+ from https://www.python.org/downloads/"
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR"
# Create and activate virtual environment
if [ ! -d ".venv" ]; then
echo "Creating virtual environment..."
python3 -m venv .venv
fi
source .venv/bin/activate
# Install dependencies if not already installed
if ! python -c "import fastapi" 2>/dev/null; then
echo "Installing dependencies..."
pip install -q .
fi
echo "Starting API server on port $API_PORT..."
uvicorn lsa_app.main:app --port "$API_PORT" &
API_PID=$!
echo "Starting frontend on port $FRONTEND_PORT..."
streamlit run lsa_frontend/app.py --server.port "$FRONTEND_PORT" --server.headless true &
FRONTEND_PID=$!
# Wait for API to be ready
echo "Waiting for API..."
for i in $(seq 1 30); do
if curl -sf "http://localhost:$API_PORT/health" >/dev/null 2>&1; then
echo "API is ready."
break
fi
sleep 1
done
# Open browser
if command -v open &>/dev/null; then
open "http://localhost:$FRONTEND_PORT"
elif command -v xdg-open &>/dev/null; then
xdg-open "http://localhost:$FRONTEND_PORT"
fi
echo ""
echo "Dashboard: http://localhost:$FRONTEND_PORT"
echo "API docs: http://localhost:$API_PORT/docs"
echo "Press Ctrl+C to stop."
echo ""
wait