Spaces:
Sleeping
Sleeping
| set -e | |
| # Default: ephemeral store path (use a mounted bucket + KINK_STORE_PATH for persistence). | |
| : "${KINK_STORE_PATH:=/tmp/kink_store.db}" | |
| : "${KINK_SEED_PATH:=/app/deploy/hf/seed/hf_bundled_store.db}" | |
| export KINK_STORE_PATH | |
| if [ ! -f "$KINK_STORE_PATH" ]; then | |
| mkdir -p "$(dirname "$KINK_STORE_PATH")" | |
| # Full-catalog images: never copy the bundled seed. If Hub dataset or HTTPS URL is set, leave DB missing for bootstrap. | |
| # Do not require KINK_HF_DATASET_REPO to be unset: Spaces often keep a stale repo id; bundled mode still wins in api. | |
| # Skip copy when opting into Hub dataset without full-catalog flag (KINK_HF_USE_HUB_DATASET=1). | |
| if [ "${KINK_HF_REQUIRE_FULL_CATALOG:-0}" != "1" ] && [ "${KINK_HF_USE_HUB_DATASET:-0}" != "1" ] && [ -z "${KINK_CATALOG_URL:-}" ] && [ -z "${B2_BUCKET:-}" ] && [ -z "${B2_KEY_ID:-}" ] && [ -f "$KINK_SEED_PATH" ]; then | |
| cp "$KINK_SEED_PATH" "$KINK_STORE_PATH" | |
| fi | |
| fi | |
| # Pre-built catalog pickle (saves ~3-5 minutes of in-memory rebuild on cpu-basic on every cold boot). | |
| # Lives in the image so it survives container restarts that wipe /tmp. | |
| STORE_DIR="$(dirname "$KINK_STORE_PATH")" | |
| STORE_BASENAME="$(basename "$KINK_STORE_PATH")" | |
| PICKLE_DST="$STORE_DIR/.$STORE_BASENAME.catalog_v1.pkl" | |
| PICKLE_SRC=/app/deploy/hf/seed/catalog.pkl | |
| if [ -f "$PICKLE_SRC" ] && [ ! -f "$PICKLE_DST" ]; then | |
| cp "$PICKLE_SRC" "$PICKLE_DST" | |
| echo "kink_cli: seeded catalog pickle ($(stat -c%s "$PICKLE_DST") bytes)" >&2 | |
| fi | |
| # Bundled kink photos (same-origin /media/...; required when COEP is enabled — external hotlinks break). | |
| # Copy entire seed cache tree (demo ``hf_seed`` + optional ``fetlife_fetishes/…`` placeholders for catalog probes). | |
| SEED_CACHE=/app/deploy/hf/seed/cached_assets | |
| TARGET_CACHE=/app/data/cached_assets | |
| if [ ! -d "$SEED_CACHE" ]; then | |
| echo "kink_cli: missing seed media dir $SEED_CACHE (image fallbacks will break)" >&2 | |
| exit 1 | |
| fi | |
| mkdir -p "$TARGET_CACHE" | |
| cp -a "$SEED_CACHE"/. "$TARGET_CACHE"/ | |
| if [ ! -f "$TARGET_CACHE/hf_seed/demo_kink_1.jpg" ]; then | |
| echo "kink_cli: expected $TARGET_CACHE/hf_seed/demo_kink_1.jpg after copying seed cached_assets" >&2 | |
| exit 1 | |
| fi | |
| # Hugging Face Spaces sets PORT (often 7860) | |
| : "${PORT:=7860}" | |
| export PORT | |
| exec uvicorn api:app --host 0.0.0.0 --port "$PORT" | |