UmeAiRT commited on
Commit
a73d303
·
verified ·
1 Parent(s): 8d6d7c0

Upload Download-FLUX-Models.ps1

Browse files
scripts/Model_downloader/Download-FLUX-Models.ps1 ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <#
2
+ .SYNOPSIS
3
+ A PowerShell script to interactively download FLUX models for ComfyUI.
4
+ .DESCRIPTION
5
+ This script replaces the UmeAiRT-Model_downloader-FLUX-Auto.bat file.
6
+ It provides a series of prompts to the user to select which specific FLUX models
7
+ they wish to download, then downloads them using the provided helper functions.
8
+ #>
9
+
10
+ #===========================================================================
11
+ # SECTION 1: HELPER FUNCTIONS & SETUP
12
+ #===========================================================================
13
+
14
+ # --- Helper function to write to console and log file ---
15
+ function Write-Log {
16
+ param([string]$Message, [string]$Color = "White")
17
+ $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
18
+ # Note: Log file path assumes it's run from the main installer's directory
19
+ $logFile = Join-Path $PSScriptRoot "logs\install_log.txt"
20
+ $formattedMessage = "[$timestamp] [ModelDownloader] $Message"
21
+ Write-Host $Message -ForegroundColor $Color
22
+ Add-Content -Path $logFile -Value $formattedMessage
23
+ }
24
+
25
+ # --- Helper function to execute a command and log its output ---
26
+ function Invoke-AndLog {
27
+ param([string]$File, [string]$Arguments)
28
+ $logFile = Join-Path $PSScriptRoot "logs\install_log.txt"
29
+ $commandToRun = "`"$File`" $Arguments"
30
+ $cmdArguments = "/C `"$commandToRun >> `"`"$logFile`"`" 2>&1`""
31
+ try {
32
+ Start-Process -FilePath "cmd.exe" -ArgumentList $cmdArguments -Wait -WindowStyle Hidden
33
+ } catch {
34
+ Write-Log "FATAL ERROR trying to execute command: $commandToRun" -Color Red
35
+ }
36
+ }
37
+
38
+ # --- Smart Download Function ---
39
+ function Download-File {
40
+ param(
41
+ [string]$Uri,
42
+ [string]$OutFile
43
+ )
44
+
45
+ # Vérifie si le fichier de destination existe déjà
46
+ if (Test-Path $OutFile) {
47
+ Write-Log "Skipping: $((Split-Path $OutFile -Leaf)) (already exists)." -Color Gray
48
+ } else {
49
+ # Si le fichier n'existe pas, on procède au téléchargement
50
+ $fileName = Split-Path -Path $Uri -Leaf
51
+
52
+ if (Get-Command 'aria2c' -ErrorAction SilentlyContinue) {
53
+ Write-Log "Downloading: $fileName"
54
+ $aria_args = "-c -x 16 -s 16 -k 1M --dir=`"$((Split-Path $OutFile -Parent))`" --out=`"$((Split-Path $OutFile -Leaf))`" `"$Uri`""
55
+ Invoke-AndLog "aria2c" $aria_args
56
+ } else {
57
+ Write-Log "Aria2 not found. Falling back to standard download: $fileName" -Color Yellow
58
+ Invoke-WebRequest -Uri $Uri -OutFile $OutFile
59
+ }
60
+ }
61
+ }
62
+
63
+ # --- Function to ask a multiple choice question ---
64
+ function Ask-Question {
65
+ param(
66
+ [string]$Prompt,
67
+ [string[]]$Choices,
68
+ [string[]]$ValidAnswers
69
+ )
70
+ $choice = ''
71
+ while ($choice -notin $ValidAnswers) {
72
+ Write-Log "`n$Prompt" -Color Yellow
73
+ foreach ($line in $Choices) {
74
+ Write-Host " $line" -ForegroundColor Green
75
+ }
76
+ $choice = (Read-Host "Enter your choice and press Enter").ToUpper()
77
+ if ($choice -notin $ValidAnswers) {
78
+ Write-Log "Invalid choice. Please try again." -Color Red
79
+ }
80
+ }
81
+ return $choice
82
+ }
83
+
84
+ #===========================================================================
85
+ # SECTION 2: SCRIPT EXECUTION
86
+ #===========================================================================
87
+
88
+ # --- Path Detection ---
89
+ $installPath = $PSScriptRoot
90
+ $basePath = Join-Path $installPath "ComfyUI_windows_portable"
91
+ if (-not (Test-Path $basePath)) {
92
+ $basePath = $installPath
93
+ }
94
+ $modelsPath = Join-Path $basePath "ComfyUI\models"
95
+ if (-not (Test-Path $modelsPath)) {
96
+ Write-Log "Could not find ComfyUI models path. Exiting." -Color Red
97
+ Read-Host "Press Enter to exit."
98
+ exit
99
+ }
100
+
101
+ # --- NOUVEAU : Détection du GPU avant les questions ---
102
+ Write-Log "-------------------------------------------------------------------------------"
103
+ Write-Log "Checking for NVIDIA GPU to provide model recommendations..." -Color Yellow
104
+ if (Get-Command 'nvidia-smi' -ErrorAction SilentlyContinue) {
105
+ try {
106
+ $gpuInfoCsv = nvidia-smi --query-gpu=name,memory.total --format=csv,noheader
107
+ if ($gpuInfoCsv) {
108
+ $gpuInfoParts = $gpuInfoCsv.Split(',')
109
+ $gpuName = $gpuInfoParts[0].Trim()
110
+ $gpuMemoryMiB = ($gpuInfoParts[1] -replace ' MiB').Trim()
111
+ $gpuMemoryGiB = [math]::Round([int]$gpuMemoryMiB / 1024)
112
+
113
+ Write-Log "GPU : $gpuName" -Color Green
114
+ Write-Log "VRAM : $gpuMemoryGiB GB" -Color Green
115
+
116
+ if ($gpuMemoryGiB -ge 30) {
117
+ Write-Log "Recommandation: fp16" -Color Cyan
118
+ } elseif ($gpuMemoryGiB -ge 18) {
119
+ Write-Log "Recommandation: fp8 or GGUF Q8" -Color Cyan
120
+ } elseif ($gpuMemoryGiB -ge 14) {
121
+ Write-Log "Recommandation: GGUF Q6" -Color Cyan
122
+ }elseif ($gpuMemoryGiB -ge 12) {
123
+ Write-Log "Recommandation: GGUF Q5" -Color Cyan
124
+ }elseif ($gpuMemoryGiB -ge 10) {
125
+ Write-Log "Recommandation: GGUF Q4" -Color Cyan
126
+ }elseif ($gpuMemoryGiB -ge 8) {
127
+ Write-Log "Recommandation: GGUF Q3" -Color Cyan
128
+ }else {
129
+ Write-Log "Recommandation: GGUF Q2" -Color Cyan
130
+ }
131
+ }
132
+ } catch {
133
+ Write-Log "Impossible de récupérer les informations GPU. Erreur: $($_.Exception.Message)" -Color Red
134
+ }
135
+ } else {
136
+ Write-Log "Aucun GPU NVIDIA detecte (nvidia-smi introuvable). Choisissez selon votre matériel." -Color Gray
137
+ }
138
+ Write-Log "-------------------------------------------------------------------------------"
139
+
140
+ # --- Ask all questions first ---
141
+
142
+ $fluxChoice = Ask-Question -Prompt "Do you want to download FLUX base models?" -Choices @("A) fp16", "B) fp8", "C) All", "D) No") -ValidAnswers @("A", "B", "C", "D")
143
+ $ggufChoice = Ask-Question -Prompt "Do you want to download FLUX GGUF models?" -Choices @("A) Q8 (18GB VRAM)","B) Q6 (14GB VRAM)", "C) Q5 (12GB VRAM)", "D) Q4 (10GB VRAM)", "E) Q3 (8GB VRAM)", "F) Q2 (6GB VRAM)", "G) All", "H) No") -ValidAnswers @("A", "B", "C", "D", "E", "F", "G", "H")
144
+ $schnellChoice = Ask-Question -Prompt "Do you want to download the FLUX SCHNELL Model?" -Choices @("A) Yes", "B) No") -ValidAnswers @("A", "B")
145
+ $controlnetChoice = Ask-Question -Prompt "Do you want to download FLUX ControlNet Models?" -Choices @("A) fp16", "B) fp8", "C) Q8", "D) Q5", "E) Q4", "F) All", "G) No") -ValidAnswers @("A", "B", "C", "D", "E", "F", "G")
146
+ $pulidChoice = Ask-Question -Prompt "Do you want to download FLUX PuLID and REDUX Models?" -Choices @("A) Yes", "B) No") -ValidAnswers @("A", "B")
147
+ $loraChoice = Ask-Question -Prompt "Do you want to download UmeAiRT LoRAs?" -Choices @("A) Yes", "B) No") -ValidAnswers @("A", "B")
148
+
149
+ # --- Download files based on answers ---
150
+
151
+ $baseUrl = "https://huggingface.co/UmeAiRT/ComfyUI-Auto_installer/resolve/main/models"
152
+
153
+ # FLUX Base Models
154
+ if ($fluxChoice -in @("A", "C")) {
155
+ $destDir = Join-Path $modelsPath "diffusion_models\FLUX"; New-Item -Path $destDir -ItemType Directory -Force | Out-Null
156
+ $clipDir = Join-Path $modelsPath "clip"; New-Item -Path $clipDir -ItemType Directory -Force | Out-Null
157
+ Download-File -Uri "$baseUrl/diffusion_models/FLUX/flux1-dev-fp16.safetensors" -OutFile (Join-Path $destDir "flux1-dev-fp16.safetensors")
158
+ Download-File -Uri "$baseUrl/clip/t5xxl_fp16.safetensors" -OutFile (Join-Path $clipDir "t5xxl_fp16.safetensors")
159
+ }
160
+ if ($fluxChoice -in @("B", "C")) {
161
+ $destDir = Join-Path $modelsPath "diffusion_models\FLUX"; New-Item -Path $destDir -ItemType Directory -Force | Out-Null
162
+ $clipDir = Join-Path $modelsPath "clip"; New-Item -Path $clipDir -ItemType Directory -Force | Out-Null
163
+ Download-File -Uri "$baseUrl/diffusion_models/FLUX/flux1-dev-fp8.safetensors" -OutFile (Join-Path $destDir "flux1-dev-fp8.safetensors")
164
+ Download-File -Uri "$baseUrl/clip/t5xxl_fp8_e4m3fn.safetensors" -OutFile (Join-Path $clipDir "t5xxl_fp8_e4m3fn.safetensors")
165
+ }
166
+
167
+ # Common files (VAE, CLIPs) - Downloaded if any main option was chosen
168
+ $destDir = Join-Path $modelsPath "vae"; New-Item -Path $destDir -ItemType Directory -Force | Out-Null
169
+ Download-File -Uri "$baseUrl/vae/ae.safetensors" -OutFile (Join-Path $destDir "ae.safetensors")
170
+ $destDir = Join-Path $modelsPath "clip"; New-Item -Path $destDir -ItemType Directory -Force | Out-Null
171
+ Download-File -Uri "$baseUrl/clip/clip_l.safetensors" -OutFile (Join-Path $destDir "clip_l.safetensors")
172
+
173
+ # GGUF Models
174
+ if ($ggufChoice -ne 'H') {
175
+ $unetDir = Join-Path $modelsPath "unet\FLUX"; New-Item -Path $unetDir -ItemType Directory -Force | Out-Null
176
+ $clipDir = Join-Path $modelsPath "clip"; New-Item -Path $clipDir -ItemType Directory -Force | Out-Null
177
+ if ($ggufChoice -in @("A", "G")) {
178
+ Download-File -Uri "$baseUrl/clip/t5-v1_1-xxl-encoder-Q8_0.gguf" -OutFile (Join-Path $clipDir "t5-v1_1-xxl-encoder-Q8_0.gguf")
179
+ Download-File -Uri "$baseUrl/unet/FLUX/flux1-dev-Q8_0.gguf" -OutFile (Join-Path $unetDir "flux1-dev-Q8_0.gguf")
180
+ }
181
+ if ($ggufChoice -in @("B", "G")) {
182
+ Download-File -Uri "$baseUrl/clip/t5-v1_1-xxl-encoder-Q6_K.gguf" -OutFile (Join-Path $clipDir "t5-v1_1-xxl-encoder-Q6_K.gguf")
183
+ Download-File -Uri "$baseUrl/unet/FLUX/flux1-dev-Q6_K.gguf" -OutFile (Join-Path $unetDir "flux1-dev-Q6_K.gguf")
184
+ }
185
+ if ($ggufChoice -in @("C", "G")) {
186
+ Download-File -Uri "$baseUrl/clip/t5-v1_1-xxl-encoder-Q5_K_M.gguf" -OutFile (Join-Path $clipDir "t5-v1_1-xxl-encoder-Q5_K_M.gguf")
187
+ Download-File -Uri "$baseUrl/unet/FLUX/flux1-dev-Q5_K_S.gguf" -OutFile (Join-Path $unetDir "flux1-dev-Q5_K_S.gguf")
188
+ }
189
+ if ($ggufChoice -in @("D", "G")) {
190
+ Download-File -Uri "$baseUrl/clip/t5-v1_1-xxl-encoder-Q4_K_S.gguf" -OutFile (Join-Path $clipDir "t5-v1_1-xxl-encoder-Q4_K_S.gguf")
191
+ Download-File -Uri "$baseUrl/unet/FLUX/flux1-dev-Q4_K_S.gguf" -OutFile (Join-Path $unetDir "flux1-dev-Q4_K_S.gguf")
192
+ }
193
+ if ($ggufChoice -in @("E", "G")) {
194
+ Download-File -Uri "$baseUrl/clip/t5-v1_1-xxl-encoder-Q3_K_S.gguf" -OutFile (Join-Path $clipDir "t5-v1_1-xxl-encoder-Q3_K_S.gguf")
195
+ Download-File -Uri "$baseUrl/unet/FLUX/flux1-dev-Q3_K_S.gguf" -OutFile (Join-Path $unetDir "flux1-dev-Q3_K_S.gguf")
196
+ }
197
+ if ($ggufChoice -in @("F", "G")) {
198
+ Download-File -Uri "$baseUrl/clip/t5-v1_1-xxl-encoder-Q3_K_S.gguf" -OutFile (Join-Path $clipDir "t5-v1_1-xxl-encoder-Q3_K_S.gguf")
199
+ Download-File -Uri "$baseUrl/unet/FLUX/flux1-dev-Q2_K.gguf" -OutFile (Join-Path $unetDir "flux1-dev-Q2_K.gguf")
200
+ }
201
+ }
202
+
203
+ # Schnell Model
204
+ if ($schnellChoice -ne 'G') {
205
+ $destDir = Join-Path $modelsPath "diffusion_models\FLUX"; New-Item -Path $destDir -ItemType Directory -Force | Out-Null
206
+ Download-File -Uri "$baseUrl/diffusion_models/FLUX/flux1-schnell-fp8.safetensors" -OutFile (Join-Path $destDir "flux1-schnell-fp8.safetensors")
207
+ }
208
+
209
+ # ControlNet Models
210
+ if ($controlnetChoice -eq 'A') {
211
+ $destDir = Join-Path $modelsPath "xlabs\controlnets"; New-Item -Path $destDir -ItemType Directory -Force | Out-Null
212
+ $unetDir = Join-Path $modelsPath "unet\FLUX"; New-Item -Path $unetDir -ItemType Directory -Force | Out-Null
213
+ Download-File -Uri "$baseUrl/xlabs/controlnets/flux-canny-controlnet-v3.safetensors" -OutFile (Join-Path $destDir "flux-canny-controlnet-v3.safetensors")
214
+ Download-File -Uri "$baseUrl/xlabs/controlnets/flux-depth-controlnet-v3.safetensors" -OutFile (Join-Path $destDir "flux-depth-controlnet-v3.safetensors")
215
+ if ($controlnetChoice -in @("A", "F")) {
216
+ Download-File -Uri "$baseUrl/diffusion_models/FLUX/flux1-canny-dev-fp16.safetensors" -OutFile (Join-Path $unetDir "flux1-canny-dev-fp16.safetensors")
217
+ Download-File -Uri "$baseUrl/diffusion_models/FLUX/flux1-depth-dev-fp16.safetensors" -OutFile (Join-Path $unetDir "flux1-depth-dev-fp16.safetensors")
218
+ }
219
+ if ($controlnetChoice -in @("B", "F")) {
220
+ Download-File -Uri "$baseUrl/diffusion_models/FLUX/flux1-canny-dev-fp8.safetensors" -OutFile (Join-Path $unetDir "flux1-canny-dev-fp8.safetensors")
221
+ Download-File -Uri "$baseUrl/diffusion_models/FLUX/flux1-depth-dev-fp8.safetensors" -OutFile (Join-Path $unetDir "flux1-depth-dev-fp8.safetensors")
222
+ }
223
+ if ($controlnetChoice -in @("C", "F")) {
224
+ Download-File -Uri "$baseUrl/unet/FLUX/flux1-canny-dev-fp16-Q8_0-GGUF.gguf" -OutFile (Join-Path $unetDir "flux1-canny-dev-fp16-Q8_0-GGUF.gguf")
225
+ Download-File -Uri "$baseUrl/unet/FLUX/flux1-depth-dev-fp16-Q8_0-GGUF.gguf" -OutFile (Join-Path $unetDir "flux1-depth-dev-fp16-Q8_0-GGUF.gguf")
226
+ }
227
+ if ($controlnetChoice -in @("D", "F")) {
228
+ Download-File -Uri "$baseUrl/unet/FLUX/flux1-canny-dev-fp16-Q5_0-GGUF.gguf" -OutFile (Join-Path $unetDir "flux1-canny-dev-fp16-Q5_0-GGUF.gguf")
229
+ Download-File -Uri "$baseUrl/unet/FLUX/flux1-depth-dev-fp16-Q5_0-GGUF.gguf" -OutFile (Join-Path $unetDir "flux1-depth-dev-fp16-Q5_0-GGUF.gguf")
230
+ }
231
+ if ($controlnetChoice -in @("E", "F")) {
232
+ Download-File -Uri "$baseUrl/unet/FLUX/flux1-canny-dev-fp16-Q4_0-GGUF.gguf" -OutFile (Join-Path $unetDir "flux1-canny-dev-fp16-Q4_0-GGUF.gguf")
233
+ Download-File -Uri "$baseUrl/unet/FLUX/flux1-depth-dev-fp16-Q4_0-GGUF.gguf" -OutFile (Join-Path $unetDir "flux1-depth-dev-fp16-Q4_0-GGUF.gguf")
234
+ }
235
+ }
236
+
237
+ # PuLID Models
238
+ if ($pulidChoice -eq 'A') {
239
+ $destDir = Join-Path $modelsPath "pulid"; New-Item -Path $destDir -ItemType Directory -Force | Out-Null
240
+ Download-File -Uri "$baseUrl/pulid/pulid_flux_v0.9.0.safetensors" -OutFile (Join-Path $destDir "pulid_flux_v0.9.0.safetensors")
241
+
242
+ $destDir = Join-Path $modelsPath "style_models"; New-Item -Path $destDir -ItemType Directory -Force | Out-Null
243
+ Download-File -Uri "$baseUrl/style_models/flux1-redux-dev.safetensors" -OutFile (Join-Path $destDir "flux1-redux-dev.safetensors")
244
+ }
245
+
246
+ # LoRA Models
247
+ if ($loraChoice -eq 'A') {
248
+ $destDir = Join-Path $modelsPath "loras\FLUX"; New-Item -Path $destDir -ItemType Directory -Force | Out-Null
249
+ Download-File -Uri "https://huggingface.co/UmeAiRT/FLUX.1-dev-LoRA-Ume_Sky/resolve/main/ume_sky_v2.safetensors" -OutFile (Join-Path $destDir "ume_sky_v2.safetensors")
250
+ Download-File -Uri "https://huggingface.co/UmeAiRT/FLUX.1-dev-LoRA-Modern_Pixel_art/resolve/main/ume_modern_pixelart.safetensors" -OutFile (Join-Path $destDir "ume_modern_pixelart.safetensors")
251
+ Download-File -Uri "https://huggingface.co/UmeAiRT/FLUX.1-dev-LoRA-Romanticism/resolve/main/ume_classic_Romanticism.safetensors" -OutFile (Join-Path $destDir "ume_classic_Romanticism.safetensors")
252
+ Download-File -Uri "https://huggingface.co/UmeAiRT/FLUX.1-dev-LoRA-Impressionism/resolve/main/ume_classic_impressionist.safetensors" -OutFile (Join-Path $destDir "ume_classic_impressionist.safetensors")
253
+ }
254
+
255
+
256
+ Write-Log "`nFLUX model downloads complete." -Color Green