From 67216187a8a6d99da77b9e3cc7b4fff15f75d2c3 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Fri, 2 Sep 2022 09:49:35 +0300 Subject: bat file for installing and launching --- README.md | 12 +++++- webui.bat | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ webui.py | 7 +++- 3 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 webui.bat diff --git a/README.md b/README.md index 62d2b167..33eb2540 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ installed to run this, and an NVidia videocard. I tested the installation to work Windows with Python 3.8.10, and with Python 3.10.6. You may be able to have success with different versions. -You need Stable Diffusion model checkpoint, a big file containing the neural network weights. You +You need `model.ckpt`, Stable Diffusion model checkpoint, a big file containing the neural network weights. You can obtain it from the following places: - [official download](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original) - [file storage](https://drive.yerf.org/wl/?id=EBfTrmcCCUAGaQBXVIj5lJmEhjoP1tgl) @@ -20,7 +20,15 @@ can obtain it from the following places: You optionally can use GPFGAN to improve faces, then you'll need to download the model from [here](https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth). -Instructions: +### Automatic installation/launch + +- place `model.ckpt` into webui directory, next to `webui.bat`. +- (optional) place `GFPGANv1.3.pth` into webui directory, next to `webui.bat`. +- run `webui.bat` from Windows explorer. + +### Manual instructions +Alternatively, if you don't want to run webui.bat, here are instructions for installing +everything by hand: ```commandline :: crate a directory somewhere for stable diffusion and open cmd in it; diff --git a/webui.bat b/webui.bat new file mode 100644 index 00000000..f633d0db --- /dev/null +++ b/webui.bat @@ -0,0 +1,129 @@ +@echo off + +set PYTHON=python +set GIT=git +set COMMANDLINE_ARGS= + +mkdir tmp 2>NUL + +set TORCH_COMMAND=pip install torch --extra-index-url https://download.pytorch.org/whl/cu113 + +%PYTHON% -c "" >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :check_git +echo Couldn't launch python +goto :show_stdout_stderr + +:check_git +%GIT% --help >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :install_torch +echo Couldn't launch git +goto :show_stdout_stderr + +:install_torch +%PYTHON% -c "import torch" >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :check_gpu +echo Installing torch... +%PYTHON% -m %TORCH_COMMAND% >tmp/stdout.txt 2>tmp/stderr.txt + +if %ERRORLEVEL% == 0 goto :check_gpu +echo Failed to install torch +goto :show_stdout_stderr + +:check_gpu +%PYTHON% -c "import torch; assert torch.cuda.is_available(), 'CUDA is not available'" >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :install_sd_reqs +echo Torch is not able to use GPU +goto :show_stdout_stderr + +:install_sd_reqs +%PYTHON% -c "import transformers" >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :install_k_diff +echo Installing SD requirements... +%PYTHON% -m pip install transformers==4.19.2 diffusers invisible-watermark >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :install_k_diff +goto :show_stdout_stderr + +:install_k_diff +%PYTHON% -c "import k_diffusion.sampling" >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :install_GFPGAN +echo Installing K-Diffusion... +%PYTHON% -m pip install git+https://github.com/crowsonkb/k-diffusion.git >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :install_GFPGAN +goto :show_stdout_stderr + + +:install_GFPGAN +%PYTHON% -c "import gfpgan" >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :install_reqs +echo Installing GFPGAN +%PYTHON% -m pip install git+https://github.com/TencentARC/GFPGAN.git >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :install_reqs +goto :show_stdout_stderr + +:install_reqs +%PYTHON% -c "import omegaconf" >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :make_dirs +echo Installing requirements... +%PYTHON% -m pip install -r requirements.txt >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :update_numpy +goto :show_stdout_stderr +:update_numpy +%PYTHON% -m pip install -U numpy >tmp/stdout.txt 2>tmp/stderr.txt + +:make_dirs +mkdir repositories 2>NUL + +if exist repositories\stable-diffusion goto :clone_transformers +echo Cloning Stable Difusion repository... +%GIT% clone https://github.com/CompVis/stable-diffusion.git repositories\stable-diffusion >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :clone_transformers +goto :show_stdout_stderr + +:clone_transformers +if exist repositories\taming-transformers goto :check_model +echo Cloning Taming Transforming repository... +%GIT% clone https://github.com/CompVis/taming-transformers.git repositories\taming-transformers >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :check_model +goto :show_stdout_stderr + +:check_model +dir model.ckpt >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :check_gfpgan +echo Stable Diffusin model not found: you need to place model.ckpt file into same directory as this file. +goto :show_stdout_stderr + +:check_gfpgan +dir GFPGANv1.3.pth >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :launch +echo GFPGAN not found: you need to place GFPGANv1.3.pth file into same directory as this file. +echo Face fixing feature will not work. + +:launch +echo Launching webui.py... +cd repositories\stable-diffusion +%PYTHON% ..\..\webui.py %COMMANDLINE_ARGS% +pause +exit /b + +:show_stdout_stderr + +echo. +echo exit code: %errorlevel% + +for /f %%i in ("tmp\stdout.txt") do set size=%%~zi +if %size% equ 0 goto :show_stderr +echo. +echo stdout: +type tmp\stdout.txt + +:show_stderr +for /f %%i in ("tmp\stderr.txt") do set size=%%~zi +if %size% equ 0 goto :show_stderr +echo. +echo stderr: +type tmp\stderr.txt + +:endofscript + +echo. +echo Launch unsuccessful. Exiting. diff --git a/webui.py b/webui.py index 0d335d92..6f935339 100644 --- a/webui.py +++ b/webui.py @@ -10,7 +10,7 @@ sd_path = os.path.abspath('.') if os.path.exists('./ldm/models/diffusion/ddpm.py # add parent directory to path; this is where Stable diffusion repo should be path_dirs = [ (sd_path, 'ldm', 'Stable Diffusion'), - ('../../taming-transformers', 'taming', 'Taming Transformers') + (os.path.join(sd_path,'../taming-transformers'), 'taming', 'Taming Transformers') ] for d, must_exist, what in path_dirs: must_exist_path = os.path.abspath(os.path.join(script_path, d, must_exist)) @@ -57,10 +57,13 @@ opt_f = 8 LANCZOS = (Image.Resampling.LANCZOS if hasattr(Image, 'Resampling') else Image.LANCZOS) invalid_filename_chars = '<>:"/\\|?*\n' config_filename = "config.json" +sd_model_file = os.path.join(script_path, 'model.ckpt') +if not os.path.exists(sd_model_file): + sd_model_file = "models/ldm/stable-diffusion-v1/model.ckpt" parser = argparse.ArgumentParser() parser.add_argument("--config", type=str, default=os.path.join(sd_path, "configs/stable-diffusion/v1-inference.yaml"), help="path to config which constructs model",) -parser.add_argument("--ckpt", type=str, default=os.path.join(sd_path, "models/ldm/stable-diffusion-v1/model.ckpt"), help="path to checkpoint of model",) +parser.add_argument("--ckpt", type=str, default=os.path.join(sd_path, sd_model_file), help="path to checkpoint of model",) parser.add_argument("--gfpgan-dir", type=str, help="GFPGAN directory", default=('./src/gfpgan' if os.path.exists('./src/gfpgan') else './GFPGAN')) parser.add_argument("--gfpgan-model", type=str, help="GFPGAN model file name", default='GFPGANv1.3.pth') parser.add_argument("--no-half", action='store_true', help="do not switch the model to 16-bit floats") -- cgit v1.2.1