File size: 1,688 Bytes
496ca41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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
}