From efc8ed13e11d3a51f953c08c74a677a55594db4f Mon Sep 17 00:00:00 2001 From: orionaskatu <100234619+orionaskatu@users.noreply.github.com> Date: Tue, 13 Sep 2022 15:28:04 +0200 Subject: [PATCH 1/5] install/launch scripts for linux --- README.md | 32 +++++++- webui-user.sh | 33 ++++++++ webui.sh | 220 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 284 insertions(+), 1 deletion(-) create mode 100644 webui-user.sh create mode 100644 webui.sh diff --git a/README.md b/README.md index ba2698d3..1eeaae27 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,36 @@ RealESRGAN into the directory with ESRGAN models. Thank you. - _*(optional)*_ place `GFPGANv1.3.pth` into webui directory, next to `webui.bat`. - run `webui-user.bat` from Windows Explorer. Run it as a normal user, ***not*** as administrator. +### Linux Automatic installation/launch + +Prequisites: +- For Debian-based: +```commandline +sudo apt install wget git python3 python3-venv +``` +- For Red Hat-based: +```commandline +sudo dnf install wget git python3 +``` + + +- If you want to install to default directory `/home/$(whoami)/stable-diffusion-webui/`, you can launch directly: +```commandline +bash <(wget -qO- https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-webui/master/webui.sh) +``` + + +- If you want to customize the installation just `git clone` the repo where you want it, +change the variables in `webui-user.sh` and launch in console `bash webui.sh`. + + + +- place `model.ckpt` into webui directory, next to `webui.py`. +- _*(optional)*_ place `GFPGANv1.3.pth` into webui directory, next to `webui.py`. +- run `bash webui.sh`. Run it as a normal user, ***not*** as root. + + + #### Troubleshooting - if your version of Python is not in PATH (or if another version is), edit `webui-user.bat`, and modify the @@ -330,4 +360,4 @@ After that follow the instructions in the `Manual instructions` section starting - Idea for SD upscale - https://github.com/jquesnelle/txt2imghd - CLIP interrogator idea and borrowing some code - https://github.com/pharmapsychotic/clip-interrogator - Initial Gradio script - posted on 4chan by an Anonymous user. Thank you Anonymous user. -- (You) +- (You) \ No newline at end of file diff --git a/webui-user.sh b/webui-user.sh new file mode 100644 index 00000000..d4b8727a --- /dev/null +++ b/webui-user.sh @@ -0,0 +1,33 @@ +#!/bin/bash +########################################### +# Change the variables below to your need:# +########################################### + +# Install directory without trailing slash +install_dir="/home/$(whoami)" + +# Name of the subdirectory (defaults to stable-diffusion-webui) +clone_dir="stable-diffusion-webui" + +# Commandline arguments for webui.py, for example: commandline_args=(--medvram --opt-split-attention) +commandline_args=() + +# python3 executable +python_cmd="python3" + +# pip3 executable +pip_cmd=(python3 -m pip) + +# git executable +git_cmd="git" + +# python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv) +venv_dir="venv" + +# pip3 install command for torch +torch_command=(torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113) + +# Requirements file to use for stable-diffusion-webui +reqs_file="requirements_versions.txt" + +########################################### \ No newline at end of file diff --git a/webui.sh b/webui.sh new file mode 100644 index 00000000..3b482a3e --- /dev/null +++ b/webui.sh @@ -0,0 +1,220 @@ +#!/bin/bash +################################################# +# Please do not make any changes to this file, # +# change the variables in webui-user.sh instead # +################################################# +# Read variables from webui-user.sh +# shellcheck source=/dev/null +if [[ -f webui-user.sh ]] +then + source ./webui-user.sh +fi + +# Set defaults +# Install directory without trailing slash +if [[ -z "${install_dir}" ]] +then + install_dir="/home/$(whoami)" +fi + +# Name of the subdirectory (defaults to stable-diffusion-webui) +if [[ -z "${clone_dir}" ]] +then + clone_dir="stable-diffusion-webui" +fi + +# Commandline arguments for webui.py, for example: commandline_args=(--medvram --opt-split-attention) +if [[ -z "${commandline_args}" ]] +then + commandline_args=() +fi + +# python3 executable +if [[ -z "${python_cmd}" ]] +then + python_cmd="python3" +fi + +# pip3 executable +if [[ -z "${pip_cmd}" ]] +then + pip_cmd=(python3 -m pip) +fi + +# git executable +if [[ -z "${git_cmd}" ]] +then + git_cmd="git" +fi + +# python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv) +if [[ -z "${venv_dir}" ]] +then + venv_dir="venv" +fi + +# pip3 install command for torch +if [[ -z "${torch_command}" ]] +then + torch_command=(torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113) +fi + +# Requirements file to use for stable-diffusion-webui +if [[ -z "${reqs_file}" ]] +then + reqs_file="requirements_versions.txt" +fi + +# Do not reinstall existing pip packages on Debian/Ubuntu +export PIP_IGNORE_INSTALLED=0 + +# Pretty print +delimiter="################################################################" + +printf "\n%s\n" "${delimiter}" +printf "\e[1m\e[32mInstall script for stable-diffusion + Web UI\n" +printf "\e[1m\e[34mTested on Debian 11 (Bullseye)\e[0m" +printf "\n%s\n" "${delimiter}" + +# Do not run as root +if [[ $(id -u) -eq 0 ]] +then + printf "\n%s\n" "${delimiter}" + printf "\e[1m\e[31mERROR: This script must not be launched as root, aborting...\e[0m" + printf "\n%s\n" "${delimiter}" + exit 1 +else + printf "\n%s\n" "${delimiter}" + printf "Running on \e[1m\e[32m%s\e[0m user" "$(whoami)" + printf "\n%s\n" "${delimiter}" +fi + +if [[ -d .git ]] +then + printf "\n%s\n" "${delimiter}" + printf "Repo already cloned, using it as install directory" + printf "\n%s\n" "${delimiter}" + install_dir="${PWD}/../" + clone_dir="${PWD##*/}" +fi + +# Check prequisites +for preq in git python3 +do + if ! hash "${preq}" &>/dev/null + then + printf "\n%s\n" "${delimiter}" + printf "\e[1m\e[31mERROR: %s is not installed, aborting...\e[0m" "${preq}" + printf "\n%s\n" "${delimiter}" + exit 1 + fi +done + +if ! "${python_cmd}" -c "import venv" &>/dev/null +then + printf "\n%s\n" "${delimiter}" + printf "\e[1m\e[31mERROR: python3-venv is not installed, aborting...\e[0m" + printf "\n%s\n" "${delimiter}" + exit 1 +fi + +printf "\n%s\n" "${delimiter}" +printf "Clone or update stable-diffusion-webui" +printf "\n%s\n" "${delimiter}" +cd "${install_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/, aborting...\e[0m" "${install_dir}"; exit 1; } +if [[ -d "${clone_dir}" ]] +then + cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; } + "${git_cmd}" pull +else + "${git_cmd}" clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git "${clone_dir}" + cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; } +fi + +printf "\n%s\n" "${delimiter}" +printf "Clone or update other repositories" +printf "\n%s\n" "${delimiter}" +if [[ ! -d repositories ]] +then + mkdir repositories +fi +cd repositories || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/repositories/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; } + +for repo in stable-diffusion taming-transformers CodeFormer BLIP +do + printf "\n%s\n" "${delimiter}" + printf "%s" "${repo}" + printf "\n%s\n" "${delimiter}" + + if [[ -d "${repo}" ]] + then + cd "${repo}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/stable-diffusion/repositories/%s, aborting...\e[0m" "${install_dir}" "${repo}"; exit 1; } + "${git_cmd}" pull + cd .. + else + if [[ "${repo}" == "stable-diffusion" || "${repo}" == "taming-transformers" ]] + then + "${git_cmd}" clone https://github.com/CompVis/"${repo}".git + elif [[ "${repo}" == "CodeFormer" ]] + then + "${git_cmd}" clone https://github.com/sczhou/"${repo}".git + elif [[ "${repo}" == "BLIP" ]] + then + "${git_cmd}" clone https://github.com/salesforce/"${repo}".git + fi + fi +done + +printf "\n%s\n" "${delimiter}" +printf "Create and activate python venv" +printf "\n%s\n" "${delimiter}" +cd "${install_dir}"/"${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; } +if [[ ! -d "${venv_dir}" ]] +then + "${python_cmd}" -m venv "${venv_dir}" + first_launch=1 +fi +# shellcheck source=/dev/null +if source "${venv_dir}"/bin/activate +then + printf "\n%s\n" "${delimiter}" + printf "Install dependencies" + printf "\n%s\n" "${delimiter}" + "${pip_cmd[@]}" install "${torch_command[@]}" + "${pip_cmd[@]}" install wheel transformers==4.19.2 diffusers invisible-watermark --prefer-binary + "${pip_cmd[@]}" install git+https://github.com/crowsonkb/k-diffusion.git@1a0703dfb7d24d8806267c3e7ccc4caf67fd1331 --prefer-binary --only-binary=psutil + "${pip_cmd[@]}" install git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 --prefer-binary + "${pip_cmd[@]}" install -r "${reqs_file}" --prefer-binary + "${pip_cmd[@]}" install -r repositories/CodeFormer/requirements.txt --prefer-binary +else + printf "\n%s\n" "${delimiter}" + printf "\e[1m\e[31mERROR: Cannot activate python venv, aborting...\e[0m" + printf "\n%s\n" "${delimiter}" + exit 1 +fi + +printf "\n%s\n" "${delimiter}" +printf "Check if models are present" +printf "\n%s\n" "${delimiter}" +for model in GFPGANv1.3.pth model.ckpt +do + if [[ ! -f "${model}" ]] + then + printf "\n%s\n" "${delimiter}" + printf "\e[1m\e[33mWarning:\e[0m %s file not found..." "${model}" + printf "\n%s\n" "${delimiter}" + if [[ "${model}" == "model.ckpt" ]] && [[ -n "${first_launch}" ]] + then + printf "\n%s\n" "${delimiter}" + printf "Place \e[1m\e[32m%s\e[0m into webui directory, next to \e[1m\e[32mwebui.py\e[0m\n" "${model}" + printf "Then press a key to continue...\n" + read -rsn 1 + printf "\n%s\n" "${delimiter}" + fi + fi +done + +printf "\n%s\n" "${delimiter}" +printf "Launching webui.py..." +printf "\n%s\n" "${delimiter}" +"${python_cmd}" webui.py "${commandline_args[@]}" From cf150757b5341a872dc008463e4e8d1e1757e49c Mon Sep 17 00:00:00 2001 From: orionaskatu <100234619+orionaskatu@users.noreply.github.com> Date: Tue, 13 Sep 2022 15:28:37 +0200 Subject: [PATCH 2/5] webui-user.sh gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3dd434df..1dffb108 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ __pycache__ /styles.csv /styles.csv.bak /webui-user.bat +/webui-user.sh /interrogate From 7bf76af40a59cfc63aa91f573ce1c8335a415a2b Mon Sep 17 00:00:00 2001 From: orionaskatu <100234619+orionaskatu@users.noreply.github.com> Date: Tue, 13 Sep 2022 17:28:54 +0200 Subject: [PATCH 3/5] rewrite for launch.py - untested --- webui-user.sh | 25 ++++++++++------ webui.sh | 82 +++++---------------------------------------------- 2 files changed, 24 insertions(+), 83 deletions(-) diff --git a/webui-user.sh b/webui-user.sh index d4b8727a..36166df9 100644 --- a/webui-user.sh +++ b/webui-user.sh @@ -9,25 +9,32 @@ install_dir="/home/$(whoami)" # Name of the subdirectory (defaults to stable-diffusion-webui) clone_dir="stable-diffusion-webui" -# Commandline arguments for webui.py, for example: commandline_args=(--medvram --opt-split-attention) -commandline_args=() +# Commandline arguments for webui.py, for example: export COMMANDLINE_ARGS=(--medvram --opt-split-attention) +export COMMANDLINE_ARGS=() # python3 executable python_cmd="python3" -# pip3 executable -pip_cmd=(python3 -m pip) - # git executable -git_cmd="git" +export GIT="" # python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv) venv_dir="venv" -# pip3 install command for torch -torch_command=(torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113) +# install command for torch +export TORCH_COMMAND=(python3 -m pip install torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113) # Requirements file to use for stable-diffusion-webui -reqs_file="requirements_versions.txt" +export REQS_FILE="" + +# Fixed git repos +export K_DIFFUSION_PACKAGE="" +export GFPGAN_PACKAGE="" + +# Fixed git commits +export STABLE_DIFFUSION_COMMIT_HASH="" +export TAMING_TRANSFORMERS_COMMIT_HASH="" +export CODEFORMER_COMMIT_HASH="" +export BLIP_COMMIT_HASH="" ########################################### \ No newline at end of file diff --git a/webui.sh b/webui.sh index 3b482a3e..2773b517 100644 --- a/webui.sh +++ b/webui.sh @@ -23,28 +23,16 @@ then clone_dir="stable-diffusion-webui" fi -# Commandline arguments for webui.py, for example: commandline_args=(--medvram --opt-split-attention) -if [[ -z "${commandline_args}" ]] -then - commandline_args=() -fi - # python3 executable if [[ -z "${python_cmd}" ]] then python_cmd="python3" fi -# pip3 executable -if [[ -z "${pip_cmd}" ]] -then - pip_cmd=(python3 -m pip) -fi - # git executable -if [[ -z "${git_cmd}" ]] +if [[ -z "${GIT}" ]] then - git_cmd="git" + export GIT="git" fi # python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv) @@ -53,18 +41,6 @@ then venv_dir="venv" fi -# pip3 install command for torch -if [[ -z "${torch_command}" ]] -then - torch_command=(torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113) -fi - -# Requirements file to use for stable-diffusion-webui -if [[ -z "${reqs_file}" ]] -then - reqs_file="requirements_versions.txt" -fi - # Do not reinstall existing pip packages on Debian/Ubuntu export PIP_IGNORE_INSTALLED=0 @@ -125,46 +101,12 @@ cd "${install_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/, aborting... if [[ -d "${clone_dir}" ]] then cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; } - "${git_cmd}" pull + "${GIT}" pull else - "${git_cmd}" clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git "${clone_dir}" + "${GIT}" clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git "${clone_dir}" cd "${clone_dir}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; } fi -printf "\n%s\n" "${delimiter}" -printf "Clone or update other repositories" -printf "\n%s\n" "${delimiter}" -if [[ ! -d repositories ]] -then - mkdir repositories -fi -cd repositories || { printf "\e[1m\e[31mERROR: Can't cd to %s/%s/repositories/, aborting...\e[0m" "${install_dir}" "${clone_dir}"; exit 1; } - -for repo in stable-diffusion taming-transformers CodeFormer BLIP -do - printf "\n%s\n" "${delimiter}" - printf "%s" "${repo}" - printf "\n%s\n" "${delimiter}" - - if [[ -d "${repo}" ]] - then - cd "${repo}"/ || { printf "\e[1m\e[31mERROR: Can't cd to %s/stable-diffusion/repositories/%s, aborting...\e[0m" "${install_dir}" "${repo}"; exit 1; } - "${git_cmd}" pull - cd .. - else - if [[ "${repo}" == "stable-diffusion" || "${repo}" == "taming-transformers" ]] - then - "${git_cmd}" clone https://github.com/CompVis/"${repo}".git - elif [[ "${repo}" == "CodeFormer" ]] - then - "${git_cmd}" clone https://github.com/sczhou/"${repo}".git - elif [[ "${repo}" == "BLIP" ]] - then - "${git_cmd}" clone https://github.com/salesforce/"${repo}".git - fi - fi -done - printf "\n%s\n" "${delimiter}" printf "Create and activate python venv" printf "\n%s\n" "${delimiter}" @@ -175,17 +117,9 @@ then first_launch=1 fi # shellcheck source=/dev/null -if source "${venv_dir}"/bin/activate +if [[ -f "${venv_dir}"/bin/activate ]] then - printf "\n%s\n" "${delimiter}" - printf "Install dependencies" - printf "\n%s\n" "${delimiter}" - "${pip_cmd[@]}" install "${torch_command[@]}" - "${pip_cmd[@]}" install wheel transformers==4.19.2 diffusers invisible-watermark --prefer-binary - "${pip_cmd[@]}" install git+https://github.com/crowsonkb/k-diffusion.git@1a0703dfb7d24d8806267c3e7ccc4caf67fd1331 --prefer-binary --only-binary=psutil - "${pip_cmd[@]}" install git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379 --prefer-binary - "${pip_cmd[@]}" install -r "${reqs_file}" --prefer-binary - "${pip_cmd[@]}" install -r repositories/CodeFormer/requirements.txt --prefer-binary + source "${venv_dir}"/bin/activate else printf "\n%s\n" "${delimiter}" printf "\e[1m\e[31mERROR: Cannot activate python venv, aborting...\e[0m" @@ -215,6 +149,6 @@ do done printf "\n%s\n" "${delimiter}" -printf "Launching webui.py..." +printf "Launching launch.py..." printf "\n%s\n" "${delimiter}" -"${python_cmd}" webui.py "${commandline_args[@]}" +"${python_cmd}" launch.py From d62fbcc5aa9381ea416f5997f291190c1e74bf29 Mon Sep 17 00:00:00 2001 From: orionaskatu <100234619+orionaskatu@users.noreply.github.com> Date: Tue, 13 Sep 2022 17:48:10 +0200 Subject: [PATCH 4/5] fix on torch_command + tested on debian --- webui.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/webui.sh b/webui.sh index 2773b517..cc4b81f7 100644 --- a/webui.sh +++ b/webui.sh @@ -41,6 +41,12 @@ then venv_dir="venv" fi +# install command for torch +if [[ -z "${TORCH_COMMAND}" ]] +then + export TORCH_COMMAND=(python3 -m pip install torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113) +fi + # Do not reinstall existing pip packages on Debian/Ubuntu export PIP_IGNORE_INSTALLED=0 From a0e819de90da4f93e7e1d8216dd9373a90851fd8 Mon Sep 17 00:00:00 2001 From: orionaskatu <100234619+orionaskatu@users.noreply.github.com> Date: Wed, 14 Sep 2022 09:31:39 +0200 Subject: [PATCH 5/5] remove model files check --- webui.sh | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/webui.sh b/webui.sh index cc4b81f7..0f9fdbef 100644 --- a/webui.sh +++ b/webui.sh @@ -133,27 +133,6 @@ else exit 1 fi -printf "\n%s\n" "${delimiter}" -printf "Check if models are present" -printf "\n%s\n" "${delimiter}" -for model in GFPGANv1.3.pth model.ckpt -do - if [[ ! -f "${model}" ]] - then - printf "\n%s\n" "${delimiter}" - printf "\e[1m\e[33mWarning:\e[0m %s file not found..." "${model}" - printf "\n%s\n" "${delimiter}" - if [[ "${model}" == "model.ckpt" ]] && [[ -n "${first_launch}" ]] - then - printf "\n%s\n" "${delimiter}" - printf "Place \e[1m\e[32m%s\e[0m into webui directory, next to \e[1m\e[32mwebui.py\e[0m\n" "${model}" - printf "Then press a key to continue...\n" - read -rsn 1 - printf "\n%s\n" "${delimiter}" - fi - fi -done - printf "\n%s\n" "${delimiter}" printf "Launching launch.py..." printf "\n%s\n" "${delimiter}"