Files
glm-coding-helper/scripts/one_click_start.ps1
T
OLmatterandClaude Opus 4.7 66a9ea559e feat(backend): pipeline GUI launcher + 精简启动器
新增 backend/gui.py Tk 监控窗口:
- 拉起 backend.server 子进程并接管 stdout
- 顶部状态栏(启动中/运行中、YOLO/OCR worker 数、监听地址)
- 中间识别列表(最近 20 条 prompt/pred_text/confidence/耗时)
- 底部日志框(stdout 实时滚动,高亮 worker ready / 错误)
- 关闭窗口自动 terminate 后端

后端新增 /recent?limit=20 端口(GUI 拉取最近识别结果),
/health 同步返回 n_yolo / n_ocr / port 字段。

精简根目录启动器(7 → 2):
- 删 start-backend.cmd / start-backend-pipeline.cmd /
      install-env.cmd / 启动后端.cmd / 首次安装环境.cmd
- 留 one-click-start.cmd(首次装环境)
- 留 start-backend-pipeline-gui.cmd(日常启动 + GUI)
- start-backend-pipeline.ps1 → start-backend-pipeline-gui.ps1

打包脚本 build_portable.ps1 / build_release_zips.ps1 同步
更新入口列表和错误提示。

补 .gitignore: official_models/(81M OCR 模型权重,不入库)

补 scripts/tools/evaluate_pipeline_compare.py(PR #10 评估
脚本,cherry-pick 时漏了)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-15 22:53:36 +08:00

101 lines
3.4 KiB
PowerShell

param(
[ValidateSet("auto", "cpu", "gpu")]
[string]$Target = "auto",
[int]$Port = 8888,
[string[]]$PipArg = @()
)
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent $PSScriptRoot
Set-Location $Root
$env:PYTHONUTF8 = "1"
$env:PYTHONIOENCODING = "utf-8"
function Test-PythonImports {
param(
[string]$PythonPath,
[string]$Code
)
if (-not $PythonPath -or -not (Test-Path $PythonPath)) { return $false }
try {
& $PythonPath -c $Code *> $null
return $LASTEXITCODE -eq 0
} catch {
return $false
}
}
function Has-NvidiaGpu {
$nvidia = Get-Command nvidia-smi -ErrorAction SilentlyContinue
if (-not $nvidia) { return $false }
& nvidia-smi -L *> $null
return $LASTEXITCODE -eq 0
}
$InstallTarget = $Target
if ($InstallTarget -eq "auto") {
$InstallTarget = if (Has-NvidiaGpu) { "gpu" } else { "cpu" }
}
$StartMode = if ($Target -eq "auto") { "auto" } else { $InstallTarget }
$CpuPython = Join-Path $Root ".venv_paddle\Scripts\python.exe"
$GpuPython = Join-Path $Root ".venv_paddle_gpu\Scripts\python.exe"
$ImportCode = "import ultralytics, paddleocr, paddlex, cv2, PIL, numpy"
$Ready = $false
$SelectedPython = ""
if ($InstallTarget -eq "gpu") {
$SelectedPython = $GpuPython
$Ready = Test-PythonImports $GpuPython $ImportCode
} else {
$SelectedPython = $CpuPython
$Ready = Test-PythonImports $CpuPython $ImportCode
}
if (-not $Ready) {
Write-Host "Backend environment is missing or incomplete (PIL/cv2/numpy etc). Installing $InstallTarget environment..."
$argsList = @("-Target", $InstallTarget)
if ($SelectedPython -and (Test-Path $SelectedPython)) {
Write-Host "Existing backend environment failed import checks. Recreating it..."
$argsList += "-Recreate"
}
foreach ($arg in $PipArg) {
$argsList += "-PipArg"
$argsList += $arg
}
& powershell -NoProfile -ExecutionPolicy Bypass -File "scripts\bootstrap_windows.ps1" @argsList
# 修复后重新验证
if ($InstallTarget -eq "gpu") {
$Ready = Test-PythonImports $GpuPython $ImportCode
} else {
$Ready = Test-PythonImports $CpuPython $ImportCode
}
if (-not $Ready) {
Write-Host "[FAIL] Backend environment repair failed. Required deps still missing." -ForegroundColor Red
Write-Host " Try running one-click-start.cmd manually." -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
}
if ($Target -eq "auto" -and $InstallTarget -eq "gpu" -and -not (Test-PythonImports $CpuPython $ImportCode)) {
Write-Host "CPU fallback environment is missing. Installing CPU environment for auto fallback..."
$fallbackArgs = @("-Target", "cpu")
foreach ($arg in $PipArg) {
$fallbackArgs += "-PipArg"
$fallbackArgs += $arg
}
& powershell -NoProfile -ExecutionPolicy Bypass -File "scripts\bootstrap_windows.ps1" @fallbackArgs
}
# ── 检查 pipeline 后端依赖(非阻塞,仅提示)─────────────────
$PipelineDepsOk = Test-PythonImports $SelectedPython "import fastapi, uvicorn, psutil"
if (-not $PipelineDepsOk) {
Write-Host "[INFO] Pipeline backend deps (fastapi/uvicorn/psutil) not installed. Run start-backend-pipeline-gui.cmd to add them." -ForegroundColor Yellow
}
Write-Host "Starting backend in $StartMode mode on port $Port..."
& powershell -NoProfile -ExecutionPolicy Bypass -File "scripts\start_backend.ps1" -Mode $StartMode -Port $Port