File size: 1,282 Bytes
07476a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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}"