webui.bat 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. @echo off
  2. if exist webui.settings.bat (
  3. call webui.settings.bat
  4. )
  5. if not defined PYTHON (
  6. for /f "delims=" %%A in ('where python ^| findstr /n . ^| findstr ^^1:') do (
  7. if /i "%%~xA" == ".exe" (
  8. set PYTHON=python
  9. ) else (
  10. set PYTHON=call python
  11. )
  12. )
  13. )
  14. if defined GIT (set "GIT_PYTHON_GIT_EXECUTABLE=%GIT%")
  15. if not defined VENV_DIR (set "VENV_DIR=%~dp0%venv")
  16. set SD_WEBUI_RESTART=tmp/restart
  17. set ERROR_REPORTING=FALSE
  18. mkdir tmp 2>NUL
  19. %PYTHON% -c "" >tmp/stdout.txt 2>tmp/stderr.txt
  20. if %ERRORLEVEL% == 0 goto :check_pip
  21. echo Couldn't launch python
  22. goto :show_stdout_stderr
  23. :check_pip
  24. %PYTHON% -mpip --help >tmp/stdout.txt 2>tmp/stderr.txt
  25. if %ERRORLEVEL% == 0 goto :start_venv
  26. if "%PIP_INSTALLER_LOCATION%" == "" goto :show_stdout_stderr
  27. %PYTHON% "%PIP_INSTALLER_LOCATION%" >tmp/stdout.txt 2>tmp/stderr.txt
  28. if %ERRORLEVEL% == 0 goto :start_venv
  29. echo Couldn't install pip
  30. goto :show_stdout_stderr
  31. :start_venv
  32. if ["%VENV_DIR%"] == ["-"] goto :skip_venv
  33. if ["%SKIP_VENV%"] == ["1"] goto :skip_venv
  34. dir "%VENV_DIR%\Scripts\Python.exe" >tmp/stdout.txt 2>tmp/stderr.txt
  35. if %ERRORLEVEL% == 0 goto :activate_venv
  36. for /f "delims=" %%i in ('CALL %PYTHON% -c "import sys; print(sys.executable)"') do set PYTHON_FULLNAME="%%i"
  37. echo Creating venv in directory %VENV_DIR% using python %PYTHON_FULLNAME%
  38. %PYTHON_FULLNAME% -m venv "%VENV_DIR%" >tmp/stdout.txt 2>tmp/stderr.txt
  39. if %ERRORLEVEL% == 0 goto :upgrade_pip
  40. echo Unable to create venv in directory "%VENV_DIR%"
  41. goto :show_stdout_stderr
  42. :upgrade_pip
  43. "%VENV_DIR%\Scripts\Python.exe" -m pip install --upgrade pip
  44. if %ERRORLEVEL% == 0 goto :activate_venv
  45. echo Warning: Failed to upgrade PIP version
  46. :activate_venv
  47. set PYTHON="%VENV_DIR%\Scripts\Python.exe"
  48. call "%VENV_DIR%\Scripts\activate.bat"
  49. echo venv %PYTHON%
  50. :skip_venv
  51. if [%ACCELERATE%] == ["True"] goto :accelerate
  52. goto :launch
  53. :accelerate
  54. echo Checking for accelerate
  55. set ACCELERATE="%VENV_DIR%\Scripts\accelerate.exe"
  56. if EXIST %ACCELERATE% goto :accelerate_launch
  57. :launch
  58. %PYTHON% launch.py %*
  59. if EXIST tmp/restart goto :skip_venv
  60. pause
  61. exit /b
  62. :accelerate_launch
  63. echo Accelerating
  64. %ACCELERATE% launch --num_cpu_threads_per_process=6 launch.py
  65. if EXIST tmp/restart goto :skip_venv
  66. pause
  67. exit /b
  68. :show_stdout_stderr
  69. echo.
  70. echo exit code: %errorlevel%
  71. for /f %%i in ("tmp\stdout.txt") do set size=%%~zi
  72. if %size% equ 0 goto :show_stderr
  73. echo.
  74. echo stdout:
  75. type tmp\stdout.txt
  76. :show_stderr
  77. for /f %%i in ("tmp\stderr.txt") do set size=%%~zi
  78. if %size% equ 0 goto :show_stderr
  79. echo.
  80. echo stderr:
  81. type tmp\stderr.txt
  82. :endofscript
  83. echo.
  84. echo Launch unsuccessful. Exiting.
  85. pause