File size: 1,245 Bytes
d96f0ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef5d512
 
 
d96f0ad
ef5d512
 
 
d96f0ad
 
 
 
 
 
 
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
# Hugging Face Spaces (Docker SDK) image for the FastAPI backend.
# Spaces routes traffic to port 7860 by default.
FROM python:3.11-slim

# System libraries needed at runtime by torch (OpenMP via libgomp) and by
# chromadb/onnxruntime; ca-certificates for HTTPS model downloads.
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libgomp1 \
        ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# Use the PyTorch backend only; never import TensorFlow/Keras in transformers.
ENV USE_TF=0 \
    USE_TORCH=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1

WORKDIR /app

# Install Python deps first so this layer caches across code changes.
# Install the CPU-only torch wheel up front: Spaces has no GPU, so this avoids
# pulling ~6 GB of unused NVIDIA CUDA libraries. sentence-transformers then sees
# torch is already satisfied and skips the default CUDA build.
COPY requirements.txt ./
RUN pip install --upgrade pip \
    && pip install torch --index-url https://download.pytorch.org/whl/cpu \
    && pip install -r requirements.txt

# Copy the rest of the project (the .dockerignore keeps secrets/db/web out).
COPY . .

EXPOSE 7860

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