File size: 1,893 Bytes
0360a02
b5d6ec4
7b04b3a
 
b5d6ec4
d7dbf7e
b5d6ec4
 
bf87feb
d7dbf7e
 
b5d6ec4
d7dbf7e
7b04b3a
b5d6ec4
 
 
 
 
 
 
 
 
 
 
5c88d83
 
b5d6ec4
 
 
 
 
f76da4e
7b04b3a
5c88d83
ee5887a
 
71786b7
 
ee5887a
 
 
 
71786b7
ee5887a
 
71786b7
5c88d83
b5d6ec4
7b04b3a
b5d6ec4
d7dbf7e
b5d6ec4
7b04b3a
5c88d83
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
FROM python:3.11-slim

WORKDIR /app

# Installation des dépendances système
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    git \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copie des requirements d'abord pour le cache Docker
COPY requirements.txt /app/requirements.txt

# Installer PyTorch et torchvision AVANT le reste
RUN pip install --no-cache-dir --default-timeout=600 \
    torch>=2.1.0 torchvision>=0.16.0 \
    -f https://download.pytorch.org/whl/torch_stable.html

# Installer timm pour les modèles de vision
RUN pip install --no-cache-dir timm>=0.9.0

# Installer les dépendances pour les modèles de vision
RUN pip install --no-cache-dir pillow>=10.0.0

# Installer FastAPI et uvicorn
RUN pip install --no-cache-dir fastapi uvicorn[standard]

# Installer le reste des dépendances
RUN pip install --no-cache-dir --default-timeout=600 -r requirements.txt -i https://pypi.org/simple

# Copie du code source
COPY . /app/

# Créer les dossiers cache et donner les droits d'écriture
RUN mkdir -p /home/user/.cache/huggingface /home/user/.cache/transformers /tmp/model_offload /tmp/model_repo && \
    chmod -R 777 /home/user/.cache /tmp/model_offload /tmp/model_repo
# Set environment variables
ENV PYTHONPATH=/app
ENV HOME=/home/user
ENV HF_HOME=/home/user/.cache/huggingface
ENV HUGGINGFACE_HUB_CACHE=/home/user/.cache/huggingface
ENV TRANSFORMERS_CACHE=/home/user/.cache/transformers
ENV HF_HUB_ENABLE_HF_TRANSFER=0
ENV HF_HUB_DISABLE_SYMLINKS_WARNING=1
ENV HF_HUB_DISABLE_PROGRESS_BARS=1
ENV MODEL_ID=google/gemma-3n-E4B-it
ENV DEVICE_MAP=cpu
ENV MAX_NEW_TOKENS=256

# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:7860/health || exit 1

# Commande de démarrage - FastAPI directement
CMD ["uvicorn", "src.app:app", "--host", "0.0.0.0", "--port", "7860"]