| [CmdletBinding()]
|
| param(
|
| [int]$AppPort = 7860,
|
| [int]$LlamaPort = 8080,
|
| [switch]$NoShare
|
| )
|
|
|
| $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
|
| $venv = Join-Path $repoRoot ".venv\Scripts\python.exe"
|
|
|
| Write-Host ""
|
| Write-Host "=== The Tower Learns You ===" -ForegroundColor Cyan
|
| Write-Host ""
|
|
|
|
|
| $env:MODEL_BACKEND = "mock"
|
|
|
| try {
|
| $pidPath = Join-Path $repoRoot ".local\llama.cpp\server.pid"
|
| $llamaRunning = $false
|
| if (Test-Path $pidPath) {
|
| try {
|
| $recorded = (Get-Content $pidPath -Raw).Trim()
|
| if ($recorded -and (Get-Process -Id ([int]$recorded) -ErrorAction SilentlyContinue)) {
|
| Write-Host "[llama-server] Already running (PID $recorded) — skipping start." -ForegroundColor Green
|
| $llamaRunning = $true
|
| }
|
| } catch {
|
| Write-Warning "[llama-server] Could not read PID file: $_"
|
| }
|
| }
|
|
|
| if (-not $llamaRunning) {
|
| Write-Host "[llama-server] Starting on port $LlamaPort..." -ForegroundColor Yellow
|
| $ErrorActionPreference = "Stop"
|
| & (Join-Path $PSScriptRoot "Start-LlamaServer.ps1") -Port $LlamaPort
|
| Write-Host "[llama-server] Ready." -ForegroundColor Green
|
| }
|
|
|
| $env:MODEL_BACKEND = "local_openai"
|
| Write-Host "[backend] Local AI active (llama.cpp)" -ForegroundColor Green
|
| } catch {
|
| Write-Warning "[llama-server] $_"
|
| Write-Warning "[backend] Falling back to mock AI mode."
|
| }
|
|
|
| Write-Host ""
|
|
|
|
|
| Write-Host "[gradio] Starting on http://127.0.0.1:$AppPort (MODEL_BACKEND=$($env:MODEL_BACKEND))" -ForegroundColor Yellow
|
| if (-not $NoShare) {
|
| Write-Host "[gradio] Public share link will be printed below." -ForegroundColor DarkGray
|
| }
|
| Write-Host ""
|
|
|
| $env:GRADIO_SERVER_PORT = "$AppPort"
|
|
|
| try {
|
| Set-Location $repoRoot
|
| & $venv app.py
|
| } finally {
|
| $env:MODEL_BACKEND = $null
|
| $env:GRADIO_SERVER_PORT = $null
|
| }
|
|
|