fix(ui): check for metadata accumulator before connecting to it

This commit is contained in:
psychedelicious 2023-07-13 20:05:45 +10:00
parent 4702eb2e6a
commit 43cc96255b
4 changed files with 31 additions and 23 deletions

View File

@ -19,9 +19,9 @@ export const addControlNetToLinearGraph = (
const validControlNets = getValidControlNets(controlNets); const validControlNets = getValidControlNets(controlNets);
const metadataAccumulator = graph.nodes[ const metadataAccumulator = graph.nodes[METADATA_ACCUMULATOR] as
METADATA_ACCUMULATOR | MetadataAccumulatorInvocation
] as MetadataAccumulatorInvocation; | undefined;
if (isControlNetEnabled && Boolean(validControlNets.length)) { if (isControlNetEnabled && Boolean(validControlNets.length)) {
if (validControlNets.length) { if (validControlNets.length) {
@ -79,6 +79,7 @@ export const addControlNetToLinearGraph = (
graph.nodes[controlNetNode.id] = controlNetNode; graph.nodes[controlNetNode.id] = controlNetNode;
if (metadataAccumulator) {
// metadata accumulator only needs a control field - not the whole node // metadata accumulator only needs a control field - not the whole node
// extract what we need and add to the accumulator // extract what we need and add to the accumulator
const controlField = omit(controlNetNode, [ const controlField = omit(controlNetNode, [
@ -86,6 +87,7 @@ export const addControlNetToLinearGraph = (
'type', 'type',
]) as ControlField; ]) as ControlField;
metadataAccumulator.controlnets.push(controlField); metadataAccumulator.controlnets.push(controlField);
}
graph.edges.push({ graph.edges.push({
source: { node_id: controlNetNode.id, field: 'control' }, source: { node_id: controlNetNode.id, field: 'control' },

View File

@ -32,9 +32,9 @@ export const addDynamicPromptsToGraph = (
maxPrompts, maxPrompts,
} = state.dynamicPrompts; } = state.dynamicPrompts;
const metadataAccumulator = graph.nodes[ const metadataAccumulator = graph.nodes[METADATA_ACCUMULATOR] as
METADATA_ACCUMULATOR | MetadataAccumulatorInvocation
] as MetadataAccumulatorInvocation; | undefined;
if (isDynamicPromptsEnabled) { if (isDynamicPromptsEnabled) {
// iteration is handled via dynamic prompts // iteration is handled via dynamic prompts
@ -116,11 +116,15 @@ export const addDynamicPromptsToGraph = (
(graph.nodes[NOISE] as NoiseInvocation).seed = seed; (graph.nodes[NOISE] as NoiseInvocation).seed = seed;
// hook up seed to metadata // hook up seed to metadata
if (metadataAccumulator) {
metadataAccumulator.seed = seed; metadataAccumulator.seed = seed;
} }
}
} else { } else {
// no dynamic prompt - hook up positive prompt // no dynamic prompt - hook up positive prompt
if (metadataAccumulator) {
metadataAccumulator.positive_prompt = positivePrompt; metadataAccumulator.positive_prompt = positivePrompt;
}
const rangeOfSizeNode: RangeOfSizeInvocation = { const rangeOfSizeNode: RangeOfSizeInvocation = {
id: RANGE_OF_SIZE, id: RANGE_OF_SIZE,

View File

@ -30,9 +30,9 @@ export const addLoRAsToGraph = (
const { loras } = state.lora; const { loras } = state.lora;
const loraCount = size(loras); const loraCount = size(loras);
const metadataAccumulator = graph.nodes[ const metadataAccumulator = graph.nodes[METADATA_ACCUMULATOR] as
METADATA_ACCUMULATOR | MetadataAccumulatorInvocation
] as MetadataAccumulatorInvocation; | undefined;
if (loraCount > 0) { if (loraCount > 0) {
// Remove MAIN_MODEL_LOADER unet connection to feed it to LoRAs // Remove MAIN_MODEL_LOADER unet connection to feed it to LoRAs
@ -70,7 +70,9 @@ export const addLoRAsToGraph = (
}; };
// add the lora to the metadata accumulator // add the lora to the metadata accumulator
if (metadataAccumulator) {
metadataAccumulator.loras.push({ lora: loraField, weight }); metadataAccumulator.loras.push({ lora: loraField, weight });
}
// add to graph // add to graph
graph.nodes[currentLoraNodeId] = loraLoaderNode; graph.nodes[currentLoraNodeId] = loraLoaderNode;

View File

@ -22,9 +22,9 @@ export const addVAEToGraph = (
const vae_model = modelIdToVAEModelField(vae?.id || ''); const vae_model = modelIdToVAEModelField(vae?.id || '');
const isAutoVae = !vae; const isAutoVae = !vae;
const metadataAccumulator = graph.nodes[ const metadataAccumulator = graph.nodes[METADATA_ACCUMULATOR] as
METADATA_ACCUMULATOR | MetadataAccumulatorInvocation
] as MetadataAccumulatorInvocation; | undefined;
if (!isAutoVae) { if (!isAutoVae) {
graph.nodes[VAE_LOADER] = { graph.nodes[VAE_LOADER] = {
@ -73,7 +73,7 @@ export const addVAEToGraph = (
}); });
} }
if (vae) { if (vae && metadataAccumulator) {
metadataAccumulator.vae = vae_model; metadataAccumulator.vae = vae_model;
} }
}; };