-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
189 lines (173 loc) · 6.45 KB
/
install.ps1
File metadata and controls
189 lines (173 loc) · 6.45 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
param(
[switch]$SkipDependencies,
[switch]$NoGPU,
[switch]$DownloadModels,
[switch]$DownloadDiarizationModels,
[switch]$SkipDiarization,
[switch]$ForceNonAdmin,
[string]$HuggingFaceToken,
[switch]$NoSmoke,
[switch]$Help
)
$ErrorActionPreference = "Stop"
$ScriptRoot = $PSScriptRoot
if (-not $ScriptRoot) {
try { $ScriptRoot = Split-Path -Parent $PSCommandPath } catch {}
}
if (-not $ScriptRoot) {
try { $ScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path } catch {}
}
if (-not $ScriptRoot) { $ScriptRoot = (Get-Location).Path }
function Write-ColorOutput {
param([string]$Message,[ConsoleColor]$Color=[ConsoleColor]::White)
$prev = $Host.UI.RawUI.ForegroundColor
$Host.UI.RawUI.ForegroundColor = $Color
Write-Host $Message
$Host.UI.RawUI.ForegroundColor = $prev
}
function Show-Help {
Write-Host "USAGE: .\install.ps1 [options]"
Write-Host "-SkipDependencies Skip system dependency installation"
Write-Host "-NoGPU Force CPU-only PyTorch installation"
Write-Host "-DownloadModels Download and warm up base Whisper models"
Write-Host "-DownloadDiarizationModels Download diarization models (pyannote)"
Write-Host "-SkipDiarization Skip diarization setup"
Write-Host "-ForceNonAdmin Allow running without Administrator privileges"
Write-Host "-HuggingFaceToken <token> HuggingFace token for pyannote.audio"
Write-Host "-NoSmoke Disable quick smoke tests"
Write-Host "-Help Show this help"
}
if ($Help) { Show-Help; exit 0 }
function Test-IsAdmin {
([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
function Invoke-PythonScript {
param([Parameter(Mandatory=$true)][string]$Code,[switch]$IgnoreExitCode)
$tmp = [System.IO.Path]::GetTempFileName()
Set-Content -Path $tmp -Value $Code -Encoding UTF8
& python $tmp
$rc = $LASTEXITCODE
Remove-Item $tmp -Force
if (-not $IgnoreExitCode -and $rc -ne 0) { throw "Python exited with code $rc" }
return $rc
}
function Resolve-Python {
$cmd = Get-Command python -ErrorAction SilentlyContinue
if (-not $cmd) { return $null }
$ver = & python -c "import sys;print(sys.version.split()[0])"
[pscustomobject]@{ exe = $cmd.Source; ver = $ver }
}
function Ensure-Venv {
$venvPath = Join-Path $ScriptRoot ".venv"
if (-not (Test-Path $venvPath)) { & python -m venv "$venvPath" }
$activate = Join-Path $venvPath "Scripts\Activate.ps1"
. $activate
& python -m pip install --upgrade pip wheel setuptools
}
function Install-PyTorch {
if ($NoGPU) {
Write-ColorOutput "Installing PyTorch (CPU-only)" ([ConsoleColor]::Yellow)
& python -m pip install --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
return
}
$hasNvidia = $false
if (Get-Command nvidia-smi -ErrorAction SilentlyContinue) {
try { & nvidia-smi | Out-Null; $hasNvidia = $LASTEXITCODE -eq 0 } catch { $hasNvidia = $false }
}
if ($hasNvidia) {
Write-ColorOutput "NVIDIA GPU detected: installing CUDA build" ([ConsoleColor]::Green)
try {
& python -m pip install --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
} catch {
Write-ColorOutput "Falling back to CPU-only build" ([ConsoleColor]::Yellow)
& python -m pip install --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
}
} else {
Write-ColorOutput "No GPU detected: installing CPU-only build" ([ConsoleColor]::Yellow)
& python -m pip install --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
}
}
function Install-ProjectRequirements {
$req = Join-Path $ScriptRoot "requirements.txt"
if (Test-Path -Path $req) {
Write-ColorOutput "Installing requirements.txt" ([ConsoleColor]::Yellow)
& python -m pip install -r $req
}
}
function Install-WhisperAndModels {
$needWhisper = Invoke-PythonScript -Code 'import importlib,sys;sys.exit(0 if importlib.util.find_spec("whisper") else 1)' -IgnoreExitCode
if ($needWhisper -ne 0) {
Write-ColorOutput "Installing openai-whisper" ([ConsoleColor]::Yellow)
& python -m pip install openai-whisper
}
if ($DownloadModels) {
Write-ColorOutput "Warming up Whisper base model" ([ConsoleColor]::Yellow)
Invoke-PythonScript -Code 'import whisper; whisper.load_model("base")'
}
}
function Install-Diarization {
if ($SkipDiarization) { return }
Write-ColorOutput "Installing pyannote.audio" ([ConsoleColor]::Yellow)
& python -m pip install "pyannote.audio>=3.0"
if ($HuggingFaceToken) { $env:HUGGING_FACE_HUB_TOKEN = $HuggingFaceToken }
if ($DownloadDiarizationModels -or $HuggingFaceToken) {
Invoke-PythonScript -Code @'
import os
try:
from huggingface_hub import login
tok = os.environ.get("HUGGING_FACE_HUB_TOKEN")
if tok:
login(token=tok, add_to_git_credential=False)
except Exception:
pass
'@
}
}
function Run-Smoke {
if ($NoSmoke) {
Write-ColorOutput "Smoke tests disabled (--NoSmoke)" ([ConsoleColor]::Yellow)
return
}
Write-ColorOutput "Running smoke tests" ([ConsoleColor]::Yellow)
Invoke-PythonScript -Code @'
import importlib, sys
ok = True
try:
import torch
_ = torch.cuda.is_available()
except Exception:
ok = False
try:
m = None
for name in ("whisper","faster_whisper"):
if importlib.util.find_spec(name):
m = name
break
if m is None:
ok = False
except Exception:
ok = False
print("OK" if ok else "FAIL")
sys.exit(0 if ok else 1)
'@
}
function Main {
if (-not $ForceNonAdmin -and -not (Test-IsAdmin)) {
Write-ColorOutput "Run PowerShell as Administrator or pass -ForceNonAdmin" ([ConsoleColor]::Red)
exit 1
}
$py = Resolve-Python
if (-not $py) {
Write-ColorOutput "Python not found in PATH" ([ConsoleColor]::Red)
exit 1
}
Ensure-Venv
if (-not $SkipDependencies) { Install-PyTorch }
Install-ProjectRequirements
Install-WhisperAndModels
Install-Diarization
Run-Smoke
Write-ColorOutput "Installation completed" ([ConsoleColor]::Green)
}
Main