-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·32 lines (28 loc) · 880 Bytes
/
Copy pathstart.sh
File metadata and controls
executable file
·32 lines (28 loc) · 880 Bytes
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
#!/usr/bin/env bash
set -euo pipefail
APP_DIR="/app"
MODEL_PKL="$APP_DIR/delivery_predictor/model/logistic_model.pkl"
TRAIN_SCRIPT="$APP_DIR/delivery_predictor/model/train_model.py"
echo "[start] Ensuring model and data exist..."
if [ ! -f "$MODEL_PKL" ]; then
echo "[start] Model not found, training..."
python "$TRAIN_SCRIPT"
else
# Optionally retrain using existing CSV to handle version changes
echo "[start] Model found. Verifying load..."
python - <<'PY'
import joblib, sys
from pathlib import Path
try:
joblib.load(Path("/app/delivery_predictor/model/logistic_model.pkl"))
print("[start] Model loaded successfully.")
except Exception as e:
print(f"[start] Model load failed: {e}. Retraining...")
sys.exit(42)
PY
if [ "$?" -ne 0 ]; then
python "$TRAIN_SCRIPT"
fi
fi
echo "[start] Starting gunicorn..."
exec gunicorn -w 2 -b 0.0.0.0:5000 app:application