FROM python:3.10-slim WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* # Install lightweight PyTorch CPU build to accelerate cloud deployment RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu # Install remaining dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Configure non-root user for Hugging Face Spaces (UID 1000) RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ PYTHONPATH=/home/user/app/src:/home/user/app \ PORT=7860 WORKDIR $HOME/app # Copy application files with proper ownership COPY --chown=user . $HOME/app EXPOSE 7860 CMD ["python", "app.py"]