Upload Download-FLUX-Models.ps1
Browse files
scripts/Model_downloader/Download-FLUX-Models.ps1
CHANGED
@@ -1,95 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<#
|
2 |
.SYNOPSIS
|
3 |
-
A PowerShell script to interactively download FLUX models for ComfyUI.
|
4 |
.DESCRIPTION
|
5 |
-
This
|
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 |
-
|
90 |
-
$
|
|
|
91 |
if (-not (Test-Path $basePath)) {
|
92 |
-
$basePath = $
|
93 |
}
|
94 |
$modelsPath = Join-Path $basePath "ComfyUI\models"
|
95 |
if (-not (Test-Path $modelsPath)) {
|
@@ -147,33 +87,30 @@ $pulidChoice = Ask-Question -Prompt "Do you want to download FLUX PuLID and REDU
|
|
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")
|
@@ -202,14 +139,11 @@ if ($ggufChoice -ne 'H') {
|
|
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")) {
|
@@ -236,16 +170,12 @@ if ($controlnetChoice -eq 'A') {
|
|
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")
|
|
|
1 |
+
param(
|
2 |
+
# Accepte le chemin d'installation du script principal.
|
3 |
+
# Par défaut, utilise son propre dossier s'il est lancé seul.
|
4 |
+
[string]$InstallPath = $PSScriptRoot
|
5 |
+
)
|
6 |
+
|
7 |
<#
|
8 |
.SYNOPSIS
|
9 |
+
A fully refactored and corrected PowerShell script to interactively download FLUX models for ComfyUI.
|
10 |
.DESCRIPTION
|
11 |
+
This version corrects pathing issues, download logic, and optimizes directory creation.
|
|
|
|
|
12 |
#>
|
13 |
|
14 |
#===========================================================================
|
15 |
# SECTION 1: HELPER FUNCTIONS & SETUP
|
16 |
#===========================================================================
|
17 |
+
function Write-Log { param([string]$Message, [string]$Color = "White") { $logFile = Join-Path (Split-Path $MyInvocation.MyCommand.Path -Parent) "logs\install_log.txt"; $formattedMessage = "[$([DateTime]::Now.ToString('yyyy-MM-dd HH:mm:ss'))] [ModelDownloader] $Message"; Write-Host $Message -ForegroundColor $Color; Add-Content -Path $logFile -Value $formattedMessage; } }
|
18 |
+
function Invoke-AndLog { param([string]$File, [string]$Arguments) { $logFile = Join-Path (Split-Path $MyInvocation.MyCommand.Path -Parent) "logs\install_log.txt"; $commandToRun = "`"$File`" $Arguments"; $cmdArguments = "/C `"$commandToRun >> `"`"$logFile`"`" 2>&1`""; try { Start-Process -FilePath "cmd.exe" -ArgumentList $cmdArguments -Wait -WindowStyle Hidden } catch { Write-Log "FATAL ERROR trying to execute command: $commandToRun" -Color Red } } }
|
19 |
+
function Download-File { param([string]$Uri, [string]$OutFile) { if (Test-Path $OutFile) { Write-Log "Skipping: $((Split-Path $OutFile -Leaf)) (already exists)." -Color Gray } else { $fileName = Split-Path -Path $Uri -Leaf; if (Get-Command 'aria2c' -ErrorAction SilentlyContinue) { Write-Log "Downloading: $fileName"; $aria_args = "-c -x 16 -s 16 -k 1M --dir=`"$((Split-Path $OutFile -Parent))`" --out=`"$((Split-Path $OutFile -Leaf))`" `"$Uri`""; Invoke-AndLog "aria2c" $aria_args } else { Write-Log "Aria2 not found. Falling back to standard download: $fileName" -Color Yellow; Invoke-WebRequest -Uri $Uri -OutFile $OutFile } } } }
|
20 |
+
function Ask-Question { param([string]$Prompt, [string[]]$Choices, [string[]]$ValidAnswers) { $choice = ''; while ($choice -notin $ValidAnswers) { Write-Log "`n$Prompt" -Color Yellow; foreach ($line in $Choices) { Write-Host " $line" -ForegroundColor Green }; $choice = (Read-Host "Enter your choice and press Enter").ToUpper(); if ($choice -notin $ValidAnswers) { Write-Log "Invalid choice. Please try again." -Color Red } }; return $choice } }
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
#===========================================================================
|
24 |
# SECTION 2: SCRIPT EXECUTION
|
25 |
#===========================================================================
|
26 |
|
27 |
# --- Path Detection ---
|
28 |
+
# On nettoie le chemin reçu en argument et on l'utilise
|
29 |
+
$InstallPath = $InstallPath.Trim('"')
|
30 |
+
$basePath = Join-Path $InstallPath "ComfyUI_windows_portable"
|
31 |
if (-not (Test-Path $basePath)) {
|
32 |
+
$basePath = $InstallPath
|
33 |
}
|
34 |
$modelsPath = Join-Path $basePath "ComfyUI\models"
|
35 |
if (-not (Test-Path $modelsPath)) {
|
|
|
87 |
$loraChoice = Ask-Question -Prompt "Do you want to download UmeAiRT LoRAs?" -Choices @("A) Yes", "B) No") -ValidAnswers @("A", "B")
|
88 |
|
89 |
# --- Download files based on answers ---
|
90 |
+
# --- Create all needed directories once ---
|
91 |
+
Write-Log "`nPreparing model directories..." -Color Cyan
|
92 |
+
$requiredDirs = @("vae", "clip", "diffusion_models/FLUX", "unet/FLUX", "xlabs/controlnets", "pulid", "style_models", "loras/FLUX")
|
93 |
+
foreach ($subDir in $requiredDirs) {
|
94 |
+
New-Item -Path (Join-Path $modelsPath $subDir) -ItemType Directory -Force | Out-Null
|
95 |
+
}
|
96 |
$baseUrl = "https://huggingface.co/UmeAiRT/ComfyUI-Auto_installer/resolve/main/models"
|
97 |
|
98 |
# FLUX Base Models
|
99 |
if ($fluxChoice -in @("A", "C")) {
|
|
|
|
|
100 |
Download-File -Uri "$baseUrl/diffusion_models/FLUX/flux1-dev-fp16.safetensors" -OutFile (Join-Path $destDir "flux1-dev-fp16.safetensors")
|
101 |
Download-File -Uri "$baseUrl/clip/t5xxl_fp16.safetensors" -OutFile (Join-Path $clipDir "t5xxl_fp16.safetensors")
|
102 |
}
|
103 |
if ($fluxChoice -in @("B", "C")) {
|
|
|
|
|
104 |
Download-File -Uri "$baseUrl/diffusion_models/FLUX/flux1-dev-fp8.safetensors" -OutFile (Join-Path $destDir "flux1-dev-fp8.safetensors")
|
105 |
Download-File -Uri "$baseUrl/clip/t5xxl_fp8_e4m3fn.safetensors" -OutFile (Join-Path $clipDir "t5xxl_fp8_e4m3fn.safetensors")
|
106 |
}
|
107 |
|
108 |
# Common files (VAE, CLIPs) - Downloaded if any main option was chosen
|
|
|
109 |
Download-File -Uri "$baseUrl/vae/ae.safetensors" -OutFile (Join-Path $destDir "ae.safetensors")
|
|
|
110 |
Download-File -Uri "$baseUrl/clip/clip_l.safetensors" -OutFile (Join-Path $destDir "clip_l.safetensors")
|
111 |
|
112 |
# GGUF Models
|
113 |
if ($ggufChoice -ne 'H') {
|
|
|
|
|
114 |
if ($ggufChoice -in @("A", "G")) {
|
115 |
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")
|
116 |
Download-File -Uri "$baseUrl/unet/FLUX/flux1-dev-Q8_0.gguf" -OutFile (Join-Path $unetDir "flux1-dev-Q8_0.gguf")
|
|
|
139 |
|
140 |
# Schnell Model
|
141 |
if ($schnellChoice -ne 'G') {
|
|
|
142 |
Download-File -Uri "$baseUrl/diffusion_models/FLUX/flux1-schnell-fp8.safetensors" -OutFile (Join-Path $destDir "flux1-schnell-fp8.safetensors")
|
143 |
}
|
144 |
|
145 |
# ControlNet Models
|
146 |
if ($controlnetChoice -eq 'A') {
|
|
|
|
|
147 |
Download-File -Uri "$baseUrl/xlabs/controlnets/flux-canny-controlnet-v3.safetensors" -OutFile (Join-Path $destDir "flux-canny-controlnet-v3.safetensors")
|
148 |
Download-File -Uri "$baseUrl/xlabs/controlnets/flux-depth-controlnet-v3.safetensors" -OutFile (Join-Path $destDir "flux-depth-controlnet-v3.safetensors")
|
149 |
if ($controlnetChoice -in @("A", "F")) {
|
|
|
170 |
|
171 |
# PuLID Models
|
172 |
if ($pulidChoice -eq 'A') {
|
|
|
173 |
Download-File -Uri "$baseUrl/pulid/pulid_flux_v0.9.0.safetensors" -OutFile (Join-Path $destDir "pulid_flux_v0.9.0.safetensors")
|
|
|
|
|
174 |
Download-File -Uri "$baseUrl/style_models/flux1-redux-dev.safetensors" -OutFile (Join-Path $destDir "flux1-redux-dev.safetensors")
|
175 |
}
|
176 |
|
177 |
# LoRA Models
|
178 |
if ($loraChoice -eq 'A') {
|
|
|
179 |
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")
|
180 |
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")
|
181 |
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")
|