FROM python:3.12-slim # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ libpq-dev \ curl \ && rm -rf /var/lib/apt/lists/* # Add a non-root user RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" WORKDIR /app # Copy and install Python dependencies COPY --chown=user ./requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Pre-download Spacy model RUN python -m spacy download pt_core_news_md # Pre-download T5 models RUN python -c "from transformers import T5Tokenizer, T5ForConditionalGeneration; \ T5Tokenizer.from_pretrained('unicamp-dl/ptt5-base-portuguese-vocab'); \ T5ForConditionalGeneration.from_pretrained('recogna-nlp/ptt5-base-summ')" # Copy application code COPY --chown=user . /app # Expose the application port EXPOSE 7860 # Run the application CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]