feat: Auto Change Dimensions on Model Switch by Type

This commit is contained in:
blessedcoolant 2023-08-30 05:49:57 +12:00
parent f5c5f59220
commit 4fd4aee2ab
7 changed files with 43 additions and 3 deletions

View File

@ -570,6 +570,7 @@
"useSlidersForAll": "Use Sliders For All Options",
"showProgressInViewer": "Show Progress Images in Viewer",
"antialiasProgressImages": "Antialias Progress Images",
"autoChangeDimensions": "Update W/H To Model Defaults On Change",
"resetWebUI": "Reset Web UI",
"resetWebUIDesc1": "Resetting the web UI only resets the browser's local cache of your images and remembered settings. It does not delete any images from disk.",
"resetWebUIDesc2": "If images aren't showing up in the gallery or something else isn't working, please try resetting before submitting an issue on GitHub.",

View File

@ -1,9 +1,12 @@
import { logger } from 'app/logging/logger';
import { setBoundingBoxDimensions } from 'features/canvas/store/canvasSlice';
import { controlNetRemoved } from 'features/controlNet/store/controlNetSlice';
import { loraRemoved } from 'features/lora/store/loraSlice';
import { modelSelected } from 'features/parameters/store/actions';
import {
modelChanged,
setHeight,
setWidth,
vaeSelected,
} from 'features/parameters/store/generationSlice';
import { zMainOrOnnxModel } from 'features/parameters/types/parameterSchemas';
@ -74,6 +77,22 @@ export const addModelSelectedListener = () => {
}
}
// Update Width / Height / Bounding Box Dimensions on Model Change
if (
state.generation.model?.base_model !== newModel.base_model &&
state.ui.shouldAutoChangeDimensions
) {
if (['sdxl', 'sdxl-refiner'].includes(newModel.base_model)) {
dispatch(setWidth(1024));
dispatch(setHeight(1024));
dispatch(setBoundingBoxDimensions({ width: 1024, height: 1024 }));
} else {
dispatch(setWidth(512));
dispatch(setHeight(512));
dispatch(setBoundingBoxDimensions({ width: 512, height: 512 }));
}
}
dispatch(modelChanged(newModel));
},
});

View File

@ -71,7 +71,7 @@ const ParamBoundingBoxWidth = () => {
<IAISlider
label={t('parameters.boundingBoxHeight')}
min={64}
max={1024}
max={1536}
step={64}
value={boundingBoxDimensions.height}
onChange={handleChangeHeight}

View File

@ -71,7 +71,7 @@ const ParamBoundingBoxWidth = () => {
<IAISlider
label={t('parameters.boundingBoxWidth')}
min={64}
max={1024}
max={1536}
step={64}
value={boundingBoxDimensions.width}
onChange={handleChangeWidth}

View File

@ -30,6 +30,7 @@ import {
shouldUseWatermarkerChanged,
} from 'features/system/store/systemSlice';
import {
setShouldAutoChangeDimensions,
setShouldShowProgressInViewer,
setShouldUseSliders,
} from 'features/ui/store/uiSlice';
@ -68,7 +69,11 @@ const selector = createSelector(
shouldUseWatermarker,
} = system;
const { shouldUseSliders, shouldShowProgressInViewer } = ui;
const {
shouldUseSliders,
shouldShowProgressInViewer,
shouldAutoChangeDimensions,
} = ui;
const { shouldShowAdvancedOptions } = generation;
@ -83,6 +88,7 @@ const selector = createSelector(
shouldShowAdvancedOptions,
shouldUseNSFWChecker,
shouldUseWatermarker,
shouldAutoChangeDimensions,
};
},
{
@ -158,6 +164,7 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => {
shouldShowAdvancedOptions,
shouldUseNSFWChecker,
shouldUseWatermarker,
shouldAutoChangeDimensions,
} = useAppSelector(selector);
const handleClickResetWebUI = useCallback(() => {
@ -297,6 +304,13 @@ const SettingsModal = ({ children, config }: SettingsModalProps) => {
)
}
/>
<SettingSwitch
label={t('settings.autoChangeDimensions')}
isChecked={shouldAutoChangeDimensions}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
dispatch(setShouldAutoChangeDimensions(e.target.checked))
}
/>
{shouldShowLocalizationToggle && (
<IAIMantineSelect
disabled={!isLocalizationEnabled}

View File

@ -15,6 +15,7 @@ export const initialUIState: UIState = {
shouldHidePreview: false,
shouldShowProgressInViewer: true,
shouldShowEmbeddingPicker: false,
shouldAutoChangeDimensions: false,
favoriteSchedulers: [],
globalContextMenuCloseTrigger: 0,
panels: {},
@ -57,6 +58,9 @@ export const uiSlice = createSlice({
toggleEmbeddingPicker: (state) => {
state.shouldShowEmbeddingPicker = !state.shouldShowEmbeddingPicker;
},
setShouldAutoChangeDimensions: (state, action: PayloadAction<boolean>) => {
state.shouldAutoChangeDimensions = action.payload;
},
contextMenusClosed: (state) => {
state.globalContextMenuCloseTrigger += 1;
},
@ -84,6 +88,7 @@ export const {
setShouldShowProgressInViewer,
favoriteSchedulersChanged,
toggleEmbeddingPicker,
setShouldAutoChangeDimensions,
contextMenusClosed,
panelsChanged,
} = uiSlice.actions;

View File

@ -21,6 +21,7 @@ export interface UIState {
shouldHidePreview: boolean;
shouldShowProgressInViewer: boolean;
shouldShowEmbeddingPicker: boolean;
shouldAutoChangeDimensions: boolean;
favoriteSchedulers: SchedulerParam[];
globalContextMenuCloseTrigger: number;
panels: Record<string, string>;