File size: 6,138 Bytes
3c4741a 8840e47 3c4741a 8840e47 3c4741a 8840e47 3c4741a 8840e47 3c4741a 8063f14 3c4741a 8063f14 3c4741a 8063f14 3c4741a |
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 |
param(
[string]$InstallPath = $PSScriptRoot
)
<#
.SYNOPSIS
A PowerShell script to interactively download HiDream models for ComfyUI.
.DESCRIPTION
This version corrects a major syntax error in the helper functions.
#>
#===========================================================================
# SECTION 1: HELPER FUNCTIONS & SETUP
#===========================================================================
function Write-Log {
param([string]$Message, [string]$Color = "White")
$logFile = Join-Path $InstallPath "logs\install_log.txt"
$formattedMessage = "[$([DateTime]::Now.ToString('yyyy-MM-dd HH:mm:ss'))] [ModelDownloader-HiDream] $Message"
Write-Host $Message -ForegroundColor $Color
Add-Content -Path $logFile -Value $formattedMessage -ErrorAction SilentlyContinue
}
function Invoke-AndLog {
param([string]$File, [string]$Arguments)
$logFile = Join-Path $InstallPath "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
}
}
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
}
}
}
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
}
#===========================================================================
# SECTION 2: SCRIPT EXECUTION
#===========================================================================
$InstallPath = $InstallPath.Trim('"')
$comfyPath = Join-Path $InstallPath "ComfyUI"
$modelsPath = Join-Path $comfyPath "models"
if (-not (Test-Path $modelsPath)) { Write-Log "Could not find ComfyUI models path at '$modelsPath'. Exiting." -Color Red; Read-Host "Press Enter to exit."; exit }
# --- GPU Detection ---
Write-Log "-------------------------------------------------------------------------------"
Write-Log "Checking for NVIDIA GPU to provide model recommendations..." -Color Yellow
# ... (logique de détection GPU) ...
Write-Log "-------------------------------------------------------------------------------"
# --- Ask all questions ---
$fp8Choice = Ask-Question "Do you want to download HiDream fp8 models? (24GB Vram recommended)" @("A) Yes", "B) No") @("A", "B")
$ggufChoice = Ask-Question "Do you want to download HiDream GGUF models?" @("A) Q8_0 (16GB Vram)", "B) Q5_K_S (12GB Vram)", "C) Q4_K_S (less than 12GB Vram)", "D) All", "E) No") @("A", "B", "C", "D", "E")
# --- Download files based on answers ---
Write-Log "`nStarting HiDream model downloads..." -Color Cyan
$baseUrl = "https://huggingface.co/UmeAiRT/ComfyUI-Auto_installer/resolve/main/models"
$hidreamDiffDir = Join-Path $modelsPath "diffusion_models\HIDREAM"; $hidreamUnetDir = Join-Path $modelsPath "unet\HIDREAM"; $clipDir = Join-Path $modelsPath "clip"; $vaeDir = Join-Path $modelsPath "vae"
New-Item -Path $hidreamDiffDir, $hidreamUnetDir, $clipDir, $vaeDir -ItemType Directory -Force | Out-Null
$doDownload = ($fp8Choice -eq 'A' -or $ggufChoice -ne 'E')
if ($doDownload) {
Write-Log "`nDownloading HiDream common support files (VAE, CLIPs)..."
Download-File -Uri "$baseUrl/vae/ae.safetensors?download=true" -OutFile (Join-Path $vaeDir "ae.safetensors")
Download-File -Uri "$baseUrl/clip/clip_g_hidream.safetensors" -OutFile (Join-Path $clipDir "clip_g_hidream.safetensors")
Download-File -Uri "$baseUrl/clip/clip_l_hidream.safetensors" -OutFile (Join-Path $clipDir "clip_l_hidream.safetensors")
Download-File -Uri "$baseUrl/clip/t5xxl_fp8_e4m3fn_scaled.safetensors" -OutFile (Join-Path $clipDir "t5xxl_fp8_e4m3fn_scaled.safetensors")
Download-File -Uri "$baseUrl/clip/llama_3.1_8b_instruct_fp8_scaled.safetensors" -OutFile (Join-Path $clipDir "llama_3.1_8b_instruct_fp8_scaled.safetensors")
}
if ($fp8Choice -eq 'A') {
Write-Log "`nDownloading HiDream fp8 model..."
Download-File -Uri "$baseUrl/diffusion_models/HiDream/hidream_i1_dev_fp8.safetensors" -OutFile (Join-Path $hidreamDiffDir "hidream_i1_dev_fp8.safetensors")
}
if ($ggufChoice -ne 'E') {
Write-Log "`nDownloading HiDream GGUF models..."
if ($ggufChoice -in 'A', 'D') { Download-File -Uri "$baseUrl/unet/HiDream/hidream-i1-dev-Q8_0.gguf" -OutFile (Join-Path $hidreamUnetDir "hidream-i1-dev-Q8_0.gguf") }
if ($ggufChoice -in 'B', 'D') { Download-File -Uri "$baseUrl/unet/HiDream/hidream-i1-dev-Q5_K_S.gguf" -OutFile (Join-Path $hidreamUnetDir "hidream-i1-dev-Q5_K_S.gguf") }
if ($ggufChoice -in 'C', 'D') { Download-File -Uri "$baseUrl/unet/HiDream/hidream-i1-dev-Q4_K_S.gguf" -OutFile (Join-Path $hidreamUnetDir "hidream-i1-dev-Q4_K_S.gguf") }
}
Write-Log "`nHiDream model downloads complete." -Color Green
Read-Host "Press Enter to return to the main installer." |