# Use a lightweight Python base image FROM python:3.12-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV PYTHONPATH=/app ENV PATH="/app/.venv/bin:$PATH" # Set working directory WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ && rm -rf /var/lib/apt/lists/* # Install uv (our package manager) COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ # Copy only requirements first for caching COPY pyproject.toml uv.lock README.md ./ # Install dependencies using uv RUN uv sync --frozen --no-dev # Copy the rest of the application COPY src/ ./src/ COPY profiles/ ./profiles/ # Download knowledge base and indices from Hugging Face Dataset RUN uv pip install huggingface_hub RUN huggingface-cli download JairoDanielMT/prompt-compiler-knowledge-v3 --repo-type dataset --local-dir data/ # Download required spaCy NLP models for English and Spanish RUN python -m spacy download en_core_web_trf RUN python -m spacy download en_core_web_sm # Pre-download Translation models for Always-English pipeline RUN python -c "from transformers import AutoTokenizer; from optimum.onnxruntime import ORTModelForSeq2SeqLM; \ AutoTokenizer.from_pretrained('Xenova/opus-mt-es-en'); \ ORTModelForSeq2SeqLM.from_pretrained('Xenova/opus-mt-es-en')" # Setup a non-root user for Hugging Face Spaces compatibility RUN useradd -m -u 1000 user RUN chown -R user:user /app USER user # Expose the API port expected by Hugging Face Spaces EXPOSE 7860 # Start the API CMD ["uvicorn", "src.api.app:app", "--host", "0.0.0.0", "--port", "7860"]