GAD-Research-Lab/MedicalAI-Light-Weight
014
1<#2.SYNOPSIS3 One-click launcher for MedicalAI - Light Weight4.DESCRIPTION5 Checks for Python, sets up venv, installs deps, and launches the app.6 Double-click this file or run: powershell -File launch.ps17#>8 9$ErrorActionPreference = "Stop"10$ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path11Set-Location $ProjectRoot12 13$Host.UI.RawUI.WindowTitle = "MedicalAI - Light Weight"14 15# ── Check Python ──16$python = $null17foreach ($cmd in @("python", "python3", "py")) {18 try {19 $v = & $cmd --version 2>&120 if ($v -match "Python 3\.(1[0-9]|[0-9]+)") {21 $python = $cmd22 break23 }24 } catch {}25}26if (-not $python) {27 Write-Host "Python 3.10+ is required but not found." -ForegroundColor Red28 Write-Host "Download from: https://www.python.org/downloads/" -ForegroundColor Yellow29 Write-Host "Make sure to check 'Add Python to PATH' during installation." -ForegroundColor Yellow30 Read-Host "Press Enter to exit"31 exit 132}33Write-Host "Using: $(& $python --version)" -ForegroundColor Green34 35# ── Virtual Environment ──36$venvPath = Join-Path $ProjectRoot ".venv"37if (-not (Test-Path $venvPath)) {38 Write-Host "Creating virtual environment..." -ForegroundColor Cyan39 & $python -m venv $venvPath40 if (-not $?) { throw "Failed to create venv" }41}42 43# ── Activate ──44$activate = Join-Path $venvPath "Scripts\Activate.ps1"45. $activate46 47# ── Install Dependencies ──48$reqPath = Join-Path $ProjectRoot "requirements.txt"49if (Test-Path $reqPath) {50 Write-Host "Installing dependencies..." -ForegroundColor Cyan51 pip install -q -r $reqPath 2>&1 | Out-Null52 if (-not $?) {53 Write-Host "Retrying with full output..." -ForegroundColor Yellow54 pip install -r $reqPath55 }56}57 58# ── Check / Generate Default Models ──59$defaultClassifier = Join-Path $ProjectRoot "models\default\fusion_classifier.onnx"60$checkpoint = Join-Path $ProjectRoot "checkpoints\fusion_model.pth"61$onnxFull = Join-Path $ProjectRoot "checkpoints\onnx_full\fusion_full.onnx"62 63if ((-not (Test-Path $checkpoint)) -and (-not (Test-Path $onnxFull)) -and (-not (Test-Path $defaultClassifier))) {64 Write-Host "No models found. Generating default models..." -ForegroundColor Yellow65 python setup_default.py66 Write-Host "Default models generated. The app will work immediately." -ForegroundColor Green67}68 69if (Test-Path $checkpoint) {70 Write-Host "Trained model found." -ForegroundColor Green71} elseif (Test-Path $onnxFull) {72 Write-Host "ONNX pipeline found." -ForegroundColor Green73} elseif (Test-Path $defaultClassifier) {74 Write-Host "Default model found. Train a proper model for accurate results." -ForegroundColor Yellow75}76 77# ── Ask how to launch ──78Write-Host ""79Write-Host "MedicalAI - Light Weight" -ForegroundColor Cyan80Write-Host "========================" -ForegroundColor Cyan81Write-Host "1) Web UI (recommended - opens in browser)"82Write-Host "2) Command-line interface (CLI)"83Write-Host "3) API Server (for website/app integration)"84Write-Host ""85 86$choice = Read-Host "Select (1, 2, or 3)"87 88if ($choice -eq "2") {89 Write-Host "Launching CLI..." -ForegroundColor Green90 python run.py91} elseif ($choice -eq "3") {92 # Ensure API deps are installed93 try {94 Import-Module python -ErrorAction Stop95 python -c "import fastapi" 2>$null96 } catch {97 Write-Host "Installing API dependencies..." -ForegroundColor Cyan98 python -m pip install "fastapi[standard]" uvicorn 2>&1 | Out-Null99 }100 Write-Host "Launching API server on http://127.0.0.1:8000 ..." -ForegroundColor Green101 Write-Host "Your website can connect to: http://127.0.0.1:8000/api" -ForegroundColor Yellow102 python quantization.py --mode serve-api103} else {104 Write-Host "Launching web UI..." -ForegroundColor Green105 python web_ui.py106}107 108# ── Keep window open on crash ──109if (-not $?) {110 Write-Host "App exited with error. Press Enter to close." -ForegroundColor Red111 Read-Host112}113 