Skip to content

Commit 7d7f577

Browse files
committed
feat: uses UV py management for frontend installer
1 parent caf72cc commit 7d7f577

File tree

1 file changed

+51
-73
lines changed

1 file changed

+51
-73
lines changed

Setup/setup_frontend.ps1

Lines changed: 51 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99
# 1. Install LM Studio from https://lmstudio.ai
1010
# 2. Download model: meta-llama-3.1-8b-instruct
1111
# 3. Start the local server in LM Studio (port 1234)
12+
#
13+
# This script installs uv, which manages Python 3.12 and all dependencies
14+
# automatically. No manual Python installation required.
1215
# =============================================================================
1316

14-
$MIN_PYTHON_MAJOR = 3
15-
$MIN_PYTHON_MINOR = 10
16-
$INSTALL_DIR = "C:\Program Files\Speech-to-Cobot"
17-
$ZIP_URL = "https://github.com/Meisdy/Speech-to-Code-Generation-for-Collaborative-Robots/archive/refs/heads/dev.zip"
18-
$ZIP_PATH = "$env:TEMP\speech-to-cobot.zip"
19-
$EXTRACT_PATH = "$env:TEMP\speech-to-cobot-extract"
20-
$VENV_DIR = "$INSTALL_DIR\venv_frontend"
21-
$REQUIREMENTS = "$INSTALL_DIR\Setup\requirements_frontend.txt"
22-
$LM_STUDIO_URL = "http://localhost:1234/v1/models"
23-
$WHISPER_CACHE = "$env:USERPROFILE\.cache\whisper"
17+
$INSTALL_DIR = "C:\Program Files\Speech-to-Cobot"
18+
$ZIP_URL = "https://github.com/Meisdy/Speech-to-Code-Generation-for-Collaborative-Robots/archive/refs/heads/dev.zip"
19+
$ZIP_PATH = "$env:TEMP\speech-to-cobot.zip"
20+
$EXTRACT_PATH = "$env:TEMP\speech-to-cobot-extract"
21+
$LM_STUDIO_URL = "http://localhost:1234/v1/models"
22+
$WHISPER_CACHE = "$env:USERPROFILE\.cache\whisper"
2423

2524
function Write-Step { param([string]$msg) Write-Host "`n[SETUP] $msg" -ForegroundColor Cyan }
2625
function Write-OK { param([string]$msg) Write-Host " [OK] $msg" -ForegroundColor Green }
@@ -61,43 +60,43 @@ if (-not (Get-Command winget -ErrorAction SilentlyContinue)) {
6160
}
6261
Write-OK "winget available"
6362

64-
# --- Python -------------------------------------------------------------------
65-
66-
Write-Step "Checking Python (minimum $MIN_PYTHON_MAJOR.$MIN_PYTHON_MINOR)"
67-
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
68-
Write-Fail "Python not found. Install Python $MIN_PYTHON_MAJOR.$MIN_PYTHON_MINOR+ from https://python.org and add to PATH."
69-
}
70-
71-
$version = & python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')"
72-
$parts = $version.Split(".")
73-
$major = [int]$parts[0]
74-
$minor = [int]$parts[1]
75-
76-
if ($major -lt $MIN_PYTHON_MAJOR -or ($major -eq $MIN_PYTHON_MAJOR -and $minor -lt $MIN_PYTHON_MINOR)) {
77-
Write-Fail "Python $version found but $MIN_PYTHON_MAJOR.$MIN_PYTHON_MINOR+ required. Install from https://python.org"
78-
}
79-
Write-OK "Python $version"
80-
8163
# --- ffmpeg -------------------------------------------------------------------
8264
# Check PATH first — instant. Only call winget if ffmpeg is genuinely missing.
83-
# winget output is shown directly so the user sees exactly what is happening.
8465

8566
Write-Step "Checking ffmpeg (required by Whisper)"
86-
$ffmpegPath = Get-Command ffmpeg -ErrorAction SilentlyContinue
87-
if ($ffmpegPath) {
88-
Write-OK "ffmpeg found at $($ffmpegPath.Source)"
67+
if (Get-Command ffmpeg -ErrorAction SilentlyContinue) {
68+
Write-OK "ffmpeg found at $((Get-Command ffmpeg).Source)"
8969
} else {
90-
Write-Host " ffmpeg not found on PATH — installing via winget..." -ForegroundColor Gray
70+
Write-Host " ffmpeg not on PATH — installing via winget..." -ForegroundColor Gray
9171
winget install -e --id Gyan.FFmpeg --accept-source-agreements --accept-package-agreements
9272
if ($LASTEXITCODE -ne 0) {
9373
Write-Fail "ffmpeg install failed. Install manually from https://ffmpeg.org, add to PATH, then re-run."
9474
}
95-
# Refresh PATH so ffmpeg is immediately available in this session
75+
# Refresh PATH so ffmpeg is available in this session without a restart
9676
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" +
9777
[System.Environment]::GetEnvironmentVariable("PATH", "User")
9878
Write-OK "ffmpeg installed"
9979
}
10080

81+
# --- uv -----------------------------------------------------------------------
82+
# uv manages Python version and dependencies — no manual Python install needed.
83+
# It installs Python 3.12 if missing and creates an isolated .venv in the
84+
# project directory.
85+
86+
Write-Step "Checking uv"
87+
if (Get-Command uv -ErrorAction SilentlyContinue) {
88+
Write-OK "uv found at $((Get-Command uv).Source)"
89+
} else {
90+
Write-Host " uv not found — installing via winget..." -ForegroundColor Gray
91+
winget install --id astral-sh.uv -e --accept-source-agreements --accept-package-agreements
92+
if ($LASTEXITCODE -ne 0) {
93+
Write-Fail "uv install failed."
94+
}
95+
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" +
96+
[System.Environment]::GetEnvironmentVariable("PATH", "User")
97+
Write-OK "uv installed"
98+
}
99+
101100
# --- Download repository ------------------------------------------------------
102101
# Uses curl.exe (built into Windows 11) for native progress output.
103102
# GitHub ZIPs extract to a single subfolder named <repo>-<branch> — we rename it.
@@ -125,59 +124,38 @@ if (Test-Path $INSTALL_DIR) {
125124
}
126125
Move-Item -Path $extractedFolder.FullName -Destination $INSTALL_DIR
127126
} finally {
128-
# Always clean up temp files regardless of success or failure
129127
if (Test-Path $ZIP_PATH) { Remove-Item -Force $ZIP_PATH }
130128
if (Test-Path $EXTRACT_PATH) { Remove-Item -Recurse -Force $EXTRACT_PATH }
131129
}
132-
133130
$elapsed = [math]::Round(((Get-Date) - $stepStart).TotalSeconds, 1)
134131
Write-OK "Repository ready at $INSTALL_DIR ($elapsed s)"
135132
}
136133

137-
# --- Virtual environment ------------------------------------------------------
138-
139-
Write-Step "Creating virtual environment"
140-
if (Test-Path $VENV_DIR) {
141-
Write-Warn "Virtual environment already exists — skipping. Delete $VENV_DIR to force a fresh install."
142-
} else {
143-
$stepStart = Get-Date
144-
python -m venv $VENV_DIR
145-
$elapsed = [math]::Round(((Get-Date) - $stepStart).TotalSeconds, 1)
146-
Write-OK "Virtual environment created ($elapsed s)"
147-
}
134+
# --- Install Python and dependencies via uv -----------------------------------
135+
# uv reads pyproject.toml at the repo root, installs Python 3.12 if needed,
136+
# creates .venv inside the project directory, and installs all dependencies.
137+
# Nothing outside the project directory or uv's own cache is modified.
148138

149-
# --- Python dependencies ------------------------------------------------------
150-
# pip upgrade is suppressed — it is an internal detail, not relevant to the user.
151-
# Package install output is shown directly so each download is visible.
152-
153-
Write-Step "Installing Python dependencies"
154-
if (-not (Test-Path $REQUIREMENTS)) {
155-
Write-Fail "$REQUIREMENTS not found. Repository structure may be unexpected — check $INSTALL_DIR."
156-
}
157-
158-
$pip = "$VENV_DIR\Scripts\pip.exe"
139+
Write-Step "Installing Python 3.12 and frontend dependencies via uv"
159140
$stepStart = Get-Date
160-
161-
& $pip install --upgrade pip --quiet
162-
Write-Host " Installing packages from requirements_frontend.txt..." -ForegroundColor Gray
163-
& $pip install -r $REQUIREMENTS
141+
Set-Location $INSTALL_DIR
142+
uv sync --only-group frontend
164143
if ($LASTEXITCODE -ne 0) {
165-
Write-Fail "pip install failed — see output above."
144+
Write-Fail "uv sync failed — see output above."
166145
}
167-
168146
$elapsed = [math]::Round(((Get-Date) - $stepStart).TotalSeconds, 1)
169-
Write-OK "Python dependencies installed ($elapsed s)"
147+
Write-OK "Python 3.12 and all dependencies installed ($elapsed s)"
170148

171149
# --- Whisper model ------------------------------------------------------------
172-
# Downloads ~140 MB to %USERPROFILE%\.cache\whisper — outside the install folder.
173-
# This is Whisper's standard cache location. cleanup_frontend.ps1 removes it.
150+
# Pre-downloads the model so the first launch does not stall.
151+
# Saved to %USERPROFILE%\.cache\whisper — outside the project directory.
152+
# cleanup_frontend.ps1 removes this.
174153

175154
Write-Step "Pre-downloading Whisper base model (~140 MB)"
176155
Write-Host " Model will be saved to $WHISPER_CACHE" -ForegroundColor Gray
177-
Write-Warn "This location is outside the install folder. Run cleanup_frontend.ps1 to remove it."
178-
$python = "$VENV_DIR\Scripts\python.exe"
156+
Write-Warn "This is outside the project directory. Run cleanup_frontend.ps1 to remove it."
179157
$stepStart = Get-Date
180-
& $python -c "import whisper; whisper.load_model('base')"
158+
uv run python -c "import whisper; whisper.load_model('base')"
181159
if ($LASTEXITCODE -ne 0) {
182160
Write-Warn "Whisper model pre-download failed — it will download on first application launch instead."
183161
} else {
@@ -186,16 +164,16 @@ if ($LASTEXITCODE -ne 0) {
186164
}
187165

188166
# --- LM Studio check ----------------------------------------------------------
189-
# Does not install LM Studio — that must be done manually.
167+
# Does not install LM Studio — that must be done manually (see prerequisites).
190168
# Only checks whether the API server is already running.
191169

192170
Write-Step "Checking LM Studio server ($LM_STUDIO_URL)"
193171
try {
194172
Invoke-WebRequest -Uri $LM_STUDIO_URL -UseBasicParsing -TimeoutSec 5 | Out-Null
195173
Write-OK "LM Studio server reachable"
196174
} catch {
197-
Write-Warn "LM Studio server not reachable — this is expected if you have not started it yet."
198-
Write-Warn "Before running the app: open LM Studio, load meta-llama-3.1-8b-instruct, and start the server."
175+
Write-Warn "LM Studio server not reachable — expected if not started yet."
176+
Write-Warn "Before running: open LM Studio, load meta-llama-3.1-8b-instruct, start the server."
199177
}
200178

201179
# --- Done ---------------------------------------------------------------------
@@ -204,8 +182,8 @@ Write-Host ""
204182
Write-Host "=====================================================" -ForegroundColor Green
205183
Write-Host " Setup complete. Installed to:" -ForegroundColor Green
206184
Write-Host " $INSTALL_DIR" -ForegroundColor White
207-
Write-Host "" -ForegroundColor Green
185+
Write-Host ""
208186
Write-Host " To launch the application:" -ForegroundColor Green
209187
Write-Host " cd '$INSTALL_DIR'" -ForegroundColor White
210-
Write-Host " '$VENV_DIR\Scripts\python.exe' -m Frontend.main" -ForegroundColor White
188+
Write-Host " uv run python -m Frontend.main" -ForegroundColor White
211189
Write-Host "=====================================================" -ForegroundColor Green

0 commit comments

Comments
 (0)