Spaces:
Sleeping
Sleeping
| # The Podium — local dev launcher | |
| # Frees the port, starts app.py, opens the browser when Gradio is ready. | |
| $ErrorActionPreference = "Continue" | |
| $Root = Split-Path -Parent $PSScriptRoot | |
| Set-Location $Root | |
| $Port = if ($env:GRADIO_SERVER_PORT) { [int]$env:GRADIO_SERVER_PORT } else { 7860 } | |
| function Stop-ListenersOnPort { | |
| param([int]$Port) | |
| $seen = @{} | |
| netstat -ano | ForEach-Object { | |
| $line = $_.Trim() | |
| if ($line -notmatch "LISTENING") { return } | |
| if ($line -notmatch ":$Port\s") { return } | |
| $processId = ($line -split '\s+')[-1] | |
| if ($processId -notmatch '^\d+$' -or $processId -eq '0' -or $seen.ContainsKey($processId)) { return } | |
| $seen[$processId] = $true | |
| Write-Host " Freeing port $Port (stopping PID $processId)..." | |
| Stop-Process -Id ([int]$processId) -Force -ErrorAction SilentlyContinue | |
| } | |
| Start-Sleep -Milliseconds 400 | |
| } | |
| function Get-Python { | |
| $venv = Join-Path $Root ".venv\Scripts\python.exe" | |
| if (Test-Path $venv) { return $venv } | |
| return "python" | |
| } | |
| # Clear stale servers from this project (7860 + common fallback) | |
| Stop-ListenersOnPort $Port | |
| Stop-ListenersOnPort ($Port + 1) | |
| $env:GRADIO_SERVER_PORT = "$Port" | |
| $env:PODIUM_OPEN_BROWSER = "1" | |
| $python = Get-Python | |
| Write-Host "" | |
| Write-Host " THE PODIUM" | |
| Write-Host " http://localhost:$Port" | |
| Write-Host "" | |
| Write-Host " Browser opens automatically when the server is ready." | |
| Write-Host " Close this window or press Ctrl+C to stop the server." | |
| Write-Host "" | |
| & $python app.py | |
| $exit = $LASTEXITCODE | |
| if ($exit -and $exit -ne 0) { | |
| Write-Host "" | |
| Write-Host " Server exited with code $exit." -ForegroundColor Red | |
| exit $exit | |
| } | |