mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): use graph util for ad-hoc upscale graph
This commit is contained in:
parent
e8d2e2330e
commit
aeb53563ff
@ -1,15 +1,13 @@
|
|||||||
import type { RootState } from 'app/store/store';
|
import type { RootState } from 'app/store/store';
|
||||||
import { fetchModelConfigWithTypeGuard } from 'features/metadata/util/modelFetchingHelpers';
|
import { fetchModelConfigWithTypeGuard } from 'features/metadata/util/modelFetchingHelpers';
|
||||||
|
import type { GraphType } from 'features/nodes/util/graph/generation/Graph';
|
||||||
|
import { Graph } from 'features/nodes/util/graph/generation/Graph';
|
||||||
import { getBoardField } from 'features/nodes/util/graph/graphBuilderUtils';
|
import { getBoardField } from 'features/nodes/util/graph/graphBuilderUtils';
|
||||||
import {
|
import type { ImageDTO } from 'services/api/types';
|
||||||
type ImageDTO,
|
import { isSpandrelImageToImageModelConfig } from 'services/api/types';
|
||||||
type Invocation,
|
|
||||||
isSpandrelImageToImageModelConfig,
|
|
||||||
type NonNullableGraph,
|
|
||||||
} from 'services/api/types';
|
|
||||||
import { assert } from 'tsafe';
|
import { assert } from 'tsafe';
|
||||||
|
|
||||||
import { addCoreMetadataNode, getModelMetadataField, upsertMetadata } from './canvas/metadata';
|
import { getModelMetadataField } from './canvas/metadata';
|
||||||
import { SPANDREL } from './constants';
|
import { SPANDREL } from './constants';
|
||||||
|
|
||||||
type Arg = {
|
type Arg = {
|
||||||
@ -17,32 +15,26 @@ type Arg = {
|
|||||||
state: RootState;
|
state: RootState;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const buildAdHocUpscaleGraph = async ({ image, state }: Arg): Promise<NonNullableGraph> => {
|
export const buildAdHocUpscaleGraph = async ({ image, state }: Arg): Promise<GraphType> => {
|
||||||
const { simpleUpscaleModel } = state.upscale;
|
const { simpleUpscaleModel } = state.upscale;
|
||||||
|
|
||||||
assert(simpleUpscaleModel, 'No upscale model found in state');
|
assert(simpleUpscaleModel, 'No upscale model found in state');
|
||||||
|
|
||||||
const upscaleNode: Invocation<'spandrel_image_to_image'> = {
|
const g = new Graph('adhoc-upscale-graph');
|
||||||
|
g.addNode({
|
||||||
id: SPANDREL,
|
id: SPANDREL,
|
||||||
type: 'spandrel_image_to_image',
|
type: 'spandrel_image_to_image',
|
||||||
image_to_image_model: simpleUpscaleModel,
|
image_to_image_model: simpleUpscaleModel,
|
||||||
image,
|
image,
|
||||||
board: getBoardField(state),
|
board: getBoardField(state),
|
||||||
};
|
is_intermediate: false,
|
||||||
|
});
|
||||||
|
|
||||||
const graph: NonNullableGraph = {
|
|
||||||
id: `adhoc-upscale-graph`,
|
|
||||||
nodes: {
|
|
||||||
[SPANDREL]: upscaleNode,
|
|
||||||
},
|
|
||||||
edges: [],
|
|
||||||
};
|
|
||||||
const modelConfig = await fetchModelConfigWithTypeGuard(simpleUpscaleModel.key, isSpandrelImageToImageModelConfig);
|
const modelConfig = await fetchModelConfigWithTypeGuard(simpleUpscaleModel.key, isSpandrelImageToImageModelConfig);
|
||||||
|
|
||||||
addCoreMetadataNode(graph, {}, SPANDREL);
|
g.upsertMetadata({
|
||||||
upsertMetadata(graph, {
|
|
||||||
upscale_model: getModelMetadataField(modelConfig),
|
upscale_model: getModelMetadataField(modelConfig),
|
||||||
});
|
});
|
||||||
|
|
||||||
return graph;
|
return g.getGraph();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user