-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun.sh
More file actions
62 lines (52 loc) · 1.83 KB
/
Copy pathrun.sh
File metadata and controls
62 lines (52 loc) · 1.83 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
#!/usr/bin/env bash
set -euo pipefail
# -----------------------------------------------------------------------------
# GLM-OCR local server launcher (Linux/macOS)
# - Creates/uses .venv next to this script
# - Installs deps on first run (or when FORCE_INSTALL=1)
# - Starts FastAPI on configured host/port
# -----------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV_DIR="$SCRIPT_DIR/.venv"
MODEL_CACHE_DIR="$SCRIPT_DIR/models/hf_cache"
HF_HOME_DIR="$SCRIPT_DIR/models/hf_home"
ENV_FILE="$SCRIPT_DIR/.env"
INSTALL_STAMP="$VENV_DIR/glm_deps_installed.stamp"
if command -v python3 >/dev/null 2>&1; then
PYTHON_BIN="python3"
elif command -v python >/dev/null 2>&1; then
PYTHON_BIN="python"
else
echo "[!] Python is not installed. Install Python 3.10+ and retry."
exit 1
fi
if [[ -f "$ENV_FILE" ]]; then
echo "[+] Loading .env from $ENV_FILE"
set -a
# shellcheck disable=SC1090
source "$ENV_FILE"
set +a
fi
mkdir -p "$MODEL_CACHE_DIR" "$HF_HOME_DIR"
export HF_HOME="$HF_HOME_DIR"
export HF_HUB_CACHE="$MODEL_CACHE_DIR"
export TRANSFORMERS_CACHE="$MODEL_CACHE_DIR"
export GLM_MODEL_CACHE="$MODEL_CACHE_DIR"
if [[ ! -f "$VENV_DIR/bin/activate" ]]; then
echo "[+] Creating virtual environment at $VENV_DIR ..."
"$PYTHON_BIN" -m venv "$VENV_DIR"
fi
# shellcheck disable=SC1091
source "$VENV_DIR/bin/activate"
FORCE_INSTALL="${FORCE_INSTALL:-0}"
if [[ "$FORCE_INSTALL" == "1" || ! -f "$INSTALL_STAMP" ]]; then
echo "[+] Installing dependencies..."
bash "$SCRIPT_DIR/scripts/install.sh"
touch "$INSTALL_STAMP"
else
echo "[*] Reusing existing virtualenv dependencies (set FORCE_INSTALL=1 to reinstall)."
fi
HOST="${HOST:-0.0.0.0}"
PORT="${PORT:-8000}"
echo "[+] Starting server at http://$HOST:$PORT"
exec uvicorn app.main:app --host "$HOST" --port "$PORT"