fix(ui): fix batch metadata logic when graph has no metadata

On canvas, images have no metadata yet, so this needs to be handled
This commit is contained in:
psychedelicious 2023-10-18 22:33:17 +11:00
parent 52fbd1b222
commit 301a8fef92
2 changed files with 50 additions and 32 deletions

View File

@ -11,7 +11,7 @@ import {
NOISE, NOISE,
POSITIVE_CONDITIONING, POSITIVE_CONDITIONING,
} from './constants'; } from './constants';
import { removeMetadata } from './metadata'; import { getHasMetadata, removeMetadata } from './metadata';
export const prepareLinearUIBatch = ( export const prepareLinearUIBatch = (
state: RootState, state: RootState,
@ -40,13 +40,15 @@ export const prepareLinearUIBatch = (
}); });
} }
// add to metadata if (getHasMetadata(graph)) {
removeMetadata(graph, 'seed'); // add to metadata
zipped.push({ removeMetadata(graph, 'seed');
node_path: METADATA, zipped.push({
field_name: 'seed', node_path: METADATA,
items: seeds, field_name: 'seed',
}); items: seeds,
});
}
if (graph.nodes[CANVAS_COHERENCE_NOISE]) { if (graph.nodes[CANVAS_COHERENCE_NOISE]) {
zipped.push({ zipped.push({
@ -78,12 +80,14 @@ export const prepareLinearUIBatch = (
} }
// add to metadata // add to metadata
removeMetadata(graph, 'seed'); if (getHasMetadata(graph)) {
firstBatchDatumList.push({ removeMetadata(graph, 'seed');
node_path: METADATA, firstBatchDatumList.push({
field_name: 'seed', node_path: METADATA,
items: seeds, field_name: 'seed',
}); items: seeds,
});
}
if (graph.nodes[CANVAS_COHERENCE_NOISE]) { if (graph.nodes[CANVAS_COHERENCE_NOISE]) {
firstBatchDatumList.push({ firstBatchDatumList.push({
@ -108,12 +112,14 @@ export const prepareLinearUIBatch = (
} }
// add to metadata // add to metadata
removeMetadata(graph, 'seed'); if (getHasMetadata(graph)) {
secondBatchDatumList.push({ removeMetadata(graph, 'seed');
node_path: METADATA, secondBatchDatumList.push({
field_name: 'seed', node_path: METADATA,
items: seeds, field_name: 'seed',
}); items: seeds,
});
}
if (graph.nodes[CANVAS_COHERENCE_NOISE]) { if (graph.nodes[CANVAS_COHERENCE_NOISE]) {
secondBatchDatumList.push({ secondBatchDatumList.push({
@ -140,12 +146,14 @@ export const prepareLinearUIBatch = (
} }
// add to metadata // add to metadata
removeMetadata(graph, 'positive_prompt'); if (getHasMetadata(graph)) {
firstBatchDatumList.push({ removeMetadata(graph, 'positive_prompt');
node_path: METADATA, firstBatchDatumList.push({
field_name: 'positive_prompt', node_path: METADATA,
items: extendedPrompts, field_name: 'positive_prompt',
}); items: extendedPrompts,
});
}
if (shouldConcatSDXLStylePrompt && model?.base_model === 'sdxl') { if (shouldConcatSDXLStylePrompt && model?.base_model === 'sdxl') {
const stylePrompts = extendedPrompts.map((p) => const stylePrompts = extendedPrompts.map((p) =>
@ -161,12 +169,14 @@ export const prepareLinearUIBatch = (
} }
// add to metadata // add to metadata
removeMetadata(graph, 'positive_style_prompt'); if (getHasMetadata(graph)) {
firstBatchDatumList.push({ removeMetadata(graph, 'positive_style_prompt');
node_path: METADATA, firstBatchDatumList.push({
field_name: 'positive_style_prompt', node_path: METADATA,
items: extendedPrompts, field_name: 'positive_style_prompt',
}); items: extendedPrompts,
});
}
} }
data.push(firstBatchDatumList); data.push(firstBatchDatumList);

View File

@ -56,3 +56,11 @@ export const removeMetadata = (
delete metadataNode[key]; delete metadataNode[key];
}; };
export const getHasMetadata = (graph: NonNullableGraph): boolean => {
const metadataNode = graph.nodes[METADATA] as
| CoreMetadataInvocation
| undefined;
return Boolean(metadataNode);
};