Spaces:
Sleeping
Sleeping
File size: 1,225 Bytes
54a9b55 | 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 | FROM python:3.10-slim
# HF Spaces requires a non-root user with uid 1000
RUN useradd -m -u 1000 user
WORKDIR /app
# Install CPU-only PyTorch before requirements.txt so sentence-transformers
# doesn't pull the full CUDA build (~2 GB) as a transitive dependency.
RUN pip install --no-cache-dir \
torch \
--index-url https://download.pytorch.org/whl/cpu
# Copy and install remaining dependencies as a separate layer so source-only
# changes don't invalidate the (slow) pip install cache.
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Pre-download the embedding model into the image so first-request latency
# on the Space is not penalised by a ~90 MB download at runtime.
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
# Copy source last — this layer changes most often
COPY --chown=user:user . .
USER user
ENV PYTHONUNBUFFERED=1 \
# Bind to all interfaces so HF Spaces proxy can reach the server
GRADIO_SERVER_NAME=0.0.0.0 \
GRADIO_SERVER_PORT=7860 \
# Keep HuggingFace model cache inside the container's home
HF_HOME=/home/user/.cache/huggingface
EXPOSE 7860
CMD ["python", "app_gradio.py"]
|