recall initial image from metadata and set to image2image

This commit is contained in:
Jennifer Player 2024-04-04 10:56:25 -04:00 committed by psychedelicious
parent f56b9537cd
commit 8a17616bf4
4 changed files with 28 additions and 0 deletions

View File

@ -189,6 +189,11 @@ export const handlers = {
recaller: recallers.cfgScale, recaller: recallers.cfgScale,
}), }),
height: buildHandlers({ getLabel: () => t('metadata.height'), parser: parsers.height, recaller: recallers.height }), height: buildHandlers({ getLabel: () => t('metadata.height'), parser: parsers.height, recaller: recallers.height }),
initialImage: buildHandlers({
getLabel: () => t('metadata.initImage'),
parser: parsers.initialImage,
recaller: recallers.initialImage,
}),
negativePrompt: buildHandlers({ negativePrompt: buildHandlers({
getLabel: () => t('metadata.negativePrompt'), getLabel: () => t('metadata.negativePrompt'),
parser: parsers.negativePrompt, parser: parsers.negativePrompt,

View File

@ -20,6 +20,7 @@ import type {
ParameterHeight, ParameterHeight,
ParameterHRFEnabled, ParameterHRFEnabled,
ParameterHRFMethod, ParameterHRFMethod,
ParameterInitialImage,
ParameterModel, ParameterModel,
ParameterNegativePrompt, ParameterNegativePrompt,
ParameterNegativeStylePromptSDXL, ParameterNegativeStylePromptSDXL,
@ -135,6 +136,9 @@ const parseCFGRescaleMultiplier: MetadataParseFunc<ParameterCFGRescaleMultiplier
const parseScheduler: MetadataParseFunc<ParameterScheduler> = (metadata) => const parseScheduler: MetadataParseFunc<ParameterScheduler> = (metadata) =>
getProperty(metadata, 'scheduler', isParameterScheduler); getProperty(metadata, 'scheduler', isParameterScheduler);
const parseInitialImage: MetadataParseFunc<ParameterInitialImage> = (metadata) =>
getProperty(metadata, 'init_image', isString);
const parseWidth: MetadataParseFunc<ParameterWidth> = (metadata) => getProperty(metadata, 'width', isParameterWidth); const parseWidth: MetadataParseFunc<ParameterWidth> = (metadata) => getProperty(metadata, 'width', isParameterWidth);
const parseHeight: MetadataParseFunc<ParameterHeight> = (metadata) => const parseHeight: MetadataParseFunc<ParameterHeight> = (metadata) =>
@ -402,6 +406,7 @@ export const parsers = {
cfgScale: parseCFGScale, cfgScale: parseCFGScale,
cfgRescaleMultiplier: parseCFGRescaleMultiplier, cfgRescaleMultiplier: parseCFGRescaleMultiplier,
scheduler: parseScheduler, scheduler: parseScheduler,
initialImage: parseInitialImage,
width: parseWidth, width: parseWidth,
height: parseHeight, height: parseHeight,
steps: parseSteps, steps: parseSteps,

View File

@ -17,6 +17,7 @@ import type {
import { modelSelected } from 'features/parameters/store/actions'; import { modelSelected } from 'features/parameters/store/actions';
import { import {
heightRecalled, heightRecalled,
initialImageChanged,
setCfgRescaleMultiplier, setCfgRescaleMultiplier,
setCfgScale, setCfgScale,
setImg2imgStrength, setImg2imgStrength,
@ -34,6 +35,7 @@ import type {
ParameterHeight, ParameterHeight,
ParameterHRFEnabled, ParameterHRFEnabled,
ParameterHRFMethod, ParameterHRFMethod,
ParameterInitialImage,
ParameterModel, ParameterModel,
ParameterNegativePrompt, ParameterNegativePrompt,
ParameterNegativeStylePromptSDXL, ParameterNegativeStylePromptSDXL,
@ -61,6 +63,7 @@ import {
setRefinerStart, setRefinerStart,
setRefinerSteps, setRefinerSteps,
} from 'features/sdxl/store/sdxlSlice'; } from 'features/sdxl/store/sdxlSlice';
import type { ImageDTO } from 'services/api/types';
const recallPositivePrompt: MetadataRecallFunc<ParameterPositivePrompt> = (positivePrompt) => { const recallPositivePrompt: MetadataRecallFunc<ParameterPositivePrompt> = (positivePrompt) => {
getStore().dispatch(setPositivePrompt(positivePrompt)); getStore().dispatch(setPositivePrompt(positivePrompt));
@ -94,6 +97,13 @@ const recallScheduler: MetadataRecallFunc<ParameterScheduler> = (scheduler) => {
getStore().dispatch(setScheduler(scheduler)); getStore().dispatch(setScheduler(scheduler));
}; };
const recallInitialImage: MetadataRecallFunc<ParameterInitialImage> = (initialImage) => {
const image = {
image_name: initialImage,
};
getStore().dispatch(initialImageChanged(image as ImageDTO));
};
const recallWidth: MetadataRecallFunc<ParameterWidth> = (width) => { const recallWidth: MetadataRecallFunc<ParameterWidth> = (width) => {
getStore().dispatch(widthRecalled(width)); getStore().dispatch(widthRecalled(width));
}; };
@ -235,6 +245,7 @@ export const recallers = {
cfgScale: recallCFGScale, cfgScale: recallCFGScale,
cfgRescaleMultiplier: recallCFGRescaleMultiplier, cfgRescaleMultiplier: recallCFGRescaleMultiplier,
scheduler: recallScheduler, scheduler: recallScheduler,
initialImage: recallInitialImage,
width: recallWidth, width: recallWidth,
height: recallHeight, height: recallHeight,
steps: recallSteps, steps: recallSteps,

View File

@ -126,6 +126,13 @@ const zParameterT2IAdapterModel = zModelIdentifierField;
export type ParameterT2IAdapterModel = z.infer<typeof zParameterT2IAdapterModel>; export type ParameterT2IAdapterModel = z.infer<typeof zParameterT2IAdapterModel>;
// #endregion // #endregion
// #region I2I Initial Image
const zParameterInitialImage = z.string();
export type ParameterInitialImage = z.infer<typeof zParameterInitialImage>;
export const isParameterInitialImage = (val: unknown): val is ParameterInitialImage =>
zParameterInitialImage.safeParse(val).success;
// #endregion
// #region Strength (l2l strength) // #region Strength (l2l strength)
const zParameterStrength = z.number().min(0).max(1); const zParameterStrength = z.number().min(0).max(1);
export type ParameterStrength = z.infer<typeof zParameterStrength>; export type ParameterStrength = z.infer<typeof zParameterStrength>;