-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.ps1
More file actions
72 lines (61 loc) · 1.92 KB
/
Copy pathrun.ps1
File metadata and controls
72 lines (61 loc) · 1.92 KB
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
param(
[switch]$SkipInstall,
[int]$Port = 8501
)
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $root
function Load-DotEnv {
param([string]$Path)
if (-not (Test-Path $Path)) {
return
}
Get-Content $Path | ForEach-Object {
$line = $_.Trim()
if (-not $line -or $line.StartsWith("#") -or -not $line.Contains("=")) {
return
}
$pair = $line.Split("=", 2)
$key = $pair[0].Trim()
$value = $pair[1].Trim().Trim("'`"")
if ($key -and -not [string]::IsNullOrWhiteSpace($value)) {
Set-Item -Path "Env:$key" -Value $value
}
}
}
Load-DotEnv -Path ".env"
$hfModel = if ($env:HF_MODEL) { $env:HF_MODEL } else { "HuggingFaceTB/SmolLM2-1.7B-Instruct" }
Write-Host "Starting AI Support Intelligence Dashboard..."
Write-Host "Model Profile: $hfModel"
function Get-FreePort {
param([int]$PreferredPort)
for ($candidate = $PreferredPort; $candidate -lt ($PreferredPort + 20); $candidate++) {
$listener = $null
try {
$listener = [System.Net.Sockets.TcpListener]::new([System.Net.IPAddress]::Loopback, $candidate)
$listener.Start()
$listener.Stop()
return $candidate
} catch {
if ($listener) {
try { $listener.Stop() } catch {}
}
continue
}
}
return $PreferredPort
}
Write-Host "Starting Streamlit..."
$pythonExe = "python"
if (Test-Path ".\\.venv\\Scripts\\python.exe") {
$pythonExe = ".\\.venv\\Scripts\\python.exe"
}
if (-not $SkipInstall) {
Write-Host "Installing dependencies..."
& $pythonExe -m pip install -r requirements.txt
}
$finalPort = Get-FreePort -PreferredPort $Port
if ($finalPort -ne $Port) {
Write-Host "Port $Port is busy. Using available port $finalPort."
}
& $pythonExe -m streamlit run app.py --server.port $finalPort