#!/usr/bin/env bash # Boot: fetch the Qdrant snapshot from the HF dataset, start Qdrant, recover the collection, # then serve the API + SPA on 7860. Free HF Spaces have no persistent disk, so this runs on every # cold start (~a few minutes to download the ~3.7GB snapshot + load models). set -euo pipefail SNAP_DIR="${QDRANT__STORAGE__SNAPSHOTS_PATH:-/home/user/app/qdrant_data/snapshots}" STORE_DIR="${QDRANT__STORAGE__STORAGE_PATH:-/home/user/app/qdrant_data/storage}" mkdir -p "$SNAP_DIR" "$STORE_DIR" status_of() { # -> collection status string ("" if absent) curl -s localhost:6333/collections/reviewsearch 2>/dev/null \ | python -c "import sys,json;print(json.load(sys.stdin).get('result',{}).get('status',''))" 2>/dev/null || echo "" } echo "[start] fetching Qdrant snapshot from HF dataset..." python - < /home/user/app/qdrant.log 2>&1 & for _ in $(seq 1 60); do curl -sf localhost:6333/healthz >/dev/null 2>&1 && break; sleep 1; done echo "[start] Qdrant healthy" if [ "$(status_of)" != "green" ]; then echo "[start] recovering collection from snapshot..." curl -s -X PUT localhost:6333/collections/reviewsearch/snapshots/recover \ -H 'content-type: application/json' \ -d "{\"location\":\"file://$SNAP_DIR/reviewsearch.snapshot\"}" echo fi for _ in $(seq 1 300); do [ "$(status_of)" = "green" ] && break; sleep 1; done echo "[start] collection status: $(status_of)" echo "[start] launching uvicorn on :7860" exec uvicorn reviewsearch.serve.app:app --host 0.0.0.0 --port 7860