2022-09-07 01:50:14 +03:00
@ echo off
2022-10-24 03:31:41 +03:00
: : This file is part of sygil-webui (https://github.com/Sygil-Dev/sygil-webui/).
2022-10-27 06:24:47 +03:00
: :
2022-10-24 03:17:50 +03:00
: : Copyright 2022 Sygil-Dev team.
2022-09-26 16:02:48 +03:00
: : This program is free software: you can redistribute it and/or modify
: : it under the terms of the GNU Affero General Public License as published by
: : the Free Software Foundation, either version 3 of the License, or
: : (at your option) any later version.
2022-10-27 06:24:47 +03:00
: :
2022-09-26 16:02:48 +03:00
: : This program is distributed in the hope that it will be useful,
: : but WITHOUT ANY WARRANTY; without even the implied warranty of
: : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
: : GNU Affero General Public License for more details.
2022-10-27 06:24:47 +03:00
: :
2022-09-26 16:02:48 +03:00
: : You should have received a copy of the GNU Affero General Public License
: : along with this program. If not, see <http://www.gnu.org/licenses/>.
2022-09-12 11:41:47 +03:00
: : Run all commands using this script's directory as the working directory
cd %~dp0
2022-09-13 12:13:23 +03:00
: : copy over the first line from environment.yaml, e.g. name: ldm, and take the second word after splitting by ":" delimiter
for /F " tokens=2 delims=: " %% i in ( environment.yaml) DO (
set v_conda_env_name = %% i
goto EOL
)
: EOL
2022-09-07 01:50:14 +03:00
2022-09-13 12:13:23 +03:00
echo Environment name is set as %v_conda_env_name% as per environment.yaml
2022-09-07 01:50:14 +03:00
2022-09-13 12:13:23 +03:00
: : Put the path to conda directory in a file called "custom-conda-path.txt" if it's installed at non-standard path
IF EXIST custom-conda-path.txt (
FOR /F %% i IN ( custom-conda-path.txt) DO set v_custom_path = %% i
2022-09-07 01:50:14 +03:00
)
2022-10-13 10:47:58 +03:00
set INSTALL_ENV_DIR = %cd% \installer_files\env
2022-10-26 14:08:32 +03:00
set PATH = %INSTALL_ENV_DIR% ;%INSTALL_ENV_DIR% \Library\bin;%INSTALL_ENV_DIR% \Scripts;%INSTALL_ENV_DIR% \Library\usr\bin;%PATH%
2022-10-13 10:47:58 +03:00
set v_paths = %INSTALL_ENV_DIR%
set v_paths = %v_paths% ;%ProgramData% \miniconda3
2022-09-13 12:13:23 +03:00
set v_paths = %v_paths% ;%USERPROFILE% \miniconda3
set v_paths = %v_paths% ;%ProgramData% \anaconda3
set v_paths = %v_paths% ;%USERPROFILE% \anaconda3
2022-09-07 01:50:14 +03:00
2022-09-13 12:13:23 +03:00
for %% a in ( %v_paths% ) do (
2022-09-14 19:43:32 +03:00
IF NOT " %v_custom_path% " == " " (
set v_paths = %v_custom_path% ;%v_paths%
)
2022-09-07 01:50:14 +03:00
)
2022-09-13 12:13:23 +03:00
for %% a in ( %v_paths% ) do (
2022-09-14 19:43:32 +03:00
if EXIST " %% a\Scripts\activate.bat " (
2022-09-13 12:13:23 +03:00
SET v_conda_path = %% a
2022-09-07 01:50:14 +03:00
echo anaconda3/miniconda3 detected in %% a
2022-09-13 12:13:23 +03:00
goto : CONDA_FOUND
2022-09-14 19:43:32 +03:00
)
2022-09-07 01:50:14 +03:00
)
2022-09-13 12:13:23 +03:00
IF " %v_conda_path% " == " " (
2022-09-07 01:50:14 +03:00
echo anaconda3/miniconda3 not found. Install from here https://docs.conda.io/en/latest/miniconda.html
2022-09-15 00:34:15 +03:00
pause
2022-09-07 01:50:14 +03:00
exit /b 1
)
2022-09-13 12:13:23 +03:00
: CONDA_FOUND
2022-09-16 13:12:15 +03:00
echo Stashing local changes and pulling latest update...
2022-10-17 13:01:17 +03:00
git status --porcelain=1 -uno | findstr . && set " HasChanges=1 " || set " HasChanges=0 "
2022-09-16 13:12:15 +03:00
call git stash
call git pull
2022-10-17 13:01:17 +03:00
IF " %HasChanges% " == " 0 " GOTO SKIP_RESTORE
2022-09-16 13:12:15 +03:00
set /P restore = " Do you want to restore changes you made before updating? (Y/N): "
IF /I " %restore% " == " N " (
2022-10-17 13:01:17 +03:00
echo Removing changes...
2022-09-16 13:12:15 +03:00
call git stash drop
2022-10-17 13:01:17 +03:00
echo Changes removed
2022-09-16 13:12:15 +03:00
) ELSE IF /I "%restore%" == "Y" (
2022-10-17 13:01:17 +03:00
echo Restoring changes...
2022-09-16 13:12:15 +03:00
call git stash pop --quiet
2022-10-17 13:01:17 +03:00
echo Changes restored
2022-09-13 12:13:23 +03:00
)
2022-10-17 13:01:17 +03:00
: SKIP_RESTORE
2022-09-16 13:12:15 +03:00
call " %v_conda_path% \Scripts\activate.bat "
2022-09-08 05:21:34 +03:00
2022-09-16 10:35:53 +03:00
for /f " delims= " %% a in ( 'git log -1 --format^=" %% H" -- environment.yaml' ) DO set v_cur_hash = %% a
2022-09-16 13:12:15 +03:00
set /p " v_last_hash= " < " z_version_env.tmp "
echo %v_cur_hash% > z_version_env.tmp
2022-09-16 10:35:53 +03:00
2022-09-16 13:12:15 +03:00
echo Current environment.yaml hash: %v_cur_hash%
echo Previous environment.yaml hash: %v_last_hash%
if " %v_last_hash% " == " %v_cur_hash% " (
echo environment.yaml unchanged. dependencies should be up to date.
echo if you still have unresolved dependencies, delete " z_version_env.tmp "
2022-09-16 10:35:53 +03:00
) else (
2022-09-16 13:12:15 +03:00
echo environment.yaml changed. updating dependencies
call conda env create --name " %v_conda_env_name% " -f environment.yaml
call conda env update --name " %v_conda_env_name% " -f environment.yaml
2022-09-16 10:35:53 +03:00
)
2022-09-16 13:12:15 +03:00
call " %v_conda_path% \Scripts\activate.bat " " %v_conda_env_name% "
2022-09-07 01:50:14 +03:00
: PROMPT
set SETUPTOOLS_USE_DISTUTILS = stdlib
2022-10-27 06:24:47 +03:00
IF EXIST " models\ldm\stable-diffusion-v1\Stable Diffusion v1.5.ckpt " (
2022-10-29 09:21:18 +03:00
python -m streamlit run scripts\webui_streamlit.py --theme.base dark
2022-09-07 01:50:14 +03:00
) ELSE (
2022-10-27 06:24:47 +03:00
echo Your model file does not exist! Once the WebUI launches please visit the Model Manager page and download the models by using the Download button for each model.
2022-10-29 09:21:18 +03:00
python -m streamlit run scripts\webui_streamlit.py --theme.base dark
2022-09-12 11:41:47 +03:00
)
2022-09-16 13:12:15 +03:00
: :cmd /k