-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWebUI-user.bat
114 lines (95 loc) · 3.65 KB
/
WebUI-user.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
@echo off
chcp 65001
::以下所有环境变量设置都无需添加引号""
::#################################################################################################
::设置python路径,不设置则使用默认python路径
set PYTHON=
::设置虚拟环境路径,不设置则使用./venv作为虚拟环境路径
set VENV_DIR=
::下面的设置如果不会设置请保持默认!!!
::设置pip源,此处默认使用清华源
set PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
::设置webUI文件路径
set WEBUI_PATH=webui.py
::设置requirements.txt文件路径,此处默认使用requirements.txt
set REQUIREMENTS_TXT=requirements.txt
::设置Python版本需求
set PYTHON_VERSION_REQUIRED=3.12
::设置PyTorch安装命令,默认安装torch2.2.1+cu118,可前往 https://pytorch.org 复制其他版本的安装命令
set PYTORCH_INSTALL_COMMAND=pip install torch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1 --index-url https://download.pytorch.org/whl/cu118
::#################################################################################################
if not defined PYTHON (set "PYTHON=python")
if not defined VENV_DIR (set "VENV_DIR=%~dp0%venv")
if exist "%VENV_DIR%\Scripts\activate.bat" (
set "PYTHON=%VENV_DIR%\Scripts\python.exe"
)
%PYTHON% -c ""
if %ERRORLEVEL% == 0 (
goto :check_python_version
) else (
echo ERROR: 无法启动Python
pause
exit /b
)
:check_python_version
set "PYTHON_VERSION="
for /f "tokens=1-2" %%a in ('%PYTHON% -c "import sys; print(sys.version_info[0], sys.version_info[1])"') do (
set "PYTHON_VERSION=%%a.%%b"
)
if "%PYTHON_VERSION%"=="%PYTHON_VERSION_REQUIRED%" (
goto :is_venv_exists
) else (
echo =======================================================================================
echo 警告: 您的Python版本为%PYTHON_VERSION%, 在运行过程中可能会出现问题, 推荐安装python版本%PYTHON_VERSION_REQUIRED%!
echo 如需重新创建虚拟环境,请删除%VENV_DIR%目录后重新运行此脚本
echo =======================================================================================
goto :is_venv_exists
)
:is_venv_exists
if exist "%VENV_DIR%\Scripts\activate.bat" goto :is_install_requirements
if %ERRORLEVEL% == 0 goto :create_venv
:create_venv
echo INFO: 正在创建虚拟环境...
%PYTHON% -m venv %VENV_DIR%
goto :install_torch
:install_torch
if exist "%VENV_DIR%\Lib\site-packages\torch" (
goto :install_requirements
) else (
echo INFO: 正在安装PyTorch
%VENV_DIR%\Scripts\python.exe -m %PYTORCH_INSTALL_COMMAND%
if %ERRORLEVEL% EQU 0 (
cls
echo INFO: PyTorch安装完成
goto :install_requirements
) else (
pause
exit /b
)
)
:install_requirements
echo INFO: 正在安装依赖...
call %VENV_DIR%\Scripts\activate.bat
%VENV_DIR%\Scripts\python.exe -m pip install --upgrade pip wheel setuptools -i %PIP_INDEX_URL%
%VENV_DIR%\Scripts\python.exe -m pip install -r %REQUIREMENTS_TXT% -i %PIP_INDEX_URL%
if %ERRORLEVEL% EQU 0 (
cls
goto :save_requirements
) else (
pause
exit /b
)
:save_requirements
%VENV_DIR%\Scripts\python.exe -m pip freeze >%VENV_DIR%\requirements.txt
goto :is_install_requirements
:is_install_requirements
if exist "%VENV_DIR%\requirements.txt" (
echo INFO: 依赖已安装
%PYTHON% -c "import torch; print('INFO: CUDA状态: ' + str(torch.cuda.is_available()))"
) else (
goto :install_torch
)
:start_venv
call "%VENV_DIR%\Scripts\activate.bat"
echo INFO: 正在启动WebUI...请稍等...
%VENV_DIR%\Scripts\python.exe %WEBUI_PATH%