-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.command
More file actions
executable file
·86 lines (72 loc) · 2.24 KB
/
Copy pathstart.command
File metadata and controls
executable file
·86 lines (72 loc) · 2.24 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
#!/bin/zsh
set -euo pipefail
# Load user shell environment so API keys from ~/.zshrc are available
# when this script is launched outside an interactive terminal.
if [[ -f "$HOME/.zprofile" ]]; then
source "$HOME/.zprofile"
fi
if [[ -f "$HOME/.zshrc" ]]; then
source "$HOME/.zshrc"
fi
SCRIPT_DIR="$(cd -- "$(dirname -- "$0")" && pwd)"
APP_DIR="$SCRIPT_DIR/codequest-ai-tutor"
ROOT_VENV_PYTHON="$SCRIPT_DIR/.venv/bin/python"
APP_VENV_PYTHON="$APP_DIR/.venv/bin/python"
APP_URL="http://127.0.0.1:8501"
HEALTH_URL="$APP_URL/_stcore/health"
LOG_FILE="/tmp/codequest-ai-tutor.log"
open_dashboard() {
if command -v open >/dev/null 2>&1; then
open "$APP_URL"
return 0
fi
if command -v xdg-open >/dev/null 2>&1; then
xdg-open "$APP_URL" >/dev/null 2>&1 &
return 0
fi
"$PYTHON_CMD" -c "import webbrowser; webbrowser.open('$APP_URL')" >/dev/null 2>&1 || true
}
if [[ -x "$ROOT_VENV_PYTHON" ]]; then
PYTHON_CMD="$ROOT_VENV_PYTHON"
elif [[ -x "$APP_VENV_PYTHON" ]]; then
PYTHON_CMD="$APP_VENV_PYTHON"
elif command -v python3 >/dev/null 2>&1; then
PYTHON_CMD="$(command -v python3)"
else
echo "Python 3 was not found."
echo "Create the virtual environment first, then try again."
read -r "?Press Enter to close this window..."
exit 1
fi
if [[ ! -d "$APP_DIR" ]]; then
echo "App folder not found: $APP_DIR"
read -r "?Press Enter to close this window..."
exit 1
fi
cd "$APP_DIR"
if ! "$PYTHON_CMD" -c "import streamlit" >/dev/null 2>&1; then
echo "Streamlit is not installed for $PYTHON_CMD"
echo "Install dependencies first with:"
echo " $PYTHON_CMD -m pip install -r requirements.txt"
read -r "?Press Enter to close this window..."
exit 1
fi
if curl -fsS "$HEALTH_URL" >/dev/null 2>&1; then
echo "CodeQuest AI Tutor is already running. Opening dashboard..."
open_dashboard
exit 0
fi
echo "Starting CodeQuest AI Tutor..."
"$PYTHON_CMD" -m streamlit run app/main.py --server.headless true > "$LOG_FILE" 2>&1 &
for _attempt in {1..30}; do
if curl -fsS "$HEALTH_URL" >/dev/null 2>&1; then
echo "Dashboard is ready. Opening browser..."
open_dashboard
exit 0
fi
sleep 1
done
echo "The app server did not become ready in time."
echo "Check the log at $LOG_FILE"
read -r "?Press Enter to close this window..."
exit 1