webui.bat 5.5 KB
Newer Older
1 2 3 4 5
@echo off

set PYTHON=python
set GIT=git
set COMMANDLINE_ARGS=
A
AUTOMATIC 已提交
6
set VENV_DIR=venv
7 8 9

mkdir tmp 2>NUL

10
set TORCH_COMMAND=pip install torch==1.12.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113
A
AUTOMATIC 已提交
11
set REQS_FILE=requirements_versions.txt
12 13 14 15 16 17 18 19

%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
A
AUTOMATIC 已提交
20
if %ERRORLEVEL% == 0 goto :setup_venv
21 22 23
echo Couldn't launch git
goto :show_stdout_stderr

A
AUTOMATIC 已提交
24 25 26 27 28 29
:setup_venv
if [%VENV_DIR%] == [] goto :skip_venv

dir %VENV_DIR%\Scripts\Python.exe >tmp/stdout.txt 2>tmp/stderr.txt
if %ERRORLEVEL% == 0 goto :activate_venv

30
for /f "delims=" %%i in ('CALL %PYTHON% -c "import sys; print(sys.executable)"') do set PYTHON_FULLNAME="%%i"
A
AUTOMATIC 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
echo Creating venv in directory %VENV_DIR% using python %PYTHON_FULLNAME%
%PYTHON_FULLNAME% -m venv %VENV_DIR% >tmp/stdout.txt 2>tmp/stderr.txt
if %ERRORLEVEL% == 0 goto :activate_venv
echo Unable to create venv in directory %VENV_DIR%
goto :show_stdout_stderr

:activate_venv
set PYTHON=%~dp0%VENV_DIR%\Scripts\Python.exe
%PYTHON% --version
echo venv %PYTHON%
goto :install_torch

:skip_venv
%PYTHON% --version

46
:install_torch
A
AUTOMATIC 已提交
47

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
%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
64
%PYTHON% -c "import transformers; import wheel" >tmp/stdout.txt 2>tmp/stderr.txt
65 66
if %ERRORLEVEL% == 0 goto :install_k_diff
echo Installing SD requirements...
67
%PYTHON% -m pip install wheel transformers==4.19.2 diffusers invisible-watermark --prefer-binary >tmp/stdout.txt 2>tmp/stderr.txt
68 69 70 71 72 73 74
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...
75
%PYTHON% -m pip install git+https://github.com/crowsonkb/k-diffusion.git --prefer-binary --only-binary=psutil >tmp/stdout.txt 2>tmp/stderr.txt
76 77 78 79 80 81 82 83
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
84
%PYTHON% -m pip install git+https://github.com/TencentARC/GFPGAN.git --prefer-binary >tmp/stdout.txt 2>tmp/stderr.txt
85 86 87 88 89 90 91
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...
92
%PYTHON% -m pip install -r %REQS_FILE% --prefer-binary >tmp/stdout.txt 2>tmp/stderr.txt
93 94
if %ERRORLEVEL% == 0 goto :update_numpy
goto :show_stdout_stderr
A
AUTOMATIC 已提交
95

96
:update_numpy
97
%PYTHON% -m pip install -U numpy --prefer-binary >tmp/stdout.txt 2>tmp/stderr.txt
98 99 100 101 102 103 104 105 106 107 108

: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
A
AUTOMATIC 已提交
109
if exist repositories\taming-transformers goto :clone_codeformer
110 111
echo Cloning Taming Transforming repository...
%GIT% clone https://github.com/CompVis/taming-transformers.git repositories\taming-transformers >tmp/stdout.txt 2>tmp/stderr.txt
A
AUTOMATIC 已提交
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
if %ERRORLEVEL% == 0 goto :clone_codeformer
goto :show_stdout_stderr

:clone_codeformer
if exist repositories\CodeFormer goto :install_codeformer_reqs
echo Cloning CodeFormer repository...
%GIT% clone https://github.com/sczhou/CodeFormer.git repositories\CodeFormer >tmp/stdout.txt 2>tmp/stderr.txt
if %ERRORLEVEL% == 0 goto :install_codeformer_reqs
goto :show_stdout_stderr

:install_codeformer_reqs
%PYTHON% -c "import lpips" >tmp/stdout.txt 2>tmp/stderr.txt
if %ERRORLEVEL% == 0 goto :check_model
echo Installing requirements for CodeFormer...
%PYTHON% -m pip install -r repositories\CodeFormer\requirements.txt --prefer-binary >tmp/stdout.txt 2>tmp/stderr.txt
127 128 129
if %ERRORLEVEL% == 0 goto :check_model
goto :show_stdout_stderr

A
AUTOMATIC 已提交
130

131 132 133
:check_model
dir model.ckpt >tmp/stdout.txt 2>tmp/stderr.txt
if %ERRORLEVEL% == 0 goto :check_gfpgan
A
AUTOMATIC 已提交
134
echo Stable Diffusion model not found: you need to place model.ckpt file into same directory as this file.
135 136 137 138 139 140 141 142 143 144
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...
145
%PYTHON% webui.py %COMMANDLINE_ARGS%
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
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.
A
AUTOMATIC 已提交
171
pause