File size: 2,302 Bytes
36720a3
39028c9
 
 
 
 
 
 
 
 
 
c9b24fa
 
39028c9
c9b24fa
 
 
 
 
 
 
 
 
36720a3
 
39028c9
c9b24fa
36720a3
39028c9
c9b24fa
39028c9
 
36720a3
 
c9b24fa
36720a3
 
 
 
c9b24fa
39028c9
c9b24fa
39028c9
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
# ── Contexto Backend – Hugging Face Spaces (CPU) ──────────────────────────────
FROM python:3.10-slim

EXPOSE 7860

RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc g++ git curl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# ── Step 1: Upgrade pip ────────────────────────────────────────────────────────
RUN pip install --no-cache-dir --upgrade pip

# ── Step 2: Pin NumPy <2.0 FIRST (faiss-cpu needs numpy.core, removed in 2.0) ─
RUN pip install --no-cache-dir "numpy>=1.24.0,<2.0.0"

# ── Step 3: Install PyTorch CPU-only ──────────────────────────────────────────
RUN pip install --no-cache-dir \
    torch==2.2.2 \
    --index-url https://download.pytorch.org/whl/cpu

# ── Step 4: Install remaining dependencies ────────────────────────────────────
COPY requirements_hf.txt ./requirements_hf.txt
RUN pip install --no-cache-dir -r requirements_hf.txt

# ── Step 5: Copy source ───────────────────────────────────────────────────────
COPY . .

# ── Step 6: HuggingFace cache config ─────────────────────────────────────────
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
ENV HF_HOME=/app/.cache/huggingface
ENV TOKENIZERS_PARALLELISM=false

# Pre-download T5-small to bake into image
RUN python -c "\
from transformers import T5Tokenizer, T5ForConditionalGeneration; \
T5Tokenizer.from_pretrained('t5-small'); \
T5ForConditionalGeneration.from_pretrained('t5-small'); \
print('T5-small cached.')" || echo "Model will download at runtime"

# ── Step 7: Run on port 7860 ──────────────────────────────────────────────────
CMD ["uvicorn", "src.api:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]