FROM python:3.10-slim WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ curl \ && rm -rf /var/lib/apt/lists/* # Install Python dependencies in layers to optimize caching and avoid timeouts COPY requirements.txt . # 1. Install core dependencies RUN pip install --no-cache-dir fastapi uvicorn pydantic-settings python-multipart pypdf python-docx # 2. Install ML/RAG dependencies (Large) RUN pip install --no-cache-dir langchain langchain-community langchain-huggingface langchain-text-splitters sentence-transformers chromadb huggingface-hub # 3. Install Torch and Transformers (Very Large) RUN pip install --no-cache-dir torch transformers accelerate bitsandbytes # Copy application code COPY . . # Create user with UID 1000 (standard for HF Spaces) RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Expose the standard HF port EXPOSE 7860 CMD ["python", "main.py"]