webui.bat 2.5 KB

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