feat(ui): do not add promptless conditioning nodes

This commit is contained in:
psychedelicious 2024-04-19 08:38:22 +10:00 committed by Kent Keirsey
parent a6e64423d9
commit 964e2236b9

View File

@ -107,6 +107,10 @@ export const addRegionalPromptsToGraph = async (state: RootState, graph: NonNull
const layer = layers.find((l) => l.id === layerId);
assert(layer, `Layer ${layerId} not found`);
if (!layer.positivePrompt && !layer.negativePrompt) {
continue;
}
const file = new File([blob], `${layerId}_mask.png`, { type: 'image/png' });
const req = dispatch(
imagesApi.endpoints.uploadImage.initiate({ file, image_category: 'mask', is_intermediate: true })
@ -145,6 +149,7 @@ export const addRegionalPromptsToGraph = async (state: RootState, graph: NonNull
},
});
if (layer.positivePrompt) {
// The main positive conditioning node
const regionalPositiveCondNode: S['SDXLCompelPromptInvocation'] = {
type: 'sdxl_compel_prompt',
@ -166,6 +171,18 @@ export const addRegionalPromptsToGraph = async (state: RootState, graph: NonNull
destination: { node_id: posCondCollectNode.id, field: 'item' },
});
// Copy the connections to the "global" positive conditioning node to the regional cond
for (const edge of graph.edges) {
if (edge.destination.node_id === POSITIVE_CONDITIONING && edge.destination.field !== 'prompt') {
graph.edges.push({
source: edge.source,
destination: { node_id: regionalPositiveCondNode.id, field: edge.destination.field },
});
}
}
}
if (layer.negativePrompt) {
// The main negative conditioning node
const regionalNegativeCondNode: S['SDXLCompelPromptInvocation'] = {
type: 'sdxl_compel_prompt',
@ -187,14 +204,8 @@ export const addRegionalPromptsToGraph = async (state: RootState, graph: NonNull
destination: { node_id: negCondCollectNode.id, field: 'item' },
});
// Copy the connections to the "global" positive and negative conditioning nodes to our regional nodes
// Copy the connections to the "global" negative conditioning node to the regional cond
for (const edge of graph.edges) {
if (edge.destination.node_id === POSITIVE_CONDITIONING && edge.destination.field !== 'prompt') {
graph.edges.push({
source: edge.source,
destination: { node_id: regionalPositiveCondNode.id, field: edge.destination.field },
});
}
if (edge.destination.node_id === NEGATIVE_CONDITIONING && edge.destination.field !== 'prompt') {
graph.edges.push({
source: edge.source,
@ -202,9 +213,10 @@ export const addRegionalPromptsToGraph = async (state: RootState, graph: NonNull
});
}
}
}
// If we are using the "invert" auto-negative setting, we need to add an additional negative conditioning node
if (layer.autoNegative === 'invert') {
if (layer.autoNegative === 'invert' && layer.positivePrompt) {
// We re-use the mask image, but invert it when converting to tensor
// TODO: Probably faster to invert the tensor from the earlier mask rather than read the mask image and convert...
const invertedMaskToTensorNode: S['AlphaMaskToTensorInvocation'] = {