Spaces:
Runtime error
Runtime error
File size: 3,938 Bytes
ad32c0c 01864b9 ad32c0c 01864b9 ad32c0c 78ef80b ad32c0c 78ef80b ad32c0c 01864b9 ad32c0c 4399f7f ad32c0c 01864b9 ad32c0c 78ef80b ad32c0c 01864b9 ad32c0c 01864b9 ad32c0c 7126efe ad32c0c 0f0ba30 ad32c0c 01864b9 ad32c0c 01864b9 ad32c0c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# Use a smaller base image if possible, but maintain CUDA compatibility
FROM nvidia/cuda:11.7.1-base-ubuntu22.04 AS base
ENV DEBIAN_FRONTEND=noninteractive
# Create user and directories early to leverage caching
RUN adduser --disabled-password --gecos '' user && \
mkdir -p /content/stable-diffusion-webui/models/Stable-diffusion && \
chown -R user:user /content
WORKDIR /content
USER user
# Pre-download model in a separate stage for better caching
FROM base AS model-downloader
ADD https://huggingface.co/darkstorm2150/OpenGen/resolve/main/OpenGen%20v1.0.safetensors \
/tmp/OpenGen%20v1.0.safetensors
USER root
RUN mv "/tmp/OpenGen%20v1.0.safetensors" \
"/content/stable-diffusion-webui/models/Stable-diffusion/OpenGen v1.0.safetensors"
USER user
# Main build stage with optimized layers
FROM base AS final
COPY --from=model-downloader /content/stable-diffusion-webui/models/Stable-diffusion/OpenGen%20v1.0.safetensors /content/stable-diffusion-webui/models/Stable-diffusion/
# Install system dependencies efficiently
RUN apt-get update && \
apt-get install -y --no-install-recommends \
libgl1 libglib2.0-0 wget git git-lfs python3-pip python-is-python3 && \
rm -rf /var/lib/apt/lists/*
# Combine pip installations into a single layer
RUN pip3 install --upgrade pip==23.3.1 && \
pip install --no-cache-dir \
torchmetrics==0.11.4 \
numexpr \
httpx==0.24.1 \
pytorch_lightning==1.7.6 \
https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.16/xformers-0.0.16+814314d.d20230119.A10G-cp310-cp310-linux_x86_64.whl \
--pre triton
# Clone repository and apply patches in a single step
RUN git clone -b v1.6 https://github.com/camenduru/stable-diffusion-webui && \
cd stable-diffusion-webui && \
sed -i 's/dict()))/dict())).cuda()/g' repositories/stable-diffusion-stability-ai/ldm/util.py && \
sed -i '/prepare_environment()/a os.system("sed -i -e '\''s/dict()))/dict())).cuda()/g'\'' repositories/stable-diffusion-stability-ai/ldm/util.py")' launch.py && \
sed -i 's/start()/#start()/g' launch.py && \
echo "fastapi==0.90.0" >> requirements_versions.txt && \
python launch.py --skip-torch-cuda-test
# Apply configuration patches
ADD --chown=user https://github.com/camenduru/webui-docker/raw/main/env_patch.py /content/
ADD --chown=user https://raw.githubusercontent.com/darkstorm2150/webui/refs/heads/main/OpenGen_header_patch.py /content/
RUN sed -i '/import image_from_url_text/r /content/env_patch.py' stable-diffusion-webui/modules/ui.py && \
sed -i '/demo:/r /content/header_patch.py' stable-diffusion-webui/modules/ui.py
# Cleanup and optimizations
RUN rm -rf stable-diffusion-webui/scripts && \
sed -i -e '/(modelmerger_interface, "Checkpoint Merger", "modelmerger"),/d' \
-e '/(train_interface, "Train", "ti"),/d' \
-e '/extensions_interface, "Extensions", "extensions"/d' \
-e '/settings_interface, "Settings", "settings"/d' \
-e 's/document.getElementsByTagName.*shadowRoot/!!& ? & : document/g' stable-diffusion-webui/script.js && \
sed -i 's/show_progress=False/show_progress=True/g' stable-diffusion-webui/modules/ui.py && \
sed -i 's/default_enabled=False/default_enabled=True/g' stable-diffusion-webui/webui.py && \
sed -i 's/ outputs=\[/queue=False, &/g' stable-diffusion-webui/modules/ui.py && \
sed -i 's/queue=False, //g' stable-diffusion-webui/modules/ui.py
# Add configuration files
ADD --chown=user https://github.com/camenduru/webui-docker/raw/main/shared-config.json /content/
ADD --chown=user https://github.com/camenduru/webui-docker/raw/main/shared-ui-config.json /content/
EXPOSE 7860
CMD ["python", "webui.py", "--xformers", "--listen", "--disable-console-progressbars", "--enable-console-prompts", "--no-progressbar-hiding", "--ui-config-file", "/content/shared-ui-config.json", "--ui-settings-file", "/content/shared-config.json"] |