FROM python:3.10-slim-bullseye # Install necessary system packages RUN apt-get update && apt-get install -y \ software-properties-common \ build-essential \ checkinstall \ cmake \ make \ pkg-config \ yasm \ git \ vim \ curl \ wget \ sudo \ apt-transport-https \ libcanberra-gtk-module \ libcanberra-gtk3-module \ dbus-x11 \ iputils-ping \ python3-dev \ python3-pip \ python3-setuptools \ libjpeg-dev \ libpng-dev \ libtiff5-dev \ libtiff-dev \ libavcodec-dev \ libavformat-dev \ libswscale-dev \ libdc1394-22-dev \ libxine2-dev \ libavfilter-dev \ libavutil-dev \ ffmpeg \ && apt-get clean \ && rm -rf /tmp/* /var/tmp/* /var/lib/apt/lists/* \ && apt-get -y autoremove # Upgrade pip and install Python packages RUN pip install --no-cache-dir --upgrade pip \ && pip install --no-cache-dir torch==2.2.0 torchvision==0.17.0 \ && pip install --no-cache-dir poetry==1.8.3 tzdata==2024.1 \ && pip install --no-cache-dir gradio==4.41.0 \ && pip install --no-cache-dir opencv-python # Set up non-root user RUN useradd -m -u 1000 user USER user # Set working directory and copy application files WORKDIR /app COPY --chown=user:user . /app COPY --chown=user:user pyproject.toml script.sh download_models.sh requirements.txt ./ RUN chmod +x script.sh download_models.sh # Run scripts and install dependencies USER root RUN ./script.sh \ && poetry config virtualenvs.create false \ && ./download_models.sh \ && poetry install --no-interaction --no-ansi --no-dev \ && pip cache purge \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Set user back to non-root and expose port USER user EXPOSE 7860 # Start the application CMD ["python", "grad.py"]