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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Portrait Generator V4 - INSTALLER.ps1
|
| 2 |
+
# Installateur principal. Normalement lance via INSTALLER.bat.
|
| 3 |
+
|
| 4 |
+
$ErrorActionPreference = "Continue"
|
| 5 |
+
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
| 6 |
+
Set-Location $Root
|
| 7 |
+
$Log = Join-Path $Root "install_log.txt"
|
| 8 |
+
"Portrait Generator V4 - Installation $(Get-Date)" | Out-File $Log -Encoding UTF8
|
| 9 |
+
|
| 10 |
+
function Log($msg) {
|
| 11 |
+
$line = "[$(Get-Date -Format 'HH:mm:ss')] $msg"
|
| 12 |
+
Write-Host $line
|
| 13 |
+
Add-Content -Path $Log -Value $line -Encoding UTF8
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
function Ask-Choice($Title, $Choices, $Default) {
|
| 17 |
+
Write-Host ""
|
| 18 |
+
Write-Host $Title -ForegroundColor Cyan
|
| 19 |
+
foreach ($key in $Choices.Keys | Sort-Object) {
|
| 20 |
+
Write-Host " $key - $($Choices[$key])"
|
| 21 |
+
}
|
| 22 |
+
$answer = Read-Host "Votre choix [$Default]"
|
| 23 |
+
if ([string]::IsNullOrWhiteSpace($answer)) { $answer = $Default }
|
| 24 |
+
if (-not $Choices.ContainsKey($answer)) {
|
| 25 |
+
Write-Host "Choix invalide, utilisation de $Default" -ForegroundColor Yellow
|
| 26 |
+
$answer = $Default
|
| 27 |
+
}
|
| 28 |
+
return $answer
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function Test-ComfyAlive {
|
| 32 |
+
try {
|
| 33 |
+
Invoke-WebRequest -Uri 'http://127.0.0.1:8188/system_stats' -UseBasicParsing -TimeoutSec 2 | Out-Null
|
| 34 |
+
return $true
|
| 35 |
+
} catch { return $false }
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
Write-Host "============================================================" -ForegroundColor Magenta
|
| 39 |
+
Write-Host " Portrait Generator V4 - Installation" -ForegroundColor Magenta
|
| 40 |
+
Write-Host "============================================================" -ForegroundColor Magenta
|
| 41 |
+
Write-Host "Ce programme va verifier Python, GPU, ComfyUI, PyTorch et le modele."
|
| 42 |
+
Write-Host "Log detaille: $Log"
|
| 43 |
+
Write-Host ""
|
| 44 |
+
|
| 45 |
+
try {
|
| 46 |
+
# 1) Python
|
| 47 |
+
Log "Detection Python"
|
| 48 |
+
$PythonCmd = $null
|
| 49 |
+
$PythonVersion = $null
|
| 50 |
+
|
| 51 |
+
if (Get-Command python -ErrorAction SilentlyContinue) {
|
| 52 |
+
$PythonCmd = "python"
|
| 53 |
+
$PythonVersion = (& python --version 2>&1) -join " "
|
| 54 |
+
} elseif (Get-Command py -ErrorAction SilentlyContinue) {
|
| 55 |
+
$PythonCmd = "py -3"
|
| 56 |
+
$PythonVersion = (& py -3 --version 2>&1) -join " "
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
if ($PythonCmd) {
|
| 60 |
+
Write-Host "Python detecte: $PythonVersion via '$PythonCmd'" -ForegroundColor Green
|
| 61 |
+
Log "Python detecte: $PythonVersion via $PythonCmd"
|
| 62 |
+
} else {
|
| 63 |
+
Write-Host "Python n'a pas ete trouve." -ForegroundColor Yellow
|
| 64 |
+
Write-Host "Python 3.10+ est requis. L'installateur peut tenter de telecharger Python 3.12.8."
|
| 65 |
+
$installPy = Ask-Choice "Installer Python automatiquement ?" @{ "1"="Oui, installer Python 3.12.8"; "2"="Non, j'installerai Python moi-meme" } "1"
|
| 66 |
+
if ($installPy -eq "1") {
|
| 67 |
+
Log "Telechargement Python 3.12.8"
|
| 68 |
+
$pyInstaller = Join-Path $Root "python_installer.exe"
|
| 69 |
+
Invoke-WebRequest -Uri "https://www.python.org/ftp/python/3.12.8/python-3.12.8-amd64.exe" -OutFile $pyInstaller
|
| 70 |
+
Start-Process -FilePath $pyInstaller -ArgumentList "/quiet InstallAllUsers=0 PrependPath=1 Include_test=0" -Wait
|
| 71 |
+
if (Get-Command python -ErrorAction SilentlyContinue) {
|
| 72 |
+
$PythonCmd = "python"
|
| 73 |
+
$PythonVersion = (& python --version 2>&1) -join " "
|
| 74 |
+
Log "Python installe: $PythonVersion"
|
| 75 |
+
} else {
|
| 76 |
+
throw "Python installe mais pas encore detecte. Fermez cette fenetre et relancez INSTALLER.bat."
|
| 77 |
+
}
|
| 78 |
+
} else {
|
| 79 |
+
throw "Installation arretee. Installez Python 3.10+ puis relancez INSTALLER.bat."
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
# 2) Espace disque
|
| 84 |
+
Log "Verification espace disque"
|
| 85 |
+
$drive = (Get-Item -LiteralPath $Root).PSDrive
|
| 86 |
+
$freeGB = [math]::Round($drive.Free / 1GB, 1)
|
| 87 |
+
Write-Host "Espace libre sur le disque cible: $freeGB Go"
|
| 88 |
+
Log "Espace libre: $freeGB Go"
|
| 89 |
+
if ($freeGB -lt 20) {
|
| 90 |
+
Write-Host "ATTENTION: moins de 20 Go libres. Recommande: 20-30 Go." -ForegroundColor Yellow
|
| 91 |
+
Read-Host "Appuyez sur Entree pour continuer quand meme"
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
# 3) GPU / mode PyTorch
|
| 95 |
+
Log "Detection GPU"
|
| 96 |
+
$GpuDetected = $false
|
| 97 |
+
$GpuInfo = "CPU uniquement"
|
| 98 |
+
try {
|
| 99 |
+
$gpu = & nvidia-smi --query-gpu=name,memory.total,driver_version --format=csv,noheader 2>$null
|
| 100 |
+
if ($LASTEXITCODE -eq 0 -and $gpu) {
|
| 101 |
+
$GpuDetected = $true
|
| 102 |
+
$GpuInfo = $gpu
|
| 103 |
+
Write-Host "GPU NVIDIA detecte: $GpuInfo" -ForegroundColor Green
|
| 104 |
+
Log "GPU NVIDIA: $GpuInfo"
|
| 105 |
+
}
|
| 106 |
+
} catch {}
|
| 107 |
+
if (-not $GpuDetected) {
|
| 108 |
+
Write-Host "Aucun GPU NVIDIA detecte. Mode CPU possible mais tres lent." -ForegroundColor Yellow
|
| 109 |
+
Log "Aucun GPU NVIDIA detecte"
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
$torchChoices = @{
|
| 113 |
+
"1"="Auto recommande: CUDA 13.0 cu130 si NVIDIA, CPU sinon"
|
| 114 |
+
"2"="Forcer CUDA 13.0 cu130, recommande RTX 50 / RTX 40 recentes"
|
| 115 |
+
"3"="Forcer CPU, tres lent mais compatible sans NVIDIA"
|
| 116 |
+
"4"="Ne pas modifier PyTorch"
|
| 117 |
+
}
|
| 118 |
+
$torchChoice = Ask-Choice "Configuration PyTorch" $torchChoices "1"
|
| 119 |
+
|
| 120 |
+
# 4) ComfyUI
|
| 121 |
+
$comfyChoices = @{
|
| 122 |
+
"1"="Installer ComfyUI dans ce dossier, package autonome"
|
| 123 |
+
"2"="Utiliser ComfyUI existant: D:\IA\ComfyUI"
|
| 124 |
+
"3"="Entrer un chemin ComfyUI personnalise"
|
| 125 |
+
"4"="Ne pas installer ComfyUI, seulement installer l'application"
|
| 126 |
+
}
|
| 127 |
+
$comfyChoice = Ask-Choice "Configuration ComfyUI" $comfyChoices "1"
|
| 128 |
+
|
| 129 |
+
if ($comfyChoice -eq "2") { $ComfyDir = "D:\IA\ComfyUI" }
|
| 130 |
+
elseif ($comfyChoice -eq "3") { $ComfyDir = Read-Host "Chemin complet du dossier ComfyUI" }
|
| 131 |
+
else { $ComfyDir = Join-Path $Root "ComfyUI" }
|
| 132 |
+
$ComfyDir = [System.IO.Path]::GetFullPath($ComfyDir)
|
| 133 |
+
Log "COMFY_DIR=$ComfyDir"
|
| 134 |
+
|
| 135 |
+
"`$ComfyDir = '$ComfyDir'" | Out-File (Join-Path $Root "config_local.ps1") -Encoding UTF8
|
| 136 |
+
"set ""COMFY_DIR=$ComfyDir""" | Out-File (Join-Path $Root "config_local.bat") -Encoding ASCII
|
| 137 |
+
|
| 138 |
+
# 5) Venv + app deps
|
| 139 |
+
$Venv = Join-Path $Root "venv"
|
| 140 |
+
$PyExe = Join-Path $Venv "Scripts\python.exe"
|
| 141 |
+
$PipExe = Join-Path $Venv "Scripts\pip.exe"
|
| 142 |
+
|
| 143 |
+
if (-not (Test-Path $PyExe)) {
|
| 144 |
+
Log "Creation environnement virtuel"
|
| 145 |
+
if ($PythonCmd -eq "py -3") { & py -3 -m venv $Venv }
|
| 146 |
+
else { & python -m venv $Venv }
|
| 147 |
+
if ($LASTEXITCODE -ne 0) { throw "Creation de l'environnement virtuel echouee" }
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
Log "Mise a jour pip"
|
| 151 |
+
& $PyExe -m pip install --upgrade pip setuptools wheel | Tee-Object -FilePath $Log -Append
|
| 152 |
+
|
| 153 |
+
Log "Installation dependances application"
|
| 154 |
+
& $PipExe install gradio requests Pillow huggingface_hub | Tee-Object -FilePath $Log -Append
|
| 155 |
+
if ($LASTEXITCODE -ne 0) { throw "Installation dependances application echouee" }
|
| 156 |
+
|
| 157 |
+
# 6) ComfyUI download if requested
|
| 158 |
+
if ($comfyChoice -ne "4") {
|
| 159 |
+
$ComfyMain = Join-Path $ComfyDir "main.py"
|
| 160 |
+
if (-not (Test-Path $ComfyMain)) {
|
| 161 |
+
Write-Host "Telechargement ComfyUI..." -ForegroundColor Cyan
|
| 162 |
+
Log "Telechargement ComfyUI"
|
| 163 |
+
$zip = Join-Path $Root "ComfyUI.zip"
|
| 164 |
+
Invoke-WebRequest -Uri "https://github.com/comfyanonymous/ComfyUI/archive/refs/heads/master.zip" -OutFile $zip
|
| 165 |
+
$tmp = Join-Path $Root "_comfy_extract"
|
| 166 |
+
if (Test-Path $tmp) { Remove-Item $tmp -Recurse -Force }
|
| 167 |
+
Expand-Archive -Path $zip -DestinationPath $tmp -Force
|
| 168 |
+
$src = Join-Path $tmp "ComfyUI-master"
|
| 169 |
+
if (Test-Path $ComfyDir) { Remove-Item $ComfyDir -Recurse -Force }
|
| 170 |
+
New-Item -ItemType Directory -Path (Split-Path -Parent $ComfyDir) -Force | Out-Null
|
| 171 |
+
Move-Item -Path $src -Destination $ComfyDir -Force
|
| 172 |
+
Remove-Item $tmp -Recurse -Force
|
| 173 |
+
Remove-Item $zip -Force
|
| 174 |
+
} else {
|
| 175 |
+
Write-Host "ComfyUI trouve: $ComfyDir" -ForegroundColor Green
|
| 176 |
+
Log "ComfyUI deja present"
|
| 177 |
+
}
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
# 7) PyTorch
|
| 181 |
+
if ($torchChoice -ne "4") {
|
| 182 |
+
Log "Installation PyTorch"
|
| 183 |
+
& $PipExe uninstall -y torch torchvision torchaudio | Tee-Object -FilePath $Log -Append
|
| 184 |
+
$useCuda = $false
|
| 185 |
+
if ($torchChoice -eq "2") { $useCuda = $true }
|
| 186 |
+
elseif ($torchChoice -eq "1" -and $GpuDetected) { $useCuda = $true }
|
| 187 |
+
|
| 188 |
+
if ($useCuda) {
|
| 189 |
+
Write-Host "Installation PyTorch CUDA 13.0 cu130..." -ForegroundColor Cyan
|
| 190 |
+
& $PipExe install --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130 | Tee-Object -FilePath $Log -Append
|
| 191 |
+
if ($LASTEXITCODE -ne 0) {
|
| 192 |
+
Write-Host "cu130 stable echoue, tentative nightly cu130..." -ForegroundColor Yellow
|
| 193 |
+
& $PipExe install --pre --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu130 | Tee-Object -FilePath $Log -Append
|
| 194 |
+
}
|
| 195 |
+
} else {
|
| 196 |
+
Write-Host "Installation PyTorch CPU..." -ForegroundColor Cyan
|
| 197 |
+
& $PipExe install --upgrade torch torchvision torchaudio | Tee-Object -FilePath $Log -Append
|
| 198 |
+
}
|
| 199 |
+
if ($LASTEXITCODE -ne 0) { throw "Installation PyTorch echouee" }
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
Log "Verification PyTorch"
|
| 203 |
+
& $PyExe -c "import torch; print('TORCH', torch.__version__); print('CUDA', torch.version.cuda); print('CUDA_AVAILABLE', torch.cuda.is_available()); print('GPU', torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'CPU'); print('ARCH', torch.cuda.get_arch_list() if torch.cuda.is_available() else 'CPU')" | Tee-Object -FilePath $Log -Append
|
| 204 |
+
|
| 205 |
+
# 8) Comfy requirements
|
| 206 |
+
$Req = Join-Path $ComfyDir "requirements.txt"
|
| 207 |
+
if (($comfyChoice -ne "4") -and (Test-Path $Req)) {
|
| 208 |
+
Log "Installation requirements ComfyUI"
|
| 209 |
+
& $PipExe install -r $Req | Tee-Object -FilePath $Log -Append
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
# 9) Model
|
| 213 |
+
if ($comfyChoice -ne "4") {
|
| 214 |
+
$modelChoice = Ask-Choice "Modele JuggernautXL Ragnarok" @{ "1"="Telecharger/verifier le modele, environ 6.6 Go"; "2"="Ne pas telecharger maintenant" } "1"
|
| 215 |
+
if ($modelChoice -eq "1") {
|
| 216 |
+
$ModelDir = Join-Path $ComfyDir "models\checkpoints"
|
| 217 |
+
$ModelFile = Join-Path $ModelDir "juggernautXL_ragnarokBy.safetensors"
|
| 218 |
+
New-Item -ItemType Directory -Path $ModelDir -Force | Out-Null
|
| 219 |
+
if (Test-Path $ModelFile) {
|
| 220 |
+
Write-Host "Modele deja present: $ModelFile" -ForegroundColor Green
|
| 221 |
+
Log "Modele deja present"
|
| 222 |
+
} else {
|
| 223 |
+
Write-Host "Telechargement du modele environ 6.6 Go..." -ForegroundColor Cyan
|
| 224 |
+
& $PyExe -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='maxborland/juggernautXL_ragnarokBy.safetensors', filename='juggernautXL_ragnarokBy.safetensors', local_dir=r'$ModelDir', local_dir_use_symlinks=False); print('Modele telecharge')" | Tee-Object -FilePath $Log -Append
|
| 225 |
+
if ($LASTEXITCODE -ne 0) { Write-Host "Modele non telecharge. Placez-le manuellement ici: $ModelFile" -ForegroundColor Yellow }
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
# 10) Summary
|
| 231 |
+
Log "Installation terminee"
|
| 232 |
+
Write-Host ""
|
| 233 |
+
Write-Host "============================================================" -ForegroundColor Green
|
| 234 |
+
Write-Host "Installation terminee" -ForegroundColor Green
|
| 235 |
+
Write-Host "Python : $PythonVersion"
|
| 236 |
+
Write-Host "GPU : $GpuInfo"
|
| 237 |
+
Write-Host "ComfyUI: $ComfyDir"
|
| 238 |
+
Write-Host "Log : $Log"
|
| 239 |
+
Write-Host "Lancement: LANCER.bat" -ForegroundColor Green
|
| 240 |
+
Write-Host "============================================================" -ForegroundColor Green
|
| 241 |
+
}
|
| 242 |
+
catch {
|
| 243 |
+
Log "ERREUR FATALE: $($_.Exception.Message)"
|
| 244 |
+
Write-Host "ERREUR: $($_.Exception.Message)" -ForegroundColor Red
|
| 245 |
+
Write-Host "Voir le log: $Log" -ForegroundColor Yellow
|
| 246 |
+
}
|
| 247 |
+
|
| 248 |
+
Read-Host "Appuyez sur Entree pour fermer"
|