# Use official Python 3.10 slim image FROM python:3.10-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 ENV PORT 7860 # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ libgl1 \ libglib2.0-0 \ && rm -rf /var/lib/apt/lists/* # Create a non-root user (Hugging Face best practice) RUN useradd -m -u 1000 user WORKDIR /home/user/app # Copy requirements first for better caching COPY --chown=user:user requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy the application code and assets COPY --chown=user:user . . # Ensure permissions are correct RUN chmod -R 777 /home/user/app # Switch to the non-root user USER user # Expose the app port EXPOSE 7860 # Start the application CMD ["python", "app.py"]