Download install.ps1 from cowpuncher/Krita_AI_Helper_Addons: direct link, hf CLI and curl.
- Browser
- Download file 21.4 kB
-
https://huggingface.co/datasets/cowpuncher/Krita_AI_Helper_Addons/resolve/main/install.ps1
- Command line
-
hf download hf://datasets/cowpuncher/Krita_AI_Helper_Addons/install.ps1
-
curl -L -o install.ps1 https://huggingface.co/datasets/cowpuncher/Krita_AI_Helper_Addons/resolve/main/install.ps1
21.4 kB
| # Krita AI Helper Pack - installer. | |
| # Started by install.bat. Written for the Windows PowerShell that ships with Windows 10/11. | |
| # | |
| # What it does, for the tools you say Yes to: | |
| # * copies the Krita plugins into %APPDATA%\krita\pykrita | |
| # * Anima Reference only, on the server the Krita AI plugin uses: | |
| # copies the "Anima Ref Adapter" node into <server>\ComfyUI\custom_nodes | |
| # downloads its weights (184 MB) into <server>\models\loras | |
| # optionally the same for SnapRef (node, 382 MB of weights) | |
| # * optionally copies two Gelbooru tag lists into %APPDATA%\krita\ai_diffusion\tags | |
| # Nothing else is changed. Running it again is safe. | |
| $ErrorActionPreference = 'Stop' | |
| $ProgressPreference = 'SilentlyContinue' | |
| try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch { } | |
| $Here = Split-Path -Parent $MyInvocation.MyCommand.Path | |
| $AdapterNode = 'ComfyUI-Anima-Ref-Adapter' | |
| $AdapterName = 'anima_ref_adapter_v2_r64.safetensors' | |
| $AdapterUrl = 'https://huggingface.co/ElectronGirl/anima-ref-adapter/resolve/main/anima_ref_adapter_v2_r64.safetensors' | |
| $AdapterSize = 183605032 | |
| $AdapterHash = '71DDA6079E18D354E16E3347BC49A9B710AFD9495C378EFBB833D30CAC9CB81B' | |
| $SnapNode = 'snapref' | |
| $SnapName = 'snapref_v2a.safetensors' | |
| $SnapUrl = 'https://huggingface.co/0ppxnhximxr/snapref-v2a/resolve/e6d6a21e4d56faae4454a1cc9bfd065d87358bf2/snapref_v2a.safetensors' | |
| $SnapPage = 'https://huggingface.co/0ppxnhximxr/snapref-v2a' | |
| $SnapSize = 381821960 | |
| $SnapHash = '8A22FC28D060447544EDA283B36EFE2DCDBAD7422CBC0B8D42828D55A8A61AB4' | |
| # used only for testing this script | |
| if ($env:ANIMA_REF_WEIGHTS_URL) { $AdapterUrl = $env:ANIMA_REF_WEIGHTS_URL } | |
| if ($env:SNAPREF_WEIGHTS_URL) { $SnapUrl = $env:SNAPREF_WEIGHTS_URL } | |
| # name, folder, text shown in Krita's Python Plugin Manager, where to find it afterwards, question | |
| $Tools = @( | |
| @{ Key = 'anima'; Folder = 'anima_reference'; Title = 'Anima Reference (add-on for AI Image Diffusion)' | |
| Where = 'Tools > Scripts > Anima Reference (status and one option)' | |
| Ask = 'Anima Reference - Reference / Style / Face control layers for Anima styles' }, | |
| @{ Key = 'board'; Folder = 'ai_reference_board'; Title = 'AI Reference Board' | |
| Where = 'Settings > Dockers > AI Reference Board' | |
| Ask = 'AI Reference Board - pick or grab reference pictures and add them as control layers' }, | |
| @{ Key = 'picker'; Folder = 'lora_trigger_picker'; Title = 'LoRA Trigger Picker' | |
| Where = 'Tools > Scripts > LoRA Trigger Picker' | |
| Ask = 'LoRA Trigger Picker - look up LoRAs and checkpoints, fill in their trigger words' }, | |
| @{ Key = 'critic'; Folder = 'prompt_critic'; Title = 'Prompt Critic' | |
| Where = 'Settings > Dockers > Prompt Critic' | |
| Ask = 'Prompt Critic - prompt fixing with your own local LLM (not included, see docs\LLM setup.txt)' } | |
| ) | |
| $problems = 0 | |
| function Say($text) { Write-Host $text } | |
| function Good($text) { Write-Host (' OK ' + $text) -ForegroundColor Green } | |
| function Note($text) { Write-Host (' NOTE ' + $text) -ForegroundColor Yellow } | |
| function Bad($text) { Write-Host (' FAIL ' + $text) -ForegroundColor Red; $script:problems = $script:problems + 1 } | |
| function Ask-YesNo($question, $default) { | |
| $hint = ' [Y/N]' | |
| if ($default -eq $true) { $hint = ' [Y/n, Enter = Yes]' } | |
| while ($true) { | |
| $answer = Read-Host ($question + $hint) | |
| if ($null -eq $answer) { return [bool]$default } | |
| $answer = $answer.Trim().ToLower() | |
| if ($answer -eq '') { return [bool]$default } | |
| if ($answer -eq 'y' -or $answer -eq 'yes') { return $true } | |
| if ($answer -eq 'n' -or $answer -eq 'no') { return $false } | |
| } | |
| } | |
| function Find-ServerFolder($kritaFolder) { | |
| # 1. what the AI plugin itself has stored | |
| $settingsFile = Join-Path (Join-Path $kritaFolder 'ai_diffusion') 'settings.json' | |
| if (Test-Path -LiteralPath $settingsFile) { | |
| try { | |
| $settings = Get-Content -LiteralPath $settingsFile -Raw | ConvertFrom-Json | |
| if ($settings.server_path -and (Test-Path -LiteralPath (Join-Path $settings.server_path 'ComfyUI'))) { | |
| return $settings.server_path | |
| } | |
| } catch { } | |
| } | |
| # 2. the usual places | |
| $guesses = @((Join-Path (Join-Path $kritaFolder 'ai_diffusion') 'server')) | |
| if ($env:USERPROFILE) { $guesses += (Join-Path (Join-Path $env:USERPROFILE 'Desktop') 'server') } | |
| foreach ($guess in $guesses) { | |
| if (Test-Path -LiteralPath (Join-Path $guess 'ComfyUI')) { return $guess } | |
| } | |
| return $null | |
| } | |
| function Get-Download($url, $target) { | |
| $partial = $target + '.part' | |
| if (Test-Path -LiteralPath $partial) { Remove-Item -LiteralPath $partial -Force } | |
| $curl = Get-Command curl.exe -ErrorAction SilentlyContinue | |
| if ($curl) { | |
| & $curl.Path -L --fail --retry 2 -o $partial $url | |
| if ($LASTEXITCODE -ne 0) { throw ('download failed, curl exit code ' + $LASTEXITCODE) } | |
| } else { | |
| Invoke-WebRequest -Uri $url -OutFile $partial -UseBasicParsing | |
| } | |
| Move-Item -LiteralPath $partial -Destination $target -Force | |
| } | |
| function Test-File($file, $size, $hash) { | |
| if (-not (Test-Path -LiteralPath $file)) { return $false } | |
| if ((Get-Item -LiteralPath $file).Length -ne $size) { return $false } | |
| return ((Get-FileHash -LiteralPath $file -Algorithm SHA256).Hash -eq $hash) | |
| } | |
| function Find-InLoras($loraFolders, $filter) { | |
| foreach ($folder in $loraFolders) { | |
| if (Test-Path -LiteralPath $folder) { | |
| $found = Get-ChildItem -LiteralPath $folder -Recurse -Filter $filter -File -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| if ($found) { return $found.FullName } | |
| } | |
| } | |
| return $null | |
| } | |
| function Get-LoraFolder($loraFolders) { | |
| if (Test-Path -LiteralPath $loraFolders[0]) { return $loraFolders[0] } | |
| if (Test-Path -LiteralPath $loraFolders[1]) { return $loraFolders[1] } | |
| New-Item -ItemType Directory -Path $loraFolders[0] -Force | Out-Null | |
| return $loraFolders[0] | |
| } | |
| function Copy-Folder($source, $target) { | |
| if (Test-Path -LiteralPath $target) { Remove-Item -LiteralPath $target -Recurse -Force } | |
| Copy-Item -LiteralPath $source -Destination $target -Recurse -Force | |
| } | |
| function Find-SnapRefNode($customNodes) { | |
| # the SnapRef node pack, whatever its folder is called | |
| foreach ($dir in @(Get-ChildItem -LiteralPath $customNodes -Directory -ErrorAction SilentlyContinue)) { | |
| $init = Join-Path $dir.FullName '__init__.py' | |
| if (Test-Path -LiteralPath $init) { | |
| $text = '' | |
| try { $text = [IO.File]::ReadAllText($init) } catch { } | |
| if ($text.Contains('"SnapRefSimple"') -and $text.Contains('class SnapRef')) { return $dir.FullName } | |
| } | |
| } | |
| return $null | |
| } | |
| function Test-SnapRefNode($folder) { | |
| # new enough for the add-on: several pictures, each with its own weight | |
| $text = '' | |
| try { $text = [IO.File]::ReadAllText((Join-Path $folder '__init__.py')) } catch { } | |
| return ($text.Contains('"image_3"') -and $text.Contains('"use_batch"') -and $text.Contains('"weight_3"')) | |
| } | |
| try { | |
| Say '' | |
| Say 'Krita AI Helper Pack - installer' | |
| Say '--------------------------------' | |
| # ---- sanity: the package must be extracted next to this script ------------------------------- | |
| $pluginSource = Join-Path $Here 'krita_plugins' | |
| $nodeSource = Join-Path $Here 'server_nodes' | |
| $tagSource = Join-Path $Here 'tag_lists' | |
| $TagFiles = @('Gelbooru.csv', 'Gelbooru NSFW.csv') | |
| $complete = (Test-Path -LiteralPath (Join-Path (Join-Path $nodeSource $AdapterNode) '__init__.py')) -and | |
| (Test-Path -LiteralPath (Join-Path (Join-Path $nodeSource $SnapNode) '__init__.py')) | |
| foreach ($tool in $Tools) { | |
| if (-not (Test-Path -LiteralPath (Join-Path (Join-Path $pluginSource $tool.Folder) '__init__.py'))) { $complete = $false } | |
| if (-not (Test-Path -LiteralPath (Join-Path $pluginSource ($tool.Folder + '.desktop')))) { $complete = $false } | |
| } | |
| foreach ($file in $TagFiles) { | |
| if (-not (Test-Path -LiteralPath (Join-Path $tagSource $file))) { $complete = $false } | |
| } | |
| if (-not $complete) { | |
| Bad 'The package is incomplete. Extract the whole zip into a folder first, then run install.bat from that folder.' | |
| throw 'stop' | |
| } | |
| # ---- Krita must be closed: it loads plugins at start, and its server keeps running otherwise -- | |
| while (Get-Process -Name 'krita' -ErrorAction SilentlyContinue) { | |
| Note 'Krita is running. Close Krita now, then press Enter here.' | |
| [void](Read-Host) | |
| } | |
| # ---- Krita's folder ----------------------------------------------------------------------------- | |
| if (-not $env:APPDATA) { Bad 'APPDATA is not set, cannot find the Krita folder.'; throw 'stop' } | |
| $kritaFolder = Join-Path $env:APPDATA 'krita' | |
| $pykrita = Join-Path $kritaFolder 'pykrita' | |
| if (-not (Test-Path -LiteralPath (Join-Path $pykrita 'ai_diffusion'))) { | |
| Bad ('The AI Image Diffusion plugin was not found in ' + $pykrita) | |
| Say ' These tools are add-ons for it. Install it first (github.com/Acly/krita-ai-diffusion), then run this again.' | |
| throw 'stop' | |
| } | |
| Say ('Krita folder : ' + $kritaFolder) | |
| Say '' | |
| # ---- which tools -------------------------------------------------------------------------------- | |
| Say 'Which tools do you want?' | |
| $chosen = @() | |
| foreach ($tool in $Tools) { | |
| if (Ask-YesNo (' ' + $tool.Ask) $true) { $chosen += $tool } | |
| } | |
| Say '' | |
| Say 'Extra, not a plugin:' | |
| $wantTags = Ask-YesNo ' Gelbooru tag lists - more words for the AI plugin''s tag auto-completion (Prompt Critic reads them too)' $true | |
| if ($chosen.Count -eq 0 -and -not $wantTags) { Say ''; Say 'Nothing chosen, nothing changed.'; throw 'stop' } | |
| Say '' | |
| # ---- 1. the Krita plugins ----------------------------------------------------------------------- | |
| if ($chosen.Count -gt 0) { Say '1. Krita plugins' } | |
| foreach ($tool in $chosen) { | |
| try { | |
| $target = Join-Path $pykrita $tool.Folder | |
| Copy-Folder (Join-Path $pluginSource $tool.Folder) $target | |
| Copy-Item -LiteralPath (Join-Path $pluginSource ($tool.Folder + '.desktop')) -Destination (Join-Path $pykrita ($tool.Folder + '.desktop')) -Force | |
| if ((Test-Path -LiteralPath (Join-Path $target '__init__.py')) -and (Test-Path -LiteralPath (Join-Path $pykrita ($tool.Folder + '.desktop')))) { | |
| Good ($tool.Title + ' -> ' + $target) | |
| } else { Bad ('could not copy ' + $tool.Title + ' to ' + $pykrita) } | |
| } catch { Bad ('could not copy ' + $tool.Title + ': ' + $_.Exception.Message) } | |
| } | |
| # ---- 2. Anima Reference: the server side ---------------------------------------------------------- | |
| $wantAnima = @($chosen | Where-Object { $_.Key -eq 'anima' }).Count -gt 0 | |
| if ($wantAnima) { | |
| Say '' | |
| Say '2. Anima Reference: nodes and weights on the server' | |
| $server = Find-ServerFolder $kritaFolder | |
| while (-not $server) { | |
| Note 'Could not find the server folder (the one that contains a ComfyUI folder).' | |
| $typed = Read-Host 'Type or paste its full path and press Enter (or just press Enter to skip this part)' | |
| if (-not $typed) { break } | |
| $typed = $typed.Trim().Trim('"') | |
| if (Test-Path -LiteralPath (Join-Path $typed 'ComfyUI')) { $server = $typed } | |
| } | |
| $customNodes = $null | |
| if ($server) { $customNodes = Join-Path (Join-Path $server 'ComfyUI') 'custom_nodes' } | |
| if (-not $server) { | |
| Bad 'No server folder: the nodes were not installed, so Reference layers stay unavailable for Anima. Run this again when you know the folder.' | |
| } elseif (-not (Test-Path -LiteralPath $customNodes)) { | |
| Bad ('Missing folder: ' + $customNodes) | |
| } else { | |
| Say (' Server folder : ' + $server) | |
| $loraFolders = @((Join-Path (Join-Path $server 'models') 'loras'), (Join-Path (Join-Path (Join-Path $server 'ComfyUI') 'models') 'loras')) | |
| # -- Anima Ref Adapter node | |
| try { | |
| Copy-Folder (Join-Path $nodeSource $AdapterNode) (Join-Path $customNodes $AdapterNode) | |
| if (Test-Path -LiteralPath (Join-Path (Join-Path $customNodes $AdapterNode) '__init__.py')) { Good ('Anima Ref Adapter node -> ' + (Join-Path $customNodes $AdapterNode)) } | |
| else { Bad 'could not copy the Anima Ref Adapter node' } | |
| } catch { Bad ('could not copy the Anima Ref Adapter node: ' + $_.Exception.Message) } | |
| # -- its weights | |
| $existing = Find-InLoras $loraFolders $AdapterName | |
| if ($existing -and (Test-File $existing $AdapterSize $AdapterHash)) { | |
| Good ('Anima Ref Adapter weights already there and intact: ' + $existing) | |
| } else { | |
| if ($existing) { Note ('found a damaged or incomplete copy, downloading again: ' + $existing) } | |
| $target = Join-Path (Get-LoraFolder $loraFolders) $AdapterName | |
| if ($existing) { $target = $existing } | |
| Say ' downloading the Anima Ref Adapter weights (184 MB) from huggingface.co ...' | |
| try { | |
| Get-Download $AdapterUrl $target | |
| if (Test-File $target $AdapterSize $AdapterHash) { Good ('downloaded and checked: ' + $target) } | |
| else { | |
| Remove-Item -LiteralPath $target -Force -ErrorAction SilentlyContinue | |
| Note 'the download did not match the expected file and was removed.' | |
| Note 'Not a blocker: the node fetches the file by itself the first time you generate (takes a minute).' | |
| } | |
| } catch { | |
| Note ('download failed: ' + $_.Exception.Message) | |
| Note 'Not a blocker: the node fetches the file by itself the first time you generate (takes a minute).' | |
| } | |
| } | |
| # -- SnapRef (Style and Face layers) | |
| Say '' | |
| Say ' SnapRef is a second adapter. It is what makes "Style" (character + art style) and "Face"' | |
| Say ' (more pictures of one character, up to 5) work. One more download, 382 MB.' | |
| if (Ask-YesNo ' Install SnapRef too?' $true) { | |
| $snapFolder = Find-SnapRefNode $customNodes | |
| if ($snapFolder -and (Test-SnapRefNode $snapFolder)) { | |
| Good ('SnapRef node already installed: ' + $snapFolder) | |
| } elseif ($snapFolder -and ((Split-Path -Leaf $snapFolder) -ne $SnapNode)) { | |
| Bad ('An older SnapRef node sits in ' + $snapFolder + '. Delete that folder, then run this again.') | |
| } else { | |
| try { | |
| Copy-Folder (Join-Path $nodeSource $SnapNode) (Join-Path $customNodes $SnapNode) | |
| if (Test-Path -LiteralPath (Join-Path (Join-Path $customNodes $SnapNode) '__init__.py')) { | |
| if ($snapFolder) { Good ('SnapRef node updated: ' + (Join-Path $customNodes $SnapNode)) } | |
| else { Good ('SnapRef node -> ' + (Join-Path $customNodes $SnapNode)) } | |
| } else { Bad 'could not copy the SnapRef node' } | |
| } catch { Bad ('could not copy the SnapRef node: ' + $_.Exception.Message) } | |
| } | |
| $existing = Find-InLoras $loraFolders '*snapref*.safetensors' | |
| $usable = $false | |
| if ($existing) { | |
| if ((Split-Path -Leaf $existing) -eq $SnapName) { $usable = (Test-File $existing $SnapSize $SnapHash) } | |
| else { $usable = ((Get-Item -LiteralPath $existing).Length -gt 100MB) } # another SnapRef version of yours | |
| } | |
| if ($usable) { | |
| Good ('SnapRef weights already there: ' + $existing) | |
| } else { | |
| if ($existing) { Note ('found a damaged or incomplete copy, downloading again: ' + $existing) } | |
| $target = Join-Path (Get-LoraFolder $loraFolders) $SnapName | |
| if ($existing -and ((Split-Path -Leaf $existing) -eq $SnapName)) { $target = $existing } | |
| Say ' downloading the SnapRef weights (382 MB) from huggingface.co ...' | |
| $ok = $false | |
| try { | |
| Get-Download $SnapUrl $target | |
| if (Test-File $target $SnapSize $SnapHash) { $ok = $true; Good ('downloaded and checked: ' + $target) } | |
| else { Remove-Item -LiteralPath $target -Force -ErrorAction SilentlyContinue; Note 'the download did not match the expected file and was removed.' } | |
| } catch { Note ('download failed: ' + $_.Exception.Message) } | |
| if (-not $ok) { | |
| Note 'Style and Face layers stay unavailable until that file is there. To get it by hand:' | |
| Note (' open ' + $SnapPage + ' , download ' + $SnapName) | |
| Note (' and put it into ' + (Get-LoraFolder $loraFolders)) | |
| } | |
| } | |
| } else { | |
| Say ' skipped. Reference layers work without it; run this again any time to add it.' | |
| } | |
| # -- leftovers of an earlier Graph-workspace version of Anima Reference | |
| $workflowFolder = Join-Path (Join-Path $kritaFolder 'ai_diffusion') 'workflows' | |
| $oldWorkflows = @() | |
| if (Test-Path -LiteralPath $workflowFolder) { | |
| $oldWorkflows = @(Get-ChildItem -LiteralPath $workflowFolder -Filter 'Anima Reference - *.json' -File -ErrorAction SilentlyContinue) | |
| } | |
| $oldHelper = Join-Path $customNodes 'ComfyUI-KritaRefPrep' | |
| if ($oldWorkflows.Count -gt 0 -or (Test-Path -LiteralPath $oldHelper)) { | |
| Say '' | |
| Say (' Found an earlier Graph-workspace version: ' + $oldWorkflows.Count + ' "Anima Reference - ..." workflow file(s)') | |
| Say ' and its helper node. They are not needed any more.' | |
| if (Ask-YesNo ' Remove them?' $false) { | |
| foreach ($file in $oldWorkflows) { Remove-Item -LiteralPath $file.FullName -Force } | |
| if (Test-Path -LiteralPath $oldHelper) { Remove-Item -LiteralPath $oldHelper -Recurse -Force } | |
| Good 'removed' | |
| } else { Say ' left in place' } | |
| } | |
| } | |
| } | |
| # ---- 3. the Gelbooru tag lists ------------------------------------------------------------------ | |
| if ($wantTags) { | |
| Say '' | |
| Say '3. Gelbooru tag lists' | |
| $tagFolder = Join-Path (Join-Path $kritaFolder 'ai_diffusion') 'tags' | |
| try { | |
| if (-not (Test-Path -LiteralPath $tagFolder)) { New-Item -ItemType Directory -Path $tagFolder -Force | Out-Null } | |
| foreach ($file in $TagFiles) { | |
| $target = Join-Path $tagFolder $file | |
| if (Test-Path -LiteralPath $target) { Good ('already there, left as it is: ' + $target) } | |
| else { | |
| Copy-Item -LiteralPath (Join-Path $tagSource $file) -Destination $target -Force | |
| if (Test-Path -LiteralPath $target) { Good ($file + ' -> ' + $tagFolder) } else { Bad ('could not copy ' + $file) } | |
| } | |
| } | |
| } catch { Bad ('could not copy the tag lists: ' + $_.Exception.Message) } | |
| } | |
| Say '' | |
| if ($problems -eq 0) { Say 'Done.' } else { Say ($problems.ToString() + ' step(s) failed - see the FAIL lines above. The rest is in place.') } | |
| Say '' | |
| if ($chosen.Count -gt 0) { | |
| Say 'One step left, inside Krita (only needed the first time):' | |
| Say ' 1. Start Krita.' | |
| Say ' 2. Settings > Configure Krita > Python Plugin Manager' | |
| Say ' 3. Tick these, then press OK:' | |
| foreach ($tool in $chosen) { Say (' ' + $tool.Title) } | |
| Say ' 4. Close Krita and start it again.' | |
| Say '' | |
| Say 'Where they are afterwards:' | |
| foreach ($tool in $chosen) { Say (' ' + $tool.Title + ': ' + $tool.Where) } | |
| } | |
| if ($wantTags) { | |
| Say '' | |
| Say 'Tag lists: in Krita open the AI plugin''s settings (gear button in the AI docker) > Interface >' | |
| Say ' Tag Auto-Completion, and tick "Gelbooru" and "Gelbooru NSFW".' | |
| } | |
| Say '' | |
| Say 'How to use each one: README.txt and the docs folder of this pack.' | |
| } catch { | |
| if ($_.Exception.Message -ne 'stop') { Bad ('Unexpected error: ' + $_.Exception.Message); Say ''; Say 'Nothing more was changed.' } | |
| } | |
| Say '' | |
| if ($problems -gt 0) { exit 1 } else { exit 0 } | |