File size: 3,352 Bytes
dee9e18 1571e78 dee9e18 de54a83 dee9e18 |
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
param(
[ValidateSet('streamlit', 'panel')]
[string]$App = 'streamlit',
[int]$Port = 0,
[Alias('Host')]
[string]$Address = 'localhost',
[switch]$Reload,
[switch]$NoBrowser,
[string]$Entry
)
$validApps = @('streamlit', 'panel')
if (-not $PSBoundParameters.ContainsKey('App')) {
Write-Host "Choisissez l'application à lancer :" -ForegroundColor Cyan
Write-Host "1) Streamlit" -ForegroundColor Yellow
Write-Host "2) Panel" -ForegroundColor Yellow
do {
$choice = Read-Host "Entrez 1 pour Streamlit, 2 pour Panel (Entrée = Streamlit)"
switch ($choice) {
'' { $App = 'streamlit'; $isValidChoice = $true }
'1' { $App = 'streamlit'; $isValidChoice = $true }
'2' { $App = 'panel'; $isValidChoice = $true }
default {
$choiceLower = $choice.ToLower()
if ($validApps -contains $choiceLower) {
$App = $choiceLower
$isValidChoice = $true
}
else {
Write-Host "Choix invalide. Réessayez." -ForegroundColor Red
$isValidChoice = $false
}
}
}
} until ($isValidChoice)
}
$ErrorActionPreference = 'Stop'
$repoRoot = $PSScriptRoot
if (-not $PSBoundParameters.ContainsKey('Port') -or $Port -eq 0) {
if ($App -eq 'panel') {
$Port = 5006
}
else {
$Port = 8501
}
}
$venvActivateCandidates = @(
(Join-Path $repoRoot '.venv\Scripts\Activate.ps1'),
(Join-Path $repoRoot 'venv\Scripts\Activate.ps1')
)
$venvActivate = $venvActivateCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1
if ($venvActivate) {
. $venvActivate
}
function Invoke-PythonModule {
param(
[Parameter(Mandatory = $true)]
[string]$Module,
[Parameter(Mandatory = $true)]
[string[]]$Args
)
$python = Get-Command python -ErrorAction SilentlyContinue
if (-not $python) {
throw "python not found in PATH. Install Python or create/activate a venv (e.g. .\\.venv\\Scripts\\Activate.ps1)."
}
& $python.Source -m $Module @Args
}
if ($App -eq 'streamlit') {
if (-not $Entry) { $Entry = 'app.py' }
$entryPath = Join-Path $repoRoot $Entry
if (-not (Test-Path $entryPath)) {
throw "Streamlit entry not found: $entryPath"
}
$cmdArgs = @(
'run',
$entryPath,
'--server.port', $Port,
'--server.address', $Address,
'--server.fileWatcherType', 'poll'
)
if ($NoBrowser) { $cmdArgs += @('--server.headless', 'true') }
if ($Reload) { $cmdArgs += @('--server.runOnSave', 'true') }
Invoke-PythonModule -Module 'streamlit' -Args $cmdArgs
exit $LASTEXITCODE
}
if ($App -eq 'panel') {
if (-not $Entry) { $Entry = 'panel_app\panel_portal.py' }
$entryPath = Join-Path $repoRoot $Entry
if (-not (Test-Path $entryPath)) {
throw "Panel entry not found: $entryPath"
}
$cmdArgs = @(
'serve',
$entryPath,
'--port', $Port,
'--address', $Address
)
if (-not $NoBrowser) { $cmdArgs += '--show' }
if ($Reload) { $cmdArgs += '--autoreload' }
Invoke-PythonModule -Module 'panel' -Args $cmdArgs
exit $LASTEXITCODE
}
throw "Unknown app: $App"
|