From efa0a6483c9dfbdde6717bec202942c6036e72ff Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Fri, 2 Sep 2022 19:26:18 +0300 Subject: [PATCH] change webui.bat to use venv --- README.md | 7 +++++-- requirements_versions.txt | 10 ++++++++++ webui.bat | 34 ++++++++++++++++++++++++++++++---- webui.py | 2 +- 4 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 requirements_versions.txt diff --git a/README.md b/README.md index f2973a808..2c4d3c5b8 100644 --- a/README.md +++ b/README.md @@ -27,12 +27,15 @@ You optionally can use GPFGAN to improve faces, then you'll need to download the - install [CUDA 11.3](https://developer.nvidia.com/cuda-11.3.0-download-archive?target_os=Windows&target_arch=x86_64) - 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. +- run `webui.bat` from Windows Explorer. #### Troublehooting: - if you get out of memory errors and your videocard has low amount of VRAM (4GB), edit `webui.bat`, change line 5 to from `set COMMANDLINE_ARGS=` to `set COMMANDLINE_ARGS=--medvram` (see below for other possible options) - +- installer creates python virtual environment, so none of installed modules will affect your system installation of python if you had one prior to installing this. +- to prevent the creation of virtual environment and use your system python, edit `webui.bat` replacing `set VENV_DIR=venv` with `set VENV_DIR=`. +- webui.bat installs requirements from files `requirements_versions.txt`, which lists versions for modules specifically compatible with Python 3.10.6. If you choose to install for a different version of python, editing `webui.bat` to have `set REQS_FILE=requirements.txt` instead of `set REQS_FILE=requirements_versions.txt` may help (but I still reccomend you to just use the recommended version of python). +- if your version of Python is not in PATH, edit the line `set PYTHON=python` to say the full path to your python executable: `B:\soft\Python310\python.exe`. You can do this for python, but not for git. ### Manual instructions Alternatively, if you don't want to run webui.bat, here are instructions for installing diff --git a/requirements_versions.txt b/requirements_versions.txt new file mode 100644 index 000000000..d2277b81f --- /dev/null +++ b/requirements_versions.txt @@ -0,0 +1,10 @@ +basicsr==1.4.1 +gfpgan +gradio==3.2 +numpy==1.22.0 +Pillow==9.2.0 +realesrgan==0.2.5.0 +torch +transformers==4.19.2 +omegaconf==2.1.1 +pytorch_lightning==1.7.2 diff --git a/webui.bat b/webui.bat index f633d0db8..681aa983c 100644 --- a/webui.bat +++ b/webui.bat @@ -3,10 +3,12 @@ set PYTHON=python set GIT=git set COMMANDLINE_ARGS= +set VENV_DIR=venv mkdir tmp 2>NUL set TORCH_COMMAND=pip install torch --extra-index-url https://download.pytorch.org/whl/cu113 +set REQS_FILE=requirements_versions.txt %PYTHON% -c "" >tmp/stdout.txt 2>tmp/stderr.txt if %ERRORLEVEL% == 0 goto :check_git @@ -15,11 +17,34 @@ goto :show_stdout_stderr :check_git %GIT% --help >tmp/stdout.txt 2>tmp/stderr.txt -if %ERRORLEVEL% == 0 goto :install_torch +if %ERRORLEVEL% == 0 goto :setup_venv echo Couldn't launch git goto :show_stdout_stderr +: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 + +for /f %%i in ('%PYTHON% -c "import sys; print(sys.executable)"') do set PYTHON_FULLNAME=%%i +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 + :install_torch + %PYTHON% -c "import torch" >tmp/stdout.txt 2>tmp/stderr.txt if %ERRORLEVEL% == 0 goto :check_gpu echo Installing torch... @@ -64,7 +89,7 @@ goto :show_stdout_stderr %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 +%PYTHON% -m pip install -r %REQS_FILE% >tmp/stdout.txt 2>tmp/stderr.txt if %ERRORLEVEL% == 0 goto :update_numpy goto :show_stdout_stderr :update_numpy @@ -89,7 +114,7 @@ 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. +echo Stable Diffusion model not found: you need to place model.ckpt file into same directory as this file. goto :show_stdout_stderr :check_gfpgan @@ -101,7 +126,7 @@ echo Face fixing feature will not work. :launch echo Launching webui.py... cd repositories\stable-diffusion -%PYTHON% ..\..\webui.py %COMMANDLINE_ARGS% +%PYTHON% ../../webui.py %COMMANDLINE_ARGS% pause exit /b @@ -127,3 +152,4 @@ type tmp\stderr.txt echo. echo Launch unsuccessful. Exiting. +pause diff --git a/webui.py b/webui.py index e59172df3..c51a78293 100644 --- a/webui.py +++ b/webui.py @@ -633,9 +633,9 @@ def draw_xy_grid(xs, ys, x_label, y_label, cell): for y in ys: for x in xs: + state.job = f"{x + y * len(xs)} out of {len(xs) * len(ys)}" res.append(cell(x, y)) - grid = image_grid(res, rows=len(ys)) grid = draw_grid_annotations(grid, res[0].width, res[0].height, hor_texts, ver_texts)