Spaces:
Running
Running
| # Use an official Python runtime as a parent image | |
| FROM python:3.11-slim | |
| # Set environment variables | |
| ENV PYTHONDONTWRITEBYTECODE 1 | |
| ENV PYTHONUNBUFFERED 1 | |
| ENV HOME=/home/user | |
| ENV PATH=/home/user/.local/bin:$PATH | |
| ENV PYTHONPATH=$HOME/app | |
| # Install system dependencies | |
| USER root | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create a non-root user | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| WORKDIR $HOME/app | |
| # Copy requirements and install dependencies | |
| COPY --chown=user requirements.txt . | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # Pre-download models to avoid cold-start lag and runtime network issues | |
| # We download both the embedding model and the reranker | |
| RUN python -c "from sentence_transformers import SentenceTransformer, CrossEncoder; \ | |
| SentenceTransformer('BAAI/bge-small-en-v1.5'); \ | |
| CrossEncoder('BAAI/bge-reranker-base')" | |
| # Copy the rest of the application code | |
| COPY --chown=user . . | |
| # Hugging Face Spaces expect the app on port 7860 | |
| EXPOSE 7860 | |
| # Run the application | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] | |