Skip to main content

Stable Diffusion Web UI

Laboratory OS Installation Details

Environment

Git Repohttps://github.com/AUTOMATIC1111/stable-diffusion-webui
Working Directory/workspace/stable-diffusion-webui
Python3.11
Env Manageruv

Environment Variables

APP_DIRECTORY
/workspace/stable-diffusion-webui
SD_WEBUI_PORT
<assigned at runtime>
APP_VERSIONWhich version of the app to use, using a git branch name or commit hash.
82a973c

Install & Run

install-and-run.sh
#!/bin/bash
set -e

export PATH="/opt/conda/bin:/root/.local/bin:$PATH"

# Clone the GitHub repository into the directory when needed
mkdir -p "/workspace/stable-diffusion-webui"
if [ -d "/workspace/stable-diffusion-webui/.git" ]; then
  echo "Git repository already initialized in /workspace/stable-diffusion-webui"
elif [ -z "$(ls -A "/workspace/stable-diffusion-webui" 2>/dev/null)" ]; then
  git clone --progress "https://github.com/AUTOMATIC1111/stable-diffusion-webui" "/workspace/stable-diffusion-webui"
else
  echo "Working directory /workspace/stable-diffusion-webui already exists and is not a git repository."
  echo "Leaving existing files untouched and skipping clone of https://github.com/AUTOMATIC1111/stable-diffusion-webui."
fi
  
# Change to the app directory
cd "/workspace/stable-diffusion-webui"

# Install the requested Python version and create a virtual environment when needed
uv python install 3.11
if [ ! -d ".venv" ]; then
  uv venv --seed --python 3.11 .venv
else
  echo "Virtual environment already exists at /workspace/stable-diffusion-webui/.venv"
fi

# Activate the virtual environment
source .venv/bin/activate


# Install PyTorch
uv pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu128

# Environment setup complete
echo "Environment setup complete!"

export STABLE_DIFFUSION_REPO="https://github.com/w-e-w/stablediffusion.git"
python3 -m pip install "setuptools==69.5.1"
python3 -m pip install -r "$APP_DIRECTORY/requirements_versions.txt"
python3 -m pip install joblib
# CLIP's legacy build breaks under isolated builds with newer setuptools/pkg_resources changes.
python3 -m pip install --no-build-isolation "https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip"

export STABLE_DIFFUSION_REPO="https://github.com/w-e-w/stablediffusion.git"
python3 "$APP_DIRECTORY/launch.py" --api --port "$SD_WEBUI_PORT" --skip-torch-cuda-test --no-download-sd-model $OPENLAB_EXTRA_ARGS