2022-09-09 17:32:33 +02:00
#!/bin/bash
2022-11-05 18:59:59 +01:00
source ./scripts/functions.sh
2022-09-09 10:36:37 +02:00
cp sd-ui-files/scripts/on_env_start.sh scripts/
2022-10-22 19:54:13 +02:00
cp sd-ui-files/scripts/bootstrap.sh scripts/
2022-09-07 16:31:39 +02:00
2022-10-26 08:45:58 +02:00
# activate the installer env
CONDA_BASEPATH = $( conda info --base)
source " $CONDA_BASEPATH /etc/profile.d/conda.sh " # avoids the 'shell not initialized' error
2022-11-05 18:59:59 +01:00
conda activate || fail "Failed to activate conda"
2022-10-26 08:45:58 +02:00
2022-10-22 19:54:13 +02:00
# remove the old version of the dev console script, if it's still present
2022-10-07 16:22:31 +02:00
if [ -e "open_dev_console.sh" ] ; then
rm "open_dev_console.sh"
fi
2022-10-07 15:20:07 +02:00
2022-11-05 18:59:59 +01:00
python -c "import os; import shutil; frm = 'sd-ui-files/ui/hotfix/9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142'; dst = os.path.join(os.path.expanduser('~'), '.cache', 'huggingface', 'transformers', '9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142'); shutil.copyfile(frm, dst) if os.path.exists(dst) else print(''); print('Hotfixed broken JSON file from OpenAI');"
2022-09-09 21:07:04 +02:00
2022-09-09 17:35:24 +02:00
# Caution, this file will make your eyes and brain bleed. It's such an unholy mess.
# Note to self: Please rewrite this in Python. For the sake of your own sanity.
2022-11-25 07:47:44 +01:00
if [ " $test_sd2 " = = "" ] ; then
export test_sd2 = "N"
fi
2022-09-07 16:31:39 +02:00
if [ -e "scripts/install_status.txt" ] && [ ` grep -c sd_git_cloned scripts/install_status.txt` -gt "0" ] ; then
2022-09-02 18:24:32 +02:00
echo "Stable Diffusion's git repository was already installed. Updating.."
cd stable-diffusion
2022-11-22 12:08:39 +01:00
git remote set-url origin https://github.com/easydiffusion/diffusion-kit.git
2022-09-02 18:24:32 +02:00
git reset --hard
git pull
2022-11-25 07:47:44 +01:00
if [ " $test_sd2 " = = "N" ] ; then
git -c advice.detachedHead= false checkout 7f32368ed1030a6e710537047bacd908adea183a
elif [ " $test_sd2 " = = "Y" ] ; then
2022-12-08 05:34:33 +01:00
git -c advice.detachedHead= false checkout 733a1f6f9cae9b9a9b83294bf3281b123378cb1f
2022-11-25 07:47:44 +01:00
fi
2022-09-13 16:29:41 +02:00
2022-09-02 18:24:32 +02:00
cd ..
else
2022-09-03 14:43:21 +02:00
printf "\n\nDownloading Stable Diffusion..\n\n"
2022-09-02 18:24:32 +02:00
2022-11-22 12:08:39 +01:00
if git clone https://github.com/easydiffusion/diffusion-kit.git stable-diffusion ; then
2022-09-02 18:24:32 +02:00
echo sd_git_cloned >> scripts/install_status.txt
else
2022-11-05 18:59:59 +01:00
fail "git clone of basujindal/stable-diffusion.git failed"
2022-09-02 18:24:32 +02:00
fi
2022-09-08 19:53:02 +02:00
cd stable-diffusion
2022-11-22 13:09:51 +01:00
git -c advice.detachedHead= false checkout 7f32368ed1030a6e710537047bacd908adea183a
2022-09-13 16:29:41 +02:00
2022-09-08 19:53:02 +02:00
cd ..
2022-09-02 18:24:32 +02:00
fi
cd stable-diffusion
if [ ` grep -c conda_sd_env_created ../scripts/install_status.txt` -gt "0" ] ; then
echo "Packages necessary for Stable Diffusion were already installed"
2022-09-06 15:31:21 +02:00
2022-11-05 18:59:59 +01:00
conda activate ./env || fail "conda activate failed"
2022-09-02 18:24:32 +02:00
else
2022-09-03 14:43:21 +02:00
printf "\n\nDownloading packages necessary for Stable Diffusion..\n"
printf "\n\n***** This will take some time (depending on the speed of the Internet connection) and may appear to be stuck, but please be patient ***** ..\n\n"
2022-09-02 18:24:32 +02:00
2022-09-12 13:09:23 +02:00
# prevent conda from using packages from the user's home directory, to avoid conflicts
export PYTHONNOUSERSITE = 1
2022-11-02 15:15:49 +01:00
export PYTHONPATH = " $( pwd ) : $( pwd ) /env/lib/site-packages "
2022-09-12 13:09:23 +02:00
2022-09-03 14:25:38 +02:00
if conda env create --prefix env --force -f environment.yaml ; then
2022-09-06 15:31:21 +02:00
echo "Installed. Testing.."
2022-09-02 18:24:32 +02:00
else
2022-11-05 18:59:59 +01:00
fail "'conda env create' failed"
2022-09-02 18:24:32 +02:00
fi
2022-11-05 18:59:59 +01:00
conda activate ./env || fail "conda activate failed"
2022-09-06 15:31:21 +02:00
2022-10-25 13:08:08 +02:00
out_test = ` python -c "import torch; import ldm; import transformers; import numpy; import antlr4; print(42)" `
if [ " $out_test " != "42" ] ; then
2022-11-05 18:59:59 +01:00
fail "Dependency test failed"
2022-10-25 13:08:08 +02:00
fi
2022-09-06 15:31:21 +02:00
echo conda_sd_env_created >> ../scripts/install_status.txt
fi
2022-09-02 18:24:32 +02:00
2022-09-09 17:35:24 +02:00
if [ ` grep -c conda_sd_gfpgan_deps_installed ../scripts/install_status.txt` -gt "0" ] ; then
echo "Packages necessary for GFPGAN (Face Correction) were already installed"
else
printf "\n\nDownloading packages necessary for GFPGAN (Face Correction)..\n"
2022-09-12 13:09:23 +02:00
export PYTHONNOUSERSITE = 1
2022-11-02 15:15:49 +01:00
export PYTHONPATH = " $( pwd ) : $( pwd ) /env/lib/site-packages "
2022-09-12 13:09:23 +02:00
2022-09-09 17:35:24 +02:00
out_test = ` python -c "from gfpgan import GFPGANer; print(42)" `
if [ " $out_test " != "42" ] ; then
2022-11-05 18:59:59 +01:00
echo "EE The dependency check has failed. This usually means that some system libraries are missing."
echo "EE On Debian/Ubuntu systems, this are often these packages: libsm6 libxext6 libxrender-dev"
echo "EE Other Linux distributions might have different package names for these libraries."
fail "GFPGAN dependency test failed"
2022-09-09 17:35:24 +02:00
fi
echo conda_sd_gfpgan_deps_installed >> ../scripts/install_status.txt
fi
if [ ` grep -c conda_sd_esrgan_deps_installed ../scripts/install_status.txt` -gt "0" ] ; then
echo "Packages necessary for ESRGAN (Resolution Upscaling) were already installed"
else
printf "\n\nDownloading packages necessary for ESRGAN (Resolution Upscaling)..\n"
2022-09-12 13:09:23 +02:00
export PYTHONNOUSERSITE = 1
2022-11-02 15:15:49 +01:00
export PYTHONPATH = " $( pwd ) : $( pwd ) /env/lib/site-packages "
2022-09-12 13:09:23 +02:00
2022-09-09 17:35:24 +02:00
out_test = ` python -c "from basicsr.archs.rrdbnet_arch import RRDBNet; from realesrgan import RealESRGANer; print(42)" `
if [ " $out_test " != "42" ] ; then
2022-11-05 18:59:59 +01:00
fail "ESRGAN dependency test failed"
2022-09-09 17:35:24 +02:00
fi
echo conda_sd_esrgan_deps_installed >> ../scripts/install_status.txt
fi
2022-09-02 18:24:32 +02:00
if [ ` grep -c conda_sd_ui_deps_installed ../scripts/install_status.txt` -gt "0" ] ; then
echo "Packages necessary for Stable Diffusion UI were already installed"
else
2022-09-03 14:43:21 +02:00
printf "\n\nDownloading packages necessary for Stable Diffusion UI..\n\n"
2022-09-02 18:24:32 +02:00
2022-09-12 13:09:23 +02:00
export PYTHONNOUSERSITE = 1
2022-11-02 15:15:49 +01:00
export PYTHONPATH = " $( pwd ) : $( pwd ) /env/lib/site-packages "
2022-09-12 13:09:23 +02:00
2022-09-03 14:25:38 +02:00
if conda install -c conda-forge --prefix ./env -y uvicorn fastapi ; then
2022-09-06 15:31:21 +02:00
echo "Installed. Testing.."
2022-09-02 18:24:32 +02:00
else
2022-11-05 18:59:59 +01:00
fail "'conda install uvicorn' failed"
2022-09-02 18:24:32 +02:00
fi
2022-09-06 15:31:21 +02:00
if ! command -v uvicorn & > /dev/null; then
2022-11-05 18:59:59 +01:00
fail "UI packages not found!"
2022-09-06 15:31:21 +02:00
fi
echo conda_sd_ui_deps_installed >> ../scripts/install_status.txt
2022-09-02 18:24:32 +02:00
fi
2022-11-16 22:34:02 +01:00
if python -m picklescan --help >/dev/null 2>& 1; then
echo "Picklescan is already installed."
else
echo "Picklescan not found, installing."
pip install picklescan || fail "Picklescan installation failed."
fi
2022-12-05 06:29:48 +01:00
if python -c "import safetensors" --help >/dev/null 2>& 1; then
echo "SafeTensors is already installed."
else
echo "SafeTensors not found, installing."
pip install safetensors || fail "SafeTensors installation failed."
fi
2022-09-09 17:35:24 +02:00
2022-11-08 12:24:15 +01:00
mkdir -p "../models/vae"
2022-10-06 10:58:02 +02:00
2022-09-02 18:24:32 +02:00
if [ -f "sd-v1-4.ckpt" ] ; then
2022-09-30 07:14:47 +02:00
model_size = ` find "sd-v1-4.ckpt" -printf "%s" `
2022-09-06 15:31:21 +02:00
2022-09-12 18:14:16 +02:00
if [ " $model_size " -eq "4265380512" ] || [ " $model_size " -eq "7703807346" ] || [ " $model_size " -eq "7703810927" ] ; then
2022-09-06 15:31:21 +02:00
echo "Data files (weights) necessary for Stable Diffusion were already downloaded"
else
printf " \n\nThe model file present at $PWD /sd-v1-4.ckpt is invalid. It is only $model_size bytes in size. Re-downloading.. "
rm sd-v1-4.ckpt
fi
fi
if [ ! -f "sd-v1-4.ckpt" ] ; then
2022-09-02 18:24:32 +02:00
echo "Downloading data files (weights) for Stable Diffusion.."
2022-10-26 21:19:32 +02:00
curl -L -k https://me.cmdr2.org/stable-diffusion-ui/sd-v1-4.ckpt > sd-v1-4.ckpt
2022-09-02 18:24:32 +02:00
2022-09-06 15:31:21 +02:00
if [ -f "sd-v1-4.ckpt" ] ; then
2022-09-30 07:14:47 +02:00
model_size = ` find "sd-v1-4.ckpt" -printf "%s" `
2022-09-12 18:14:16 +02:00
if [ ! " $model_size " = = "4265380512" ] ; then
2022-11-05 18:59:59 +01:00
fail " The downloaded model file was invalid! Bytes downloaded: $model_size "
2022-09-06 15:31:21 +02:00
fi
else
2022-11-05 18:59:59 +01:00
fail "Error downloading the data files (weights) for Stable Diffusion"
2022-09-02 18:24:32 +02:00
fi
2022-09-09 17:35:24 +02:00
fi
if [ -f "GFPGANv1.3.pth" ] ; then
2022-09-30 07:14:47 +02:00
model_size = ` find "GFPGANv1.3.pth" -printf "%s" `
2022-09-09 17:35:24 +02:00
if [ " $model_size " -eq "348632874" ] ; then
echo "Data files (weights) necessary for GFPGAN (Face Correction) were already downloaded"
else
printf " \n\nThe model file present at $PWD /GFPGANv1.3.pth is invalid. It is only $model_size bytes in size. Re-downloading.. "
rm GFPGANv1.3.pth
fi
fi
if [ ! -f "GFPGANv1.3.pth" ] ; then
echo "Downloading data files (weights) for GFPGAN (Face Correction).."
2022-10-26 21:19:32 +02:00
curl -L -k https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth > GFPGANv1.3.pth
2022-09-09 17:35:24 +02:00
if [ -f "GFPGANv1.3.pth" ] ; then
2022-09-30 07:14:47 +02:00
model_size = ` find "GFPGANv1.3.pth" -printf "%s" `
2022-09-09 17:35:24 +02:00
if [ ! " $model_size " -eq "348632874" ] ; then
2022-11-05 18:59:59 +01:00
fail " The downloaded GFPGAN model file was invalid! Bytes downloaded: $model_size "
2022-09-09 17:35:24 +02:00
fi
else
2022-11-05 18:59:59 +01:00
fail "Error downloading the data files (weights) for GFPGAN (Face Correction)."
2022-09-09 17:35:24 +02:00
fi
fi
if [ -f "RealESRGAN_x4plus.pth" ] ; then
2022-09-30 07:14:47 +02:00
model_size = ` find "RealESRGAN_x4plus.pth" -printf "%s" `
2022-09-09 17:35:24 +02:00
if [ " $model_size " -eq "67040989" ] ; then
echo "Data files (weights) necessary for ESRGAN (Resolution Upscaling) x4plus were already downloaded"
else
printf " \n\nThe model file present at $PWD /RealESRGAN_x4plus.pth is invalid. It is only $model_size bytes in size. Re-downloading.. "
rm RealESRGAN_x4plus.pth
fi
fi
if [ ! -f "RealESRGAN_x4plus.pth" ] ; then
echo "Downloading data files (weights) for ESRGAN (Resolution Upscaling) x4plus.."
2022-10-26 21:19:32 +02:00
curl -L -k https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth > RealESRGAN_x4plus.pth
2022-09-09 17:35:24 +02:00
if [ -f "RealESRGAN_x4plus.pth" ] ; then
2022-09-30 07:14:47 +02:00
model_size = ` find "RealESRGAN_x4plus.pth" -printf "%s" `
2022-09-09 17:35:24 +02:00
if [ ! " $model_size " -eq "67040989" ] ; then
2022-11-05 18:59:59 +01:00
fail " The downloaded ESRGAN x4plus model file was invalid! Bytes downloaded: $model_size "
2022-09-09 17:35:24 +02:00
fi
else
2022-11-05 18:59:59 +01:00
fail "Error downloading the data files (weights) for ESRGAN (Resolution Upscaling) x4plus"
2022-09-09 17:35:24 +02:00
fi
fi
if [ -f "RealESRGAN_x4plus_anime_6B.pth" ] ; then
2022-09-30 07:14:47 +02:00
model_size = ` find "RealESRGAN_x4plus_anime_6B.pth" -printf "%s" `
2022-09-09 17:35:24 +02:00
if [ " $model_size " -eq "17938799" ] ; then
echo "Data files (weights) necessary for ESRGAN (Resolution Upscaling) x4plus_anime were already downloaded"
else
printf " \n\nThe model file present at $PWD /RealESRGAN_x4plus_anime_6B.pth is invalid. It is only $model_size bytes in size. Re-downloading.. "
rm RealESRGAN_x4plus_anime_6B.pth
fi
fi
if [ ! -f "RealESRGAN_x4plus_anime_6B.pth" ] ; then
echo "Downloading data files (weights) for ESRGAN (Resolution Upscaling) x4plus_anime.."
2022-10-26 21:19:32 +02:00
curl -L -k https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth > RealESRGAN_x4plus_anime_6B.pth
2022-09-09 17:35:24 +02:00
if [ -f "RealESRGAN_x4plus_anime_6B.pth" ] ; then
2022-09-30 07:14:47 +02:00
model_size = ` find "RealESRGAN_x4plus_anime_6B.pth" -printf "%s" `
2022-09-09 17:35:24 +02:00
if [ ! " $model_size " -eq "17938799" ] ; then
2022-11-05 18:59:59 +01:00
fail " The downloaded ESRGAN x4plus_anime model file was invalid! Bytes downloaded: $model_size "
2022-09-09 17:35:24 +02:00
fi
else
2022-11-05 18:59:59 +01:00
fail "Error downloading the data files (weights) for ESRGAN (Resolution Upscaling) x4plus_anime."
2022-10-28 16:36:44 +02:00
fi
fi
2022-11-08 12:24:15 +01:00
if [ -f "../models/vae/vae-ft-mse-840000-ema-pruned.ckpt" ] ; then
model_size = ` find ../models/vae/vae-ft-mse-840000-ema-pruned.ckpt -printf "%s" `
2022-10-28 16:36:44 +02:00
if [ " $model_size " -eq "334695179" ] ; then
echo "Data files (weights) necessary for the default VAE (sd-vae-ft-mse-original) were already downloaded"
else
2022-11-08 12:24:15 +01:00
printf " \n\nThe model file present at models/vae/vae-ft-mse-840000-ema-pruned.ckpt is invalid. It is only $model_size bytes in size. Re-downloading.. "
rm ../models/vae/vae-ft-mse-840000-ema-pruned.ckpt
2022-10-28 16:36:44 +02:00
fi
fi
2022-11-08 12:24:15 +01:00
if [ ! -f "../models/vae/vae-ft-mse-840000-ema-pruned.ckpt" ] ; then
2022-10-28 16:36:44 +02:00
echo "Downloading data files (weights) for the default VAE (sd-vae-ft-mse-original).."
2022-11-08 12:24:15 +01:00
curl -L -k https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt > ../models/vae/vae-ft-mse-840000-ema-pruned.ckpt
2022-10-28 16:36:44 +02:00
2022-11-08 12:24:15 +01:00
if [ -f "../models/vae/vae-ft-mse-840000-ema-pruned.ckpt" ] ; then
model_size = ` find ../models/vae/vae-ft-mse-840000-ema-pruned.ckpt -printf "%s" `
2022-10-28 16:36:44 +02:00
if [ ! " $model_size " -eq "334695179" ] ; then
printf " \n\nError: The downloaded default VAE (sd-vae-ft-mse-original) file was invalid! Bytes downloaded: $model_size \n\n "
printf "\n\nError downloading the data files (weights) for the default VAE (sd-vae-ft-mse-original). Sorry about that, please try to:\n 1. Run this installer again.\n 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting\n 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB\n 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues\nThanks!\n\n"
read -p "Press any key to continue"
exit
fi
else
printf "\n\nError downloading the data files (weights) for the default VAE (sd-vae-ft-mse-original). Sorry about that, please try to:\n 1. Run this installer again.\n 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting\n 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB\n 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues\nThanks!\n\n"
2022-09-09 17:35:24 +02:00
read -p "Press any key to continue"
exit
fi
fi
2022-11-25 07:47:44 +01:00
if [ " $test_sd2 " = = "Y" ] ; then
pip install open_clip_torch = = 2.0.2
fi
2022-09-02 18:24:32 +02:00
2022-09-09 17:35:24 +02:00
if [ ` grep -c sd_install_complete ../scripts/install_status.txt` -gt "0" ] ; then
2022-09-02 18:24:32 +02:00
echo sd_weights_downloaded >> ../scripts/install_status.txt
echo sd_install_complete >> ../scripts/install_status.txt
fi
2022-09-03 14:43:21 +02:00
printf "\n\nStable Diffusion is ready!\n\n"
2022-09-02 18:24:32 +02:00
2022-09-13 07:06:50 +02:00
SD_PATH = ` pwd `
2022-10-25 09:14:05 +02:00
export PYTHONPATH = " $SD_PATH : $SD_PATH /env/lib/python3.8/site-packages "
2022-09-13 07:06:50 +02:00
echo " PYTHONPATH= $PYTHONPATH "
2022-10-26 12:30:21 +02:00
which python
python --version
2022-09-05 12:00:04 +02:00
cd ..
export SD_UI_PATH = ` pwd ` /ui
cd stable-diffusion
2022-09-02 18:24:32 +02:00
2022-12-12 10:48:30 +01:00
uvicorn server:server_api --app-dir " $SD_UI_PATH " --port ${ SD_UI_BIND_PORT :- 9000 } --host ${ SD_UI_BIND_IP :- 0 .0.0.0 } --log-level error
2022-09-02 18:24:32 +02:00
2022-09-12 13:09:23 +02:00
read -p "Press any key to continue"