From d5b9dd34b70b3f116a4a9fb96486f2a240760a7b Mon Sep 17 00:00:00 2001 From: LenAnderson Date: Mon, 20 Nov 2023 10:16:18 +0000 Subject: [PATCH 01/10] remove unused comfy method --- public/scripts/extensions/stable-diffusion/index.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/public/scripts/extensions/stable-diffusion/index.js b/public/scripts/extensions/stable-diffusion/index.js index c9e2fc29e..6d9aae232 100644 --- a/public/scripts/extensions/stable-diffusion/index.js +++ b/public/scripts/extensions/stable-diffusion/index.js @@ -846,12 +846,6 @@ function onComfyUrlInput() { saveSettingsDebounced(); } -function onComfyPromptInput() { - extension_settings.sd.comfy_prompt = $('#sd_comfy_prompt').val(); - resetScrollHeight($(this)); - saveSettingsDebounced(); -} - async function validateAutoUrl() { try { if (!extension_settings.sd.auto_url) { From 5e5c111d25af72cea8c6511619407d162ca5e4e4 Mon Sep 17 00:00:00 2001 From: LenAnderson Date: Mon, 20 Nov 2023 10:35:11 +0000 Subject: [PATCH 02/10] add VAE selection --- .../stable-diffusion/comfyWorkflowEditor.html | 1 + .../extensions/stable-diffusion/index.js | 69 ++++++++++++++++++- .../extensions/stable-diffusion/settings.html | 4 ++ src/stable-diffusion.js | 18 +++++ 4 files changed, 91 insertions(+), 1 deletion(-) diff --git a/public/scripts/extensions/stable-diffusion/comfyWorkflowEditor.html b/public/scripts/extensions/stable-diffusion/comfyWorkflowEditor.html index e8b438f84..db4e81b13 100644 --- a/public/scripts/extensions/stable-diffusion/comfyWorkflowEditor.html +++ b/public/scripts/extensions/stable-diffusion/comfyWorkflowEditor.html @@ -12,6 +12,7 @@
  • "%prompt%"
  • "%negative_prompt%"
  • "%model%"
  • +
  • "%vae%"
  • "%sampler%"
  • "%scheduler%"
  • "%steps%"
  • diff --git a/public/scripts/extensions/stable-diffusion/index.js b/public/scripts/extensions/stable-diffusion/index.js index 6d9aae232..ad597d2e9 100644 --- a/public/scripts/extensions/stable-diffusion/index.js +++ b/public/scripts/extensions/stable-diffusion/index.js @@ -186,6 +186,7 @@ const defaultSettings = { negative_prompt: defaultNegative, sampler: 'DDIM', model: '', + vae: '', // Automatic1111/Horde exclusives restore_faces: false, @@ -480,7 +481,7 @@ async function loadSettings() { toggleSourceControls(); addPromptTemplates(); - await Promise.all([loadSamplers(), loadModels(), loadSchedulers()]); + await Promise.all([loadSamplers(), loadModels(), loadSchedulers(), loadVaes()]); } function addPromptTemplates() { @@ -914,6 +915,7 @@ async function validateComfyUrl() { await loadSamplers(); await loadSchedulers(); await loadModels(); + await loadVaes(); toastr.success('ComfyUI API connected.'); } catch (error) { toastr.error(`Could not validate ComfyUI API: ${error.message}`); @@ -960,6 +962,10 @@ async function getAutoRemoteModel() { } } +async function onVaeChange() { + extension_settings.sd.vae = $('#sd_vae').find(':selected').val(); +} + async function getAutoRemoteUpscalers() { try { const result = await fetch('/api/sd/upscalers', { @@ -1473,6 +1479,65 @@ async function loadComfySchedulers() { } } +async function loadVaes() { + $('#sd_vae').empty(); + let vaes = []; + + switch (extension_settings.sd.source) { + case sources.extras: + vaes = ['N/A']; + break; + case sources.horde: + vaes = ['N/A']; + break; + case sources.auto: + vaes = ['N/A']; + break; + case sources.novel: + vaes = ['N/A']; + break; + case sources.vlad: + vaes = ['N/A']; + break; + case sources.openai: + vaes = ['N/A']; + break; + case sources.comfy: + vaes = await loadComfyVaes(); + break; + } + + for (const vae of vaes) { + const option = document.createElement('option'); + option.innerText = vae; + option.value = vae; + option.selected = vae === extension_settings.sd.vae; + $('#sd_vae').append(option); + } +} + +async function loadComfyVaes() { + if (!extension_settings.sd.comfy_url) { + return []; + } + + try { + const result = await fetch(`/api/sd/comfy/vaes`, { + method: 'POST', + headers: getRequestHeaders(), + body: JSON.stringify({ + url: extension_settings.sd.comfy_url, + }) + }); + if (!result.ok) { + throw new Error('ComfyUI returned an error.'); + } + return await result.json(); + } catch (error) { + return []; + } +} + function getGenerationType(prompt) { let mode = generationMode.FREE; @@ -2037,6 +2102,7 @@ async function generateComfyImage(prompt) { const placeholders = [ 'negative_prompt', 'model', + 'vae', 'sampler', 'scheduler', 'steps', @@ -2294,6 +2360,7 @@ jQuery(async () => { $('#sd_scale').on('input', onScaleInput); $('#sd_steps').on('input', onStepsInput); $('#sd_model').on('change', onModelChange); + $('#sd_vae').on('change', onVaeChange); $('#sd_sampler').on('change', onSamplerChange); $('#sd_scheduler').on('change', onSchedulerChange); $('#sd_prompt_prefix').on('input', onPromptPrefixInput); diff --git a/public/scripts/extensions/stable-diffusion/settings.html b/public/scripts/extensions/stable-diffusion/settings.html index cb0a20cd4..00a0e3673 100644 --- a/public/scripts/extensions/stable-diffusion/settings.html +++ b/public/scripts/extensions/stable-diffusion/settings.html @@ -150,6 +150,10 @@ +
    + + +