| FROM python:3.11-slim | |
| # Install build tools for torch.compile | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create a non-root user with home directory for cache | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| WORKDIR /home/user/app | |
| # Set cache directory to user's home | |
| ENV HOME=/home/user | |
| ENV HF_HOME=/home/user/.cache/huggingface | |
| ENV TRANSFORMERS_CACHE=/home/user/.cache/huggingface/transformers | |
| ENV HF_DATASETS_CACHE=/home/user/.cache/huggingface/datasets | |
| # Install dependencies as user (use --user flag) | |
| RUN pip install --user --no-cache-dir \ | |
| torch \ | |
| transformers>=4.48.0 \ | |
| datasets \ | |
| evaluate \ | |
| seqeval \ | |
| accelerate>=1.0.0 \ | |
| huggingface_hub \ | |
| gradio | |
| # Add user's pip bin to PATH | |
| ENV PATH="/home/user/.local/bin:${PATH}" | |
| # Copy training script and app | |
| COPY --chown=user:user train.py . | |
| COPY --chown=user:user app.py . | |
| # Expose Gradio port | |
| EXPOSE 7860 | |
| # Run Gradio app which starts training in background | |
| CMD ["python", "app.py"] | |