|
1 | 1 | import type { RootState } from 'app/store/store';
|
2 |
| -import { getBoardField } from 'features/nodes/util/graph/graphBuilderUtils'; |
3 |
| -import type { Graph, Invocation, NonNullableGraph } from 'services/api/types'; |
| 2 | +import { fetchModelConfigWithTypeGuard } from 'features/metadata/util/modelFetchingHelpers'; |
| 3 | +import { |
| 4 | + type ImageDTO, |
| 5 | + type Invocation, |
| 6 | + isSpandrelImageToImageModelConfig, |
| 7 | + type NonNullableGraph, |
| 8 | +} from 'services/api/types'; |
| 9 | +import { assert } from 'tsafe'; |
4 | 10 |
|
5 |
| -import { addCoreMetadataNode, upsertMetadata } from './canvas/metadata'; |
6 |
| -import { ESRGAN } from './constants'; |
| 11 | +import { addCoreMetadataNode, getModelMetadataField, upsertMetadata } from './canvas/metadata'; |
| 12 | +import { SPANDREL } from './constants'; |
7 | 13 |
|
8 | 14 | type Arg = {
|
9 |
| - image_name: string; |
| 15 | + image: ImageDTO; |
10 | 16 | state: RootState;
|
11 | 17 | };
|
12 | 18 |
|
13 |
| -export const buildAdHocUpscaleGraph = ({ image_name, state }: Arg): Graph => { |
14 |
| - const { esrganModelName } = state.postprocessing; |
| 19 | +export const buildAdHocUpscaleGraph = async ({ image, state }: Arg): Promise<NonNullableGraph> => { |
| 20 | + const { simpleUpscaleModel } = state.upscale; |
15 | 21 |
|
16 |
| - const realesrganNode: Invocation<'esrgan'> = { |
17 |
| - id: ESRGAN, |
18 |
| - type: 'esrgan', |
19 |
| - image: { image_name }, |
20 |
| - model_name: esrganModelName, |
21 |
| - is_intermediate: false, |
22 |
| - board: getBoardField(state), |
| 22 | + assert(simpleUpscaleModel, 'No upscale model found in state'); |
| 23 | + |
| 24 | + const upscaleNode: Invocation<'spandrel_image_to_image'> = { |
| 25 | + id: SPANDREL, |
| 26 | + type: 'spandrel_image_to_image', |
| 27 | + image_to_image_model: simpleUpscaleModel, |
| 28 | + tile_size: 500, |
| 29 | + image, |
23 | 30 | };
|
24 | 31 |
|
25 | 32 | const graph: NonNullableGraph = {
|
26 |
| - id: `adhoc-esrgan-graph`, |
| 33 | + id: `adhoc-upscale-graph`, |
27 | 34 | nodes: {
|
28 |
| - [ESRGAN]: realesrganNode, |
| 35 | + [SPANDREL]: upscaleNode, |
29 | 36 | },
|
30 | 37 | edges: [],
|
31 | 38 | };
|
| 39 | + const modelConfig = await fetchModelConfigWithTypeGuard(simpleUpscaleModel.key, isSpandrelImageToImageModelConfig); |
32 | 40 |
|
33 |
| - addCoreMetadataNode(graph, {}, ESRGAN); |
| 41 | + addCoreMetadataNode(graph, {}, SPANDREL); |
34 | 42 | upsertMetadata(graph, {
|
35 |
| - esrgan_model: esrganModelName, |
| 43 | + upscale_model: getModelMetadataField(modelConfig), |
36 | 44 | });
|
37 | 45 |
|
38 | 46 | return graph;
|
|
0 commit comments