# ── 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"]