| 1 | @echo off |
| 2 | setlocal |
| 3 | set "CURRENT_DIR=%CD%" |
| 4 | echo ***** Current directory: %CURRENT_DIR% ***** |
| 5 | set "PYTHONPATH=%CURRENT_DIR%" |
| 6 | |
| 7 | rem set HF_ENDPOINT=https://hf-mirror.com |
| 8 | |
| 9 | if not defined MPT_WEBUI_HOST set "MPT_WEBUI_HOST=127.0.0.1" |
| 10 | if not defined MPT_WEBUI_PORT set "MPT_WEBUI_PORT=8501" |
| 11 | |
| 12 | set "STREAMLIT_CMD=" |
| 13 | if exist "%CURRENT_DIR%\.venv\Scripts\python.exe" ( |
| 14 | set "STREAMLIT_CMD="%CURRENT_DIR%\.venv\Scripts\python.exe" -m streamlit" |
| 15 | ) else if exist "%CURRENT_DIR%\lib\python\python.exe" ( |
| 16 | set "STREAMLIT_CMD="%CURRENT_DIR%\lib\python\python.exe" -m streamlit" |
| 17 | ) else ( |
| 18 | where uv >nul 2>nul |
| 19 | if not errorlevel 1 set "STREAMLIT_CMD=uv run streamlit" |
| 20 | ) |
| 21 | |
| 22 | if not defined STREAMLIT_CMD ( |
| 23 | where streamlit >nul 2>nul |
| 24 | if not errorlevel 1 ( |
| 25 | echo ***** Warning: using streamlit from PATH. If dependencies fail, run 'uv sync --frozen' first. ***** |
| 26 | set "STREAMLIT_CMD=streamlit" |
| 27 | ) |
| 28 | ) |
| 29 | |
| 30 | if not defined STREAMLIT_CMD ( |
| 31 | echo ***** Neither project Python, uv, nor streamlit was found. Please install dependencies first. ***** |
| 32 | pause |
| 33 | exit /b 1 |
| 34 | ) |
| 35 | |
| 36 | set "SELECTED_WEBUI_PORT=" |
| 37 | for /f %%P in ('powershell -NoProfile -ExecutionPolicy Bypass -Command "$hostAddress=$null; foreach ($address in [Net.Dns]::GetHostAddresses($env:MPT_WEBUI_HOST)) { if ($address.AddressFamily -eq [Net.Sockets.AddressFamily]::InterNetwork) { $hostAddress=$address; break } }; if ($null -eq $hostAddress) { exit 1 }; $preferred=[int]$env:MPT_WEBUI_PORT; $candidates=New-Object System.Collections.Generic.List[int]; $candidates.Add($preferred); foreach ($candidate in 8502..8599) { if ($candidate -ne $preferred) { $candidates.Add($candidate) } }; foreach ($port in $candidates) { $socket=[Net.Sockets.Socket]::new([Net.Sockets.AddressFamily]::InterNetwork,[Net.Sockets.SocketType]::Stream,[Net.Sockets.ProtocolType]::Tcp); try { $socket.Bind([Net.IPEndPoint]::new($hostAddress,$port)); $socket.Close(); Write-Output $port; exit 0 } catch { try { $socket.Close() } catch {} } }; exit 1"') do set "SELECTED_WEBUI_PORT=%%P" |
| 38 | |
| 39 | if not defined SELECTED_WEBUI_PORT ( |
| 40 | echo ***** No available WebUI port found in 8501-8599 for %MPT_WEBUI_HOST%. ***** |
| 41 | echo ***** If Windows reports WinError 10013, check reserved ports: netsh interface ipv4 show excludedportrange protocol=tcp ***** |
| 42 | pause |
| 43 | exit /b 1 |
| 44 | ) |
| 45 | |
| 46 | if not "%SELECTED_WEBUI_PORT%"=="%MPT_WEBUI_PORT%" ( |
| 47 | echo ***** Port %MPT_WEBUI_PORT% is unavailable, using %SELECTED_WEBUI_PORT% instead. ***** |
| 48 | ) |
| 49 | set "MPT_WEBUI_PORT=%SELECTED_WEBUI_PORT%" |
| 50 | |
| 51 | echo ***** WebUI address: http://%MPT_WEBUI_HOST%:%MPT_WEBUI_PORT% ***** |
| 52 | %STREAMLIT_CMD% run .\webui\Main.py --server.address=%MPT_WEBUI_HOST% --server.port=%MPT_WEBUI_PORT% --browser.serverAddress=%MPT_WEBUI_HOST% --browser.gatherUsageStats=False --server.showEmailPrompt=False --server.enableCORS=True |
| 53 |