File size: 1,062 Bytes
2c45e8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM python:3.11-slim

# Évite les prompts apt + bytecode cache
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    HF_HUB_DISABLE_TELEMETRY=1

# HF Spaces s'attend à un user non-root pour les writes (cache HF, etc.)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

WORKDIR /home/user/app

# Install Python deps en premier (cache layer)
COPY --chown=user:user requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy app + warm download du modèle au build (évite cold start sur 1er hit)
COPY --chown=user:user app.py .

# Pre-download le modèle dans le cache HF du container (~800 Mo)
# Économise ~60s sur le 1er request post-deploy
RUN python -c "from transformers import AutoModel, AutoProcessor; \
    AutoModel.from_pretrained('invensync/siglip2-base-invensync-v1'); \
    AutoProcessor.from_pretrained('invensync/siglip2-base-invensync-v1')"

EXPOSE 7860

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