File size: 1,785 Bytes
56749a4
 
 
 
 
 
 
 
 
ed66956
56749a4
 
 
ed66956
 
 
56749a4
ed66956
 
 
 
 
56749a4
 
 
ed66956
 
56749a4
 
 
 
ed66956
 
 
 
 
 
 
 
56749a4
 
 
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
34
35
36
37
38
39
40
41
42
43
FROM python:3.12-slim

# HF Spaces runs containers as a non-root user; create one and give it a writable
# HF cache so the baked-in model is readable at runtime.
RUN useradd -m -u 1000 user
ENV HF_HOME=/home/user/.cache/huggingface \
    PYTHONUNBUFFERED=1
WORKDIR /home/user/app

# Runtime dependencies only; pytest/httpx live in requirements-dev.txt.
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# The checkpoint, its pinned revision and the tower file. The bake below and
# text_encoder.py both read these, so the image holds exactly what the app
# resolves offline at start.
ARG SIGLIP_MODEL_ID=onnx-community/siglip2-base-patch16-256-ONNX
ARG SIGLIP_MODEL_REVISION=d1114256522a37ffa257a0a58017348ab0058db2
ARG SIGLIP_TEXT_ONNX_FILE=onnx/text_model_quantized.onnx
ENV SIGLIP_MODEL_ID=${SIGLIP_MODEL_ID} \
    SIGLIP_MODEL_REVISION=${SIGLIP_MODEL_REVISION} \
    SIGLIP_TEXT_ONNX_FILE=${SIGLIP_TEXT_ONNX_FILE}

USER user
# Bake the 283 MB text tower + tokenizer into the image so a post-sleep wake
# never re-downloads from HuggingFace. This layer sits above the app code, so
# a code-only change rebuilds from the cache without fetching the model again.
RUN python -c "import os; \
from huggingface_hub import hf_hub_download; \
from transformers import AutoTokenizer; \
m = os.environ['SIGLIP_MODEL_ID']; \
r = os.environ['SIGLIP_MODEL_REVISION']; \
hf_hub_download(m, os.environ['SIGLIP_TEXT_ONNX_FILE'], revision=r); \
AutoTokenizer.from_pretrained(m, revision=r)"
# Everything the app loads is now on disk: resolve it from the cache without
# asking the Hub, so a start never waits on (or fails with) the network.
ENV HF_HUB_OFFLINE=1

COPY text_encoder.py app.py ./

EXPOSE 7860
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]