Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix: harden Windows WebUI launcher

harry07039cbe6686dd45
diff --git a/README-en.md b/README-en.md
index 0b512e76..cdfa8251 100644
--- a/README-en.md
+++ b/README-en.md
@@ -159,7 +159,7 @@ docker-compose up
#### ② Access the Web Interface
-Open your browser and visit http://0.0.0.0:8501
+Open your browser and visit http://127.0.0.1:8501
#### ③ Access the API Interface
@@ -223,15 +223,13 @@ Note that you need to execute the following commands in the `root directory` of
###### Windows
-```shell
-uv run streamlit run ./webui/Main.py --browser.gatherUsageStats=False
+```powershell
+.\webui.bat
```
-If you have already activated the virtual environment manually, you can still run:
-
-```bat
-webui.bat
-```
+You can also run `webui.bat` in CMD.
+`webui.bat` prefers the project `.venv` or bundled Python from the portable package. If no project Python is found but `uv` is installed, it automatically falls back to `uv run streamlit`.
+To allow other devices on your LAN to access the WebUI, run `set MPT_WEBUI_HOST=0.0.0.0` before running `webui.bat`.
###### MacOS or Linux
diff --git a/README.md b/README.md
index 58238254..614ebd63 100644
--- a/README.md
+++ b/README.md
@@ -161,7 +161,7 @@ docker-compose up
#### ② 访问Web界面
-打开浏览器,访问 http://0.0.0.0:8501
+打开浏览器,访问 http://127.0.0.1:8501
#### ③ 访问API文档
@@ -225,15 +225,13 @@ pip install -r requirements.txt
###### Windows
-```shell
-uv run streamlit run ./webui/Main.py --browser.gatherUsageStats=False
+```powershell
+.\webui.bat
```
-如果你已经手动激活了虚拟环境,也可以直接执行:
-
-```bat
-webui.bat
-```
+在 CMD 中也可以执行 `webui.bat`。
+`webui.bat` 会优先使用项目 `.venv` 或一键包内置 Python;如果没有找到项目 Python,但已安装 `uv`,会自动切换为 `uv run streamlit`。
+如需允许局域网内其他设备访问 WebUI,可以先执行 `set MPT_WEBUI_HOST=0.0.0.0`,再运行 `webui.bat`。
###### MacOS or Linux
diff --git a/webui.bat b/webui.bat
index fd975146..cc20c768 100644
--- a/webui.bat
+++ b/webui.bat
@@ -1,7 +1,52 @@
@echo off
-set CURRENT_DIR=%CD%
+setlocal
+set "CURRENT_DIR=%CD%"
echo ***** Current directory: %CURRENT_DIR% *****
-set PYTHONPATH=%CURRENT_DIR%
+set "PYTHONPATH=%CURRENT_DIR%"
rem set HF_ENDPOINT=https://hf-mirror.com
-streamlit run .\webui\Main.py --browser.gatherUsageStats=False --server.enableCORS=True
\ No newline at end of file
+
+if not defined MPT_WEBUI_HOST set "MPT_WEBUI_HOST=127.0.0.1"
+if not defined MPT_WEBUI_PORT set "MPT_WEBUI_PORT=8501"
+
+set "STREAMLIT_CMD="
+if exist "%CURRENT_DIR%\.venv\Scripts\python.exe" (
+ set "STREAMLIT_CMD="%CURRENT_DIR%\.venv\Scripts\python.exe" -m streamlit"
+) else if exist "%CURRENT_DIR%\lib\python\python.exe" (
+ set "STREAMLIT_CMD="%CURRENT_DIR%\lib\python\python.exe" -m streamlit"
+) else (
+ where uv >nul 2>nul
+ if not errorlevel 1 set "STREAMLIT_CMD=uv run streamlit"
+)
+
+if not defined STREAMLIT_CMD (
+ where streamlit >nul 2>nul
+ if not errorlevel 1 (
+ echo ***** Warning: using streamlit from PATH. If dependencies fail, run 'uv sync --frozen' first. *****
+ set "STREAMLIT_CMD=streamlit"
+ )
+)
+
+if not defined STREAMLIT_CMD (
+ echo ***** Neither project Python, uv, nor streamlit was found. Please install dependencies first. *****
+ pause
+ exit /b 1
+)
+
+set "SELECTED_WEBUI_PORT="
+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"
+
+if not defined SELECTED_WEBUI_PORT (
+ echo ***** No available WebUI port found in 8501-8599 for %MPT_WEBUI_HOST%. *****
+ echo ***** If Windows reports WinError 10013, check reserved ports: netsh interface ipv4 show excludedportrange protocol=tcp *****
+ pause
+ exit /b 1
+)
+
+if not "%SELECTED_WEBUI_PORT%"=="%MPT_WEBUI_PORT%" (
+ echo ***** Port %MPT_WEBUI_PORT% is unavailable, using %SELECTED_WEBUI_PORT% instead. *****
+)
+set "MPT_WEBUI_PORT=%SELECTED_WEBUI_PORT%"
+
+echo ***** WebUI address: http://%MPT_WEBUI_HOST%:%MPT_WEBUI_PORT% *****
+%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.enableCORS=True