avans06/Audio-To-MIDI-And-Advanced-Renderer
37
1@echo off2 3:: The original source of the webui.bat file is stable-diffusion-webui4:: Modified and enhanced by Gemini with features for venv management and requirements handling.5 6:: --------- Configuration ---------7set COMMANDLINE_ARGS=8:: Define the name of the Launch application9set APPLICATION_NAME=app.py10:: Define the name of the virtual environment directory11set VENV_NAME=venv12:: Set to 1 to always attempt to update packages from requirements.txt on every launch13set ALWAYS_UPDATE_REQS=014:: ---------------------------------15 16 17:: Set PYTHON executable if not already defined18if not defined PYTHON (set PYTHON=python)19:: Set VENV_DIR using VENV_NAME if not already defined20if not defined VENV_DIR (set "VENV_DIR=%~dp0%VENV_NAME%")21 22mkdir tmp 2>NUL23 24:: Check if Python is callable25%PYTHON% -c "" >tmp/stdout.txt 2>tmp/stderr.txt26if %ERRORLEVEL% == 0 goto :check_pip27echo Couldn't launch python28goto :show_stdout_stderr29 30:check_pip31:: Check if pip is available32%PYTHON% -mpip --help >tmp/stdout.txt 2>tmp/stderr.txt33if %ERRORLEVEL% == 0 goto :start_venv34:: If pip is not available and PIP_INSTALLER_LOCATION is set, try to install pip35if "%PIP_INSTALLER_LOCATION%" == "" goto :show_stdout_stderr36%PYTHON% "%PIP_INSTALLER_LOCATION%" >tmp/stdout.txt 2>tmp/stderr.txt37if %ERRORLEVEL% == 0 goto :start_venv38echo Couldn't install pip39goto :show_stdout_stderr40 41:start_venv42:: Skip venv creation/activation if VENV_DIR is explicitly set to "-"43if ["%VENV_DIR%"] == ["-"] goto :skip_venv_entirely44:: Skip venv creation/activation if SKIP_VENV is set to "1"45if ["%SKIP_VENV%"] == ["1"] goto :skip_venv_entirely46 47:: Check if the venv already exists by looking for Python.exe in its Scripts directory48dir "%VENV_DIR%\Scripts\Python.exe" >tmp/stdout.txt 2>tmp/stderr.txt49if %ERRORLEVEL% == 0 goto :activate_venv_and_maybe_update50 51:: Venv does not exist, create it52echo Virtual environment not found in "%VENV_DIR%". Creating a new one.53for /f "delims=" %%i in ('CALL %PYTHON% -c "import sys; print(sys.executable)"') do set PYTHON_FULLNAME="%%i"54echo Creating venv in directory %VENV_DIR% using python %PYTHON_FULLNAME%55%PYTHON_FULLNAME% -m venv "%VENV_DIR%" >tmp/stdout.txt 2>tmp/stderr.txt56if %ERRORLEVEL% NEQ 0 (57 echo Unable to create venv in directory "%VENV_DIR%"58 goto :show_stdout_stderr59)60echo Venv created.61 62:: Install requirements for the first time if venv was just created63:: This section handles the initial installation of packages from requirements.txt64:: immediately after a new virtual environment is created.65echo Checking for requirements.txt for initial setup in %~dp066if exist "%~dp0requirements.txt" (67 echo Found requirements.txt, attempting to install for initial setup...68 call "%VENV_DIR%\Scripts\activate.bat"69 echo Installing packages from requirements.txt ^(initial setup^)...70 "%VENV_DIR%\Scripts\python.exe" -m pip install -r "%~dp0requirements.txt"71 if %ERRORLEVEL% NEQ 0 (72 echo Failed to install requirements during initial setup. Please check the output above.73 pause74 goto :show_stdout_stderr_custom_pip_initial 75 )76 echo Initial requirements installed successfully.77 call "%VENV_DIR%\Scripts\deactivate.bat"78) else (79 echo No requirements.txt found for initial setup, skipping package installation.80)81goto :activate_venv_and_maybe_update82 83 84:activate_venv_and_maybe_update85:: This label is reached if the venv exists or was just created.86:: Set PYTHON to point to the venv's Python interpreter.87set PYTHON="%VENV_DIR%\Scripts\Python.exe"88echo Activating venv: %PYTHON%89 90:: Always update requirements if ALWAYS_UPDATE_REQS is 191:: This section allows for updating packages from requirements.txt on every launch92:: if the ALWAYS_UPDATE_REQS variable is set to 1.93if defined ALWAYS_UPDATE_REQS (94 if "%ALWAYS_UPDATE_REQS%"=="1" (95 echo ALWAYS_UPDATE_REQS is enabled.96 if exist "%~dp0requirements.txt" (97 echo Attempting to update packages from requirements.txt...98 REM No need to call activate.bat here again, PYTHON is already set to the venv's python99 %PYTHON% -m pip install -r "%~dp0requirements.txt"100 if %ERRORLEVEL% NEQ 0 (101 echo Failed to update requirements. Please check the output above.102 pause103 goto :endofscript 104 )105 echo Requirements updated successfully.106 ) else (107 echo ALWAYS_UPDATE_REQS is enabled, but no requirements.txt found. Skipping update.108 )109 ) else (110 echo ALWAYS_UPDATE_REQS is not enabled or not set to 1. Skipping routine update.111 )112)113 114goto :launch115 116:skip_venv_entirely117:: This label is reached if venv usage is explicitly skipped.118echo Skipping venv.119goto :launch120 121:launch122:: Launch the main application123echo Launching Web UI with arguments: %COMMANDLINE_ARGS% %*124%PYTHON% %APPLICATION_NAME% %COMMANDLINE_ARGS% %*125echo Launch finished.126pause127exit /b128 129:show_stdout_stderr_custom_pip_initial130:: Custom error handler for failures during the initial pip install process.131echo.132echo exit code ^(pip initial install^): %errorlevel%133echo Errors during initial pip install. See output above.134echo.135echo Launch unsuccessful. Exiting.136pause137exit /b138 139 140:show_stdout_stderr141:: General error handler: displays stdout and stderr from the tmp directory.142echo.143echo exit code: %errorlevel%144 145for /f %%i in ("tmp\stdout.txt") do set size=%%~zi146if %size% equ 0 goto :show_stderr147echo.148echo stdout:149type tmp\stdout.txt150 151:show_stderr152for /f %%i in ("tmp\stderr.txt") do set size=%%~zi153if %size% equ 0 goto :endofscript154echo.155echo stderr:156type tmp\stderr.txt157 158:endofscript159echo.160echo Launch unsuccessful. Exiting.161pause162exit /b