addgbf commited on
Commit
07a620f
·
verified ·
1 Parent(s): 2c8a1de

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -15
Dockerfile CHANGED
@@ -2,37 +2,51 @@ FROM python:3.11-slim
2
 
3
  ENV PIP_NO_CACHE_DIR=1 \
4
  PYTHONDONTWRITEBYTECODE=1 \
5
- PYTHONUNBUFFERED=1
6
-
7
- ENV APP_CACHE=/tmp/appcache \
8
  XDG_CACHE_HOME=/tmp/appcache \
9
  HF_HOME=/tmp/appcache/hf \
10
  HUGGINGFACE_HUB_CACHE=/tmp/appcache/hf \
11
  TORCH_HOME=/tmp/appcache/torch \
12
  OPENCLIP_CACHE_DIR=/tmp/appcache/open_clip \
13
- HF_HUB_ENABLE_HF_TRANSFER=0
 
 
 
14
 
 
15
  RUN apt-get update && apt-get install -y --no-install-recommends \
16
- build-essential git && \
17
  rm -rf /var/lib/apt/lists/*
18
 
19
  WORKDIR /app
20
 
21
- # deps de proyecto
22
  COPY requirements.txt ./
23
- RUN pip install --upgrade pip && pip install -r requirements.txt
 
 
 
 
24
 
25
- # PyTorch CPU y OpenCLIP
26
- RUN pip install --index-url https://download.pytorch.org/whl/cpu torch torchvision
27
- RUN pip install open_clip_torch
28
 
29
  # copiar codigo y embeddings
30
- COPY server1.py ./
31
- COPY text_embeddings_modelos_bigg.pt ./
32
- COPY text_embeddings_bigg.pt ./
 
 
 
 
 
 
 
 
33
 
34
- # Puerto de Spaces
35
  ENV PORT=7860
36
  EXPOSE 7860
37
 
38
- CMD ["uvicorn", "server1:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
2
 
3
  ENV PIP_NO_CACHE_DIR=1 \
4
  PYTHONDONTWRITEBYTECODE=1 \
5
+ PYTHONUNBUFFERED=1 \
6
+ APP_CACHE=/tmp/appcache \
 
7
  XDG_CACHE_HOME=/tmp/appcache \
8
  HF_HOME=/tmp/appcache/hf \
9
  HUGGINGFACE_HUB_CACHE=/tmp/appcache/hf \
10
  TORCH_HOME=/tmp/appcache/torch \
11
  OPENCLIP_CACHE_DIR=/tmp/appcache/open_clip \
12
+ HF_HUB_ENABLE_HF_TRANSFER=0 \
13
+ OMP_NUM_THREADS=2 \
14
+ MKL_NUM_THREADS=2 \
15
+ NUM_THREADS=2
16
 
17
+ # deps del sistema: OpenMP y build tools
18
  RUN apt-get update && apt-get install -y --no-install-recommends \
19
+ build-essential git libgomp1 && \
20
  rm -rf /var/lib/apt/lists/*
21
 
22
  WORKDIR /app
23
 
24
+ # deps de proyecto (ligeras)
25
  COPY requirements.txt ./
26
+ RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
27
+
28
+ # PyTorch CPU wheels oficiales
29
+ RUN pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cpu \
30
+ torch torchvision
31
 
32
+ # (opcional) asegurar que open_clip este instalado (si no viene por reqs)
33
+ # RUN pip install --no-cache-dir open_clip_torch
 
34
 
35
  # copiar codigo y embeddings
36
+ COPY server1.py ./server1.py
37
+ COPY text_embeddings_modelos_bigg.pt ./text_embeddings_modelos_bigg.pt
38
+ COPY text_embeddings_bigg.pt ./text_embeddings_bigg.pt
39
+
40
+ # (opcional) precarga ligera para evitar cold-start de dependencias
41
+ # No hace forward pesado ni cambia precision
42
+ # RUN python - <<'PY'\n\
43
+ # import open_clip\n\
44
+ # open_clip.create_model_and_transforms('hf-hub:timm/PE-Core-bigG-14-448', pretrained=None)\n\
45
+ # print('open_clip model meta loaded')\n\
46
+ # PY
47
 
 
48
  ENV PORT=7860
49
  EXPOSE 7860
50
 
51
+ # uvloop + httptools (vienen con uvicorn[standard]); 1 worker evita duplicar el modelo
52
+ CMD ["uvicorn", "server1:app", "--host", "0.0.0.0", "--port", "7860", "--loop", "uvloop", "--http", "httptools", "--workers", "1", "--no-server-header", "--timeout-keep-alive", "5"]