#!/bin/sh set -e # Download models when forced or when UBJ artifact is missing if { [ "${FORCE_MODEL_DOWNLOAD}" = "1" ] || [ ! -f "/app/models/regression/resolution_predictor.ubj" ]; } && [ "${SKIP_MODEL_DOWNLOAD}" != "1" ]; then python - << 'PY' import os, shutil from huggingface_hub import snapshot_download repo_id = os.environ.get("MODEL_REPO_ID", "ridzki-nrzngr/gapura-ai-models") local_dir = "/app" try: os.makedirs(local_dir, exist_ok=True) snapshot_download(repo_id=repo_id, local_dir=local_dir, local_dir_use_symlinks=False) double_models = os.path.join("/app", "models", "models") if os.path.isdir(double_models): for name in os.listdir(double_models): src = os.path.join(double_models, name) dst = os.path.join("/app/models", name) if os.path.isdir(src): if os.path.exists(dst): shutil.rmtree(dst) shutil.move(src, dst) else: shutil.move(src, dst) shutil.rmtree(double_models, ignore_errors=True) except Exception as e: print(f"Model download skipped: {e}") PY else echo "Skipping model download (existing models found or SKIP_MODEL_DOWNLOAD=1)" fi exec uvicorn api.main:app --host 0.0.0.0 --port "${PORT:-7860}"