forked from azuritecoin/OnnxDiffusersUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.bat
119 lines (97 loc) · 4.55 KB
/
setup.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
@echo off
set first_run=0
set venv_path="virtualenv"
set model_path="model"
:: check if programs are installed
python --version 1> NUL 2> NUL
if %errorlevel% NEQ 0 goto NoPython
git --version 1> NUL 2> NUL
if %errorlevel% NEQ 0 goto NoGit
pip --version 1> NUL 2> NUL
if %errorlevel% NEQ 0 goto NoPip
:: parse the parameters
set update=0
:ArgParseLoop
if not "%1"=="" (
if "%1"=="-update" (
set update=1
)
shift
goto ArgParseLoop
)
:: check if virtual environment is present, else create it and install requirements
if exist %venv_path%\Scripts\activate.bat goto ActivateVirtEnv
echo no %venv_path% folder detected, creating virtual environment
set first_run=1
python -m venv %venv_path% --upgrade-deps
:ActivateVirtEnv
call %venv_path%\Scripts\activate.bat
:: for the first run, get requirements and install packages
if %first_run%==0 goto ScriptDownload
pip install wheel
:: using wget from python library instead of standalone wget for Windows
pip install wget
echo installing Python packages
if not exist requirements.txt python -m wget https://raw.githubusercontent.com/azuritecoin/OnnxDiffusersUI/main/requirements.txt
pip install -r requirements.txt
:: install onnxruntime-directml separately after onnxruntime to enable DmlExecutionProvider
pip install onnxruntime-directml
:ScriptDownload
if not exist onnxUI.py python -m wget https://raw.githubusercontent.com/azuritecoin/OnnxDiffusersUI/main/onnxUI.py
if not exist txt2img_onnx.py python -m wget https://raw.githubusercontent.com/azuritecoin/OnnxDiffusersUI/main/txt2img_onnx.py
if not exist lpw_pipe.py python -m wget https://raw.githubusercontent.com/azuritecoin/OnnxDiffusersUI/main/lpw_pipe.py
:: get version number from pip
for /F "delims= eol=|" %%f in ('pip show diffusers ^| findstr "Version"') do set version_tag=%%f
set version_tag=v%version_tag:~9%
if not exist convert_original_stable_diffusion_to_diffusers.py (
python -m wget https://raw.githubusercontent.com/huggingface/diffusers/%version_tag%/scripts/convert_original_stable_diffusion_to_diffusers.py -o convert_original_stable_diffusion_to_diffusers.py
)
if not exist convert_stable_diffusion_checkpoint_to_onnx.py (
python -m wget https://raw.githubusercontent.com/huggingface/diffusers/%version_tag%/scripts/convert_stable_diffusion_checkpoint_to_onnx.py -o convert_stable_diffusion_checkpoint_to_onnx.py
)
if not exist v1-inference.yaml (
python -m wget https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml -o v1-inference.yaml
)
if not exist %model_path% mkdir %model_path%
:: update the python packages and redownload onnxUI.py
if %first_run% NEQ 0 goto FinishSetup
if %update%==0 goto FinishSetup
python -m pip install --upgrade pip
pip install -U wget wheel
:: need to uninstall these two packages to upgrade
pip uninstall --yes onnxruntime-directml
if exist requirements.txt del requirements.txt
python -m wget https://raw.githubusercontent.com/azuritecoin/OnnxDiffusersUI/main/requirements.txt
pip install -U -r requirements.txt
pip install -U onnxruntime-directml
for /F "delims= eol=|" %%f in ('pip show diffusers ^| findstr "Version"') do set version_tag=%%f
set version_tag=v%version_tag:~9%
if exist onnxUI.py del onnxUI.py
python -m wget https://raw.githubusercontent.com/azuritecoin/OnnxDiffusersUI/main/onnxUI.py
if exist txt2img_onnx.py del txt2img_onnx.py
python -m wget https://raw.githubusercontent.com/azuritecoin/OnnxDiffusersUI/main/txt2img_onnx.py
if exist lpw_pipe.py del lpw_pipe.py
python -m wget https://raw.githubusercontent.com/azuritecoin/OnnxDiffusersUI/main/lpw_pipe.py
if exist convert_original_stable_diffusion_to_diffusers.py del convert_original_stable_diffusion_to_diffusers.py
python -m wget https://raw.githubusercontent.com/huggingface/diffusers/%version_tag%/scripts/convert_original_stable_diffusion_to_diffusers.py -o convert_original_stable_diffusion_to_diffusers.py
if exist convert_stable_diffusion_checkpoint_to_onnx.py del convert_stable_diffusion_checkpoint_to_onnx.py
python -m wget https://raw.githubusercontent.com/huggingface/diffusers/%version_tag%/scripts/convert_stable_diffusion_checkpoint_to_onnx.py -o convert_stable_diffusion_checkpoint_to_onnx.py
if exist v1-inference.yaml del v1-inference.yaml
python -m wget https://raw.githubusercontent.com/CompVis/stable-diffusion/main/configs/stable-diffusion/v1-inference.yaml -o v1-inference.yaml
:FinishSetup
echo setup complete
pause
deactivate
goto :eof
:NoPython
echo python not found
goto CheckError
:NoGit
echo git not found
goto CheckError
:NoPip
echo pip not found
goto CheckError
:CheckError
pause
goto :eof