Skip to content

Commit 3d29c99

Browse files
feat(ui): support img2img for chatgpt 4o w/ ref images
1 parent 42d57d1 commit 3d29c99

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

invokeai/frontend/web/public/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@
13231323
"unableToCopyDesc_theseSteps": "these steps",
13241324
"fluxFillIncompatibleWithT2IAndI2I": "FLUX Fill is not compatible with Text to Image or Image to Image. Use other FLUX models for these tasks.",
13251325
"imagen3IncompatibleGenerationMode": "Google Imagen3 supports Text to Image only. Ensure the bounding box is empty, or use other models for Image to Image, Inpainting and Outpainting tasks.",
1326-
"chatGPT4oIncompatibleGenerationMode": "ChatGPT 4o supports Text to Image only. Ensure the bounding box is empty, or use other models for Image to Image, Inpainting and Outpainting tasks.",
1326+
"chatGPT4oIncompatibleGenerationMode": "ChatGPT 4o supports Text to Image and Image to Image. Use other models Inpainting and Outpainting tasks.",
13271327
"problemUnpublishingWorkflow": "Problem Unpublishing Workflow",
13281328
"problemUnpublishingWorkflowDescription": "There was a problem unpublishing the workflow. Please try again.",
13291329
"workflowUnpublished": "Workflow Unpublished"

invokeai/frontend/web/src/features/nodes/util/graph/generation/buildChatGPT4oGraph.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const log = logger('system');
2424
export const buildChatGPT4oGraph = async (state: RootState, manager: CanvasManager): Promise<GraphBuilderReturn> => {
2525
const generationMode = await manager.compositor.getGenerationMode();
2626

27-
assert(generationMode === 'txt2img', t('toast.chatGPT4oIncompatibleGenerationMode'));
27+
assert(generationMode === 'txt2img' || generationMode === 'img2img', t('toast.chatGPT4oIncompatibleGenerationMode'));
2828

2929
log.debug({ generationMode }, 'Building GPT Image graph');
3030

@@ -80,5 +80,30 @@ export const buildChatGPT4oGraph = async (state: RootState, manager: CanvasManag
8080
};
8181
}
8282

83-
assert<Equals<typeof generationMode, never>>(false, 'Invalid generation mode for ChatGPT 4o');
83+
if (generationMode === 'img2img') {
84+
const adapters = manager.compositor.getVisibleAdaptersOfType('raster_layer');
85+
const { image_name } = await manager.compositor.getCompositeImageDTO(adapters, bbox.rect, {
86+
is_intermediate: true,
87+
silent: true,
88+
});
89+
const g = new Graph(getPrefixedId('chatgpt_4o_img2img_graph'));
90+
const gptImage = g.addNode({
91+
// @ts-expect-error: These nodes are not available in the OSS application
92+
type: 'chatgpt_4o_edit_image',
93+
id: getPrefixedId(CANVAS_OUTPUT_PREFIX),
94+
positive_prompt: positivePrompt,
95+
aspect_ratio: bbox.aspectRatio.id,
96+
base_image: { image_name },
97+
reference_images,
98+
use_cache: false,
99+
is_intermediate,
100+
board,
101+
});
102+
return {
103+
g,
104+
positivePromptFieldIdentifier: { nodeId: gptImage.id, fieldName: 'positive_prompt' },
105+
};
106+
}
107+
108+
assert<Equals<typeof generationMode, never>>(false, 'Invalid generation mode for ChatGPT ');
84109
};

0 commit comments

Comments
 (0)