| # ββ Hugging Face Spaces β Docker SDK βββββββββββββββββββββββββββββββββββββββββ | |
| # Base image: Python 3.10 slim | |
| FROM python:3.10-slim | |
| # HF Spaces requires a non-root user | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| WORKDIR $HOME/app | |
| # Install dependencies first (cached layer β only re-runs when requirements change) | |
| COPY --chown=user requirements.txt . | |
| RUN pip install --no-cache-dir --upgrade -r requirements.txt | |
| # Pre-download the embedding model at build time so startup is instant | |
| RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')" | |
| # Copy all project files | |
| COPY --chown=user . . | |
| # Create required runtime directories | |
| RUN mkdir -p faiss_index uploads | |
| # HF Spaces expects port 7860 | |
| ENV PORT=7860 | |
| # Start the server | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] | |