Add GGUF models and denoise parameter for ComfyUI

This commit is contained in:
ceruleandeep 2024-11-18 17:55:30 +11:00
parent 61469ec999
commit 5992117904
4 changed files with 34 additions and 15 deletions

View File

@ -17,6 +17,7 @@
<li data-placeholder="scheduler" class="sd_comfy_workflow_editor_not_found">"%scheduler%"</li>
<li data-placeholder="steps" class="sd_comfy_workflow_editor_not_found">"%steps%"</li>
<li data-placeholder="scale" class="sd_comfy_workflow_editor_not_found">"%scale%"</li>
<li data-placeholder="denoise" class="sd_comfy_workflow_editor_not_found">"%denoise%"</li>
<li data-placeholder="clip_skip" class="sd_comfy_workflow_editor_not_found">"%clip_skip%"</li>
<li data-placeholder="width" class="sd_comfy_workflow_editor_not_found">"%width%"</li>
<li data-placeholder="height" class="sd_comfy_workflow_editor_not_found">"%height%"</li>

View File

@ -3269,6 +3269,10 @@ async function generateComfyImage(prompt, negativePrompt, signal) {
const seed = extension_settings.sd.seed >= 0 ? extension_settings.sd.seed : Math.round(Math.random() * Number.MAX_SAFE_INTEGER);
workflow = workflow.replaceAll('"%seed%"', JSON.stringify(seed));
const denoising_strength = extension_settings.sd.denoising_strength === undefined ? 1.0 : extension_settings.sd.denoising_strength;
workflow = workflow.replaceAll('"%denoise%"', JSON.stringify(denoising_strength));
placeholders.forEach(ph => {
workflow = workflow.replaceAll(`"%${ph}%"`, JSON.stringify(extension_settings.sd[ph]));
});

View File

@ -319,7 +319,7 @@
<input class="neo-range-input" type="number" id="sd_hr_scale_value" data-for="sd_hr_scale" min="{{hr_scale_min}}" max="{{hr_scale_max}}" step="{{hr_scale_step}}" value="{{hr_scale}}" >
</div>
<div class="alignitemscenter flex-container flexFlowColumn flexGrow flexShrink gap0 flexBasis48p" data-sd-source="auto,vlad">
<div class="alignitemscenter flex-container flexFlowColumn flexGrow flexShrink gap0 flexBasis48p" data-sd-source="auto,vlad,comfy">
<small>
<span data-i18n="Denoising strength">Denoising strength</span>
</small>

View File

@ -7,7 +7,7 @@ import sanitize from 'sanitize-filename';
import { sync as writeFileAtomicSync } from 'write-file-atomic';
import FormData from 'form-data';
import { getBasicAuthHeader, delay } from '../util.js';
import { delay, getBasicAuthHeader } from '../util.js';
import { jsonParser } from '../express-common.js';
import { readSecret, SECRET_KEYS } from './secrets.js';
@ -19,7 +19,7 @@ import { readSecret, SECRET_KEYS } from './secrets.js';
function getComfyWorkflows(directories) {
return fs
.readdirSync(directories.comfyWorkflows)
.filter(file => file[0] != '.' && file.toLowerCase().endsWith('.json'))
.filter(file => file[0] !== '.' && file.toLowerCase().endsWith('.json'))
.sort(Intl.Collator().compare);
}
@ -67,8 +67,7 @@ router.post('/upscalers', jsonParser, async (request, response) => {
/** @type {any} */
const data = await result.json();
const names = data.map(x => x.name);
return names;
return data.map(x => x.name);
}
async function getLatentUpscalers() {
@ -88,8 +87,7 @@ router.post('/upscalers', jsonParser, async (request, response) => {
/** @type {any} */
const data = await result.json();
const names = data.map(x => x.name);
return names;
return data.map(x => x.name);
}
const [upscalers, latentUpscalers] = await Promise.all([getUpscalerModels(), getLatentUpscalers()]);
@ -241,8 +239,7 @@ router.post('/set-model', jsonParser, async (request, response) => {
'Authorization': getBasicAuthHeader(request.body.auth),
},
});
const data = await result.json();
return data;
return await result.json();
}
const url = new URL(request.body.url);
@ -274,7 +271,7 @@ router.post('/set-model', jsonParser, async (request, response) => {
const progress = progressState['progress'];
const jobCount = progressState['state']['job_count'];
if (progress == 0.0 && jobCount === 0) {
if (progress === 0.0 && jobCount === 0) {
break;
}
@ -412,7 +409,17 @@ comfy.post('/models', jsonParser, async (request, response) => {
}
/** @type {any} */
const data = await result.json();
return response.send(data.CheckpointLoaderSimple.input.required.ckpt_name[0].map(it => ({ value: it, text: it })));
const ckpts = data.CheckpointLoaderSimple.input.required.ckpt_name[0].map(it => ({ value: it, text: it })) || [];
// load list of GGUF unets from diffusion_models if the loader node is available
const ggufs = data.UnetLoaderGGUF?.input.required.unet_name[0].map(it => ({ value: it, text: `GGUF: ${it}` })) || [];
const models = ckpts.concat(ggufs);
// make the display names of the models somewhat presentable
models.forEach(it => it.text = it.text.replace(/\.[^.]*$/, '').replace(/_/g, ' '));
return response.send(models);
} catch (error) {
console.log(error);
return response.sendStatus(500);
@ -550,7 +557,13 @@ comfy.post('/generate', jsonParser, async (request, response) => {
await delay(100);
}
if (item.status.status_str === 'error') {
throw new Error('ComfyUI generation did not succeed.');
// Report node tracebacks if available
const errorMessages = item.status?.messages
?.filter(it => it[0] === 'execution_error')
.map(it => it[1])
.map(it => `${it.node_type} [${it.node_id}] ${it.exception_type}: ${it.exception_message}`)
.join('\n') || '';
throw new Error(`ComfyUI generation did not succeed.\n\n${errorMessages}`.trim());
}
const imgInfo = Object.keys(item.outputs).map(it => item.outputs[it].images).flat()[0];
const imgUrl = new URL(request.body.url);
@ -563,8 +576,9 @@ comfy.post('/generate', jsonParser, async (request, response) => {
const imgBuffer = await imgResponse.buffer();
return response.send(imgBuffer.toString('base64'));
} catch (error) {
console.log(error);
return response.sendStatus(500);
console.log('ComfyUI error:', error);
response.status(500).send(`${error.message}`);
return response;
}
});