feat(ui): support negative controlnet weights

This commit is contained in:
psychedelicious 2023-06-12 11:23:44 +10:00
parent 8607b1994c
commit af42d7d347
17 changed files with 112 additions and 59 deletions

View File

@ -1,4 +1,5 @@
import { import {
ChakraProps,
FormControl, FormControl,
FormControlProps, FormControlProps,
FormLabel, FormLabel,
@ -39,6 +40,11 @@ import { BiReset } from 'react-icons/bi';
import IAIIconButton, { IAIIconButtonProps } from './IAIIconButton'; import IAIIconButton, { IAIIconButtonProps } from './IAIIconButton';
import { roundDownToMultiple } from 'common/util/roundDownToMultiple'; import { roundDownToMultiple } from 'common/util/roundDownToMultiple';
const SLIDER_MARK_STYLES: ChakraProps['sx'] = {
mt: 1.5,
fontSize: '2xs',
};
export type IAIFullSliderProps = { export type IAIFullSliderProps = {
label?: string; label?: string;
value: number; value: number;
@ -57,6 +63,7 @@ export type IAIFullSliderProps = {
hideTooltip?: boolean; hideTooltip?: boolean;
isCompact?: boolean; isCompact?: boolean;
isDisabled?: boolean; isDisabled?: boolean;
sliderMarks?: number[];
sliderFormControlProps?: FormControlProps; sliderFormControlProps?: FormControlProps;
sliderFormLabelProps?: FormLabelProps; sliderFormLabelProps?: FormLabelProps;
sliderMarkProps?: Omit<SliderMarkProps, 'value'>; sliderMarkProps?: Omit<SliderMarkProps, 'value'>;
@ -88,6 +95,7 @@ const IAISlider = (props: IAIFullSliderProps) => {
hideTooltip = false, hideTooltip = false,
isCompact = false, isCompact = false,
isDisabled = false, isDisabled = false,
sliderMarks,
handleReset, handleReset,
sliderFormControlProps, sliderFormControlProps,
sliderFormLabelProps, sliderFormLabelProps,
@ -198,14 +206,14 @@ const IAISlider = (props: IAIFullSliderProps) => {
isDisabled={isDisabled} isDisabled={isDisabled}
{...rest} {...rest}
> >
{withSliderMarks && ( {withSliderMarks && !sliderMarks && (
<> <>
<SliderMark <SliderMark
value={min} value={min}
sx={{ sx={{
insetInlineStart: '0 !important', insetInlineStart: '0 !important',
insetInlineEnd: 'unset !important', insetInlineEnd: 'unset !important',
mt: 1.5, ...SLIDER_MARK_STYLES,
}} }}
{...sliderMarkProps} {...sliderMarkProps}
> >
@ -216,7 +224,7 @@ const IAISlider = (props: IAIFullSliderProps) => {
sx={{ sx={{
insetInlineStart: 'unset !important', insetInlineStart: 'unset !important',
insetInlineEnd: '0 !important', insetInlineEnd: '0 !important',
mt: 1.5, ...SLIDER_MARK_STYLES,
}} }}
{...sliderMarkProps} {...sliderMarkProps}
> >
@ -224,6 +232,56 @@ const IAISlider = (props: IAIFullSliderProps) => {
</SliderMark> </SliderMark>
</> </>
)} )}
{withSliderMarks && sliderMarks && (
<>
{sliderMarks.map((m, i) => {
if (i === 0) {
return (
<SliderMark
key={m}
value={m}
sx={{
insetInlineStart: '0 !important',
insetInlineEnd: 'unset !important',
...SLIDER_MARK_STYLES,
}}
{...sliderMarkProps}
>
{m}
</SliderMark>
);
} else if (i === sliderMarks.length - 1) {
return (
<SliderMark
key={m}
value={m}
sx={{
insetInlineStart: 'unset !important',
insetInlineEnd: '0 !important',
...SLIDER_MARK_STYLES,
}}
{...sliderMarkProps}
>
{m}
</SliderMark>
);
} else {
return (
<SliderMark
key={m}
value={m}
sx={{
...SLIDER_MARK_STYLES,
}}
{...sliderMarkProps}
>
{m}
</SliderMark>
);
}
})}
</>
)}
<SliderTrack {...sliderTrackProps}> <SliderTrack {...sliderTrackProps}>
<SliderFilledTrack /> <SliderFilledTrack />

View File

@ -143,7 +143,7 @@ const ControlNet = (props: ControlNetProps) => {
flexDir: 'column', flexDir: 'column',
gap: 2, gap: 2,
w: 'full', w: 'full',
h: 24, h: isExpanded ? 28 : 24,
paddingInlineStart: 1, paddingInlineStart: 1,
paddingInlineEnd: isExpanded ? 1 : 0, paddingInlineEnd: isExpanded ? 1 : 0,
pb: 2, pb: 2,
@ -153,13 +153,13 @@ const ControlNet = (props: ControlNetProps) => {
<ParamControlNetWeight <ParamControlNetWeight
controlNetId={controlNetId} controlNetId={controlNetId}
weight={weight} weight={weight}
mini mini={!isExpanded}
/> />
<ParamControlNetBeginEnd <ParamControlNetBeginEnd
controlNetId={controlNetId} controlNetId={controlNetId}
beginStepPct={beginStepPct} beginStepPct={beginStepPct}
endStepPct={endStepPct} endStepPct={endStepPct}
mini mini={!isExpanded}
/> />
</Flex> </Flex>
{!isExpanded && ( {!isExpanded && (

View File

@ -1,4 +1,5 @@
import { import {
ChakraProps,
FormControl, FormControl,
FormLabel, FormLabel,
HStack, HStack,
@ -10,14 +11,19 @@ import {
Tooltip, Tooltip,
} from '@chakra-ui/react'; } from '@chakra-ui/react';
import { useAppDispatch } from 'app/store/storeHooks'; import { useAppDispatch } from 'app/store/storeHooks';
import IAIIconButton from 'common/components/IAIIconButton';
import { import {
controlNetBeginStepPctChanged, controlNetBeginStepPctChanged,
controlNetEndStepPctChanged, controlNetEndStepPctChanged,
} from 'features/controlNet/store/controlNetSlice'; } from 'features/controlNet/store/controlNetSlice';
import { memo, useCallback } from 'react'; import { memo, useCallback } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { BiReset } from 'react-icons/bi';
const SLIDER_MARK_STYLES: ChakraProps['sx'] = {
mt: 1.5,
fontSize: '2xs',
fontWeight: '500',
color: 'base.400',
};
type Props = { type Props = {
controlNetId: string; controlNetId: string;
@ -29,7 +35,7 @@ type Props = {
const formatPct = (v: number) => `${Math.round(v * 100)}%`; const formatPct = (v: number) => `${Math.round(v * 100)}%`;
const ParamControlNetBeginEnd = (props: Props) => { const ParamControlNetBeginEnd = (props: Props) => {
const { controlNetId, beginStepPct, endStepPct, mini = false } = props; const { controlNetId, beginStepPct, mini = false, endStepPct } = props;
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { t } = useTranslation(); const { t } = useTranslation();
@ -75,12 +81,9 @@ const ParamControlNetBeginEnd = (props: Props) => {
<RangeSliderMark <RangeSliderMark
value={0} value={0}
sx={{ sx={{
fontSize: 'xs',
fontWeight: '500',
color: 'base.200',
insetInlineStart: '0 !important', insetInlineStart: '0 !important',
insetInlineEnd: 'unset !important', insetInlineEnd: 'unset !important',
mt: 1.5, ...SLIDER_MARK_STYLES,
}} }}
> >
0% 0%
@ -88,10 +91,7 @@ const ParamControlNetBeginEnd = (props: Props) => {
<RangeSliderMark <RangeSliderMark
value={0.5} value={0.5}
sx={{ sx={{
fontSize: 'xs', ...SLIDER_MARK_STYLES,
fontWeight: '500',
color: 'base.200',
mt: 1.5,
}} }}
> >
50% 50%
@ -99,12 +99,9 @@ const ParamControlNetBeginEnd = (props: Props) => {
<RangeSliderMark <RangeSliderMark
value={1} value={1}
sx={{ sx={{
fontSize: 'xs',
fontWeight: '500',
color: 'base.200',
insetInlineStart: 'unset !important', insetInlineStart: 'unset !important',
insetInlineEnd: '0 !important', insetInlineEnd: '0 !important',
mt: 1.5, ...SLIDER_MARK_STYLES,
}} }}
> >
100% 100%
@ -112,16 +109,6 @@ const ParamControlNetBeginEnd = (props: Props) => {
</> </>
)} )}
</RangeSlider> </RangeSlider>
{!mini && (
<IAIIconButton
size="sm"
aria-label={t('accessibility.reset')}
tooltip={t('accessibility.reset')}
icon={<BiReset />}
onClick={handleStepPctReset}
/>
)}
</HStack> </HStack>
</FormControl> </FormControl>
); );

View File

@ -20,36 +20,17 @@ const ParamControlNetWeight = (props: ParamControlNetWeightProps) => {
[controlNetId, dispatch] [controlNetId, dispatch]
); );
const handleWeightReset = () => {
dispatch(controlNetWeightChanged({ controlNetId, weight: 1 }));
};
if (mini) {
return ( return (
<IAISlider <IAISlider
label={'Weight'} label={'Weight'}
sliderFormLabelProps={{ pb: 1 }} sliderFormLabelProps={{ pb: 2 }}
value={weight} value={weight}
onChange={handleWeightChanged} onChange={handleWeightChanged}
min={0} min={-1}
max={1}
step={0.01}
/>
);
}
return (
<IAISlider
label="Weight"
value={weight}
onChange={handleWeightChanged}
withInput
withReset
handleReset={handleWeightReset}
withSliderMarks
min={0}
max={1} max={1}
step={0.01} step={0.01}
withSliderMarks={!mini}
sliderMarks={[-1, 0, 1]}
/> />
); );
}; };

View File

@ -54,6 +54,7 @@ const CannyProcessor = (props: CannyProcessorProps) => {
min={0} min={0}
max={255} max={255}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="High Threshold" label="High Threshold"
@ -64,6 +65,7 @@ const CannyProcessor = (props: CannyProcessorProps) => {
min={0} min={0}
max={255} max={255}
withInput withInput
withSliderMarks
/> />
</ProcessorWrapper> </ProcessorWrapper>
); );

View File

@ -93,6 +93,7 @@ const ContentShuffleProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="Image Resolution" label="Image Resolution"
@ -103,6 +104,7 @@ const ContentShuffleProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="W" label="W"
@ -113,6 +115,7 @@ const ContentShuffleProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="H" label="H"
@ -123,6 +126,7 @@ const ContentShuffleProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="F" label="F"
@ -133,6 +137,7 @@ const ContentShuffleProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
</ProcessorWrapper> </ProcessorWrapper>
); );

View File

@ -65,6 +65,7 @@ const HedPreprocessor = (props: HedProcessorProps) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="Image Resolution" label="Image Resolution"
@ -75,6 +76,7 @@ const HedPreprocessor = (props: HedProcessorProps) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISwitch <IAISwitch
label="Scribble" label="Scribble"

View File

@ -54,6 +54,7 @@ const LineartAnimeProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="Image Resolution" label="Image Resolution"
@ -64,6 +65,7 @@ const LineartAnimeProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
</ProcessorWrapper> </ProcessorWrapper>
); );

View File

@ -62,6 +62,7 @@ const LineartProcessor = (props: LineartProcessorProps) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="Image Resolution" label="Image Resolution"
@ -72,6 +73,7 @@ const LineartProcessor = (props: LineartProcessorProps) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISwitch <IAISwitch
label="Coarse" label="Coarse"

View File

@ -50,6 +50,7 @@ const MediapipeFaceProcessor = (props: Props) => {
min={1} min={1}
max={20} max={20}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="Min Confidence" label="Min Confidence"
@ -61,6 +62,7 @@ const MediapipeFaceProcessor = (props: Props) => {
max={1} max={1}
step={0.01} step={0.01}
withInput withInput
withSliderMarks
/> />
</ProcessorWrapper> </ProcessorWrapper>
); );

View File

@ -51,6 +51,7 @@ const MidasDepthProcessor = (props: Props) => {
max={20} max={20}
step={0.01} step={0.01}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="bg_th" label="bg_th"
@ -62,6 +63,7 @@ const MidasDepthProcessor = (props: Props) => {
max={20} max={20}
step={0.01} step={0.01}
withInput withInput
withSliderMarks
/> />
</ProcessorWrapper> </ProcessorWrapper>
); );

View File

@ -76,6 +76,7 @@ const MlsdImageProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="Image Resolution" label="Image Resolution"
@ -86,6 +87,7 @@ const MlsdImageProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="W" label="W"
@ -97,6 +99,7 @@ const MlsdImageProcessor = (props: Props) => {
max={1} max={1}
step={0.01} step={0.01}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="H" label="H"
@ -108,6 +111,7 @@ const MlsdImageProcessor = (props: Props) => {
max={1} max={1}
step={0.01} step={0.01}
withInput withInput
withSliderMarks
/> />
</ProcessorWrapper> </ProcessorWrapper>
); );

View File

@ -54,6 +54,7 @@ const NormalBaeProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="Image Resolution" label="Image Resolution"
@ -64,6 +65,7 @@ const NormalBaeProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
</ProcessorWrapper> </ProcessorWrapper>
); );

View File

@ -62,6 +62,7 @@ const OpenposeProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="Image Resolution" label="Image Resolution"
@ -72,6 +73,7 @@ const OpenposeProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISwitch <IAISwitch
label="Hand and Face" label="Hand and Face"

View File

@ -69,6 +69,7 @@ const PidiProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISlider <IAISlider
label="Image Resolution" label="Image Resolution"
@ -79,6 +80,7 @@ const PidiProcessor = (props: Props) => {
min={0} min={0}
max={4096} max={4096}
withInput withInput
withSliderMarks
/> />
<IAISwitch <IAISwitch
label="Scribble" label="Scribble"

View File

@ -23,7 +23,7 @@ type ControlNetProcessorsDict = Record<
* *
* TODO: Generate from the OpenAPI schema * TODO: Generate from the OpenAPI schema
*/ */
export const CONTROLNET_PROCESSORS: ControlNetProcessorsDict = { export const CONTROLNET_PROCESSORS = {
none: { none: {
type: 'none', type: 'none',
label: 'none', label: 'none',
@ -129,7 +129,7 @@ export const CONTROLNET_PROCESSORS: ControlNetProcessorsDict = {
}, },
normalbae_image_processor: { normalbae_image_processor: {
type: 'normalbae_image_processor', type: 'normalbae_image_processor',
label: 'NormalBae', label: 'Normal BAE',
description: '', description: '',
default: { default: {
id: 'normalbae_image_processor', id: 'normalbae_image_processor',
@ -208,7 +208,7 @@ export const CONTROLNET_MODELS: Record<string, ControlNetModel> = {
}, },
'lllyasviel/control_v11p_sd15_seg': { 'lllyasviel/control_v11p_sd15_seg': {
type: 'lllyasviel/control_v11p_sd15_seg', type: 'lllyasviel/control_v11p_sd15_seg',
label: 'Segment Anything', label: 'Segmentation',
}, },
'lllyasviel/control_v11p_sd15_lineart': { 'lllyasviel/control_v11p_sd15_lineart': {
type: 'lllyasviel/control_v11p_sd15_lineart', type: 'lllyasviel/control_v11p_sd15_lineart',

View File

@ -30,7 +30,7 @@ const invokeAIMark = defineStyle((_props) => {
return { return {
fontSize: 'xs', fontSize: 'xs',
fontWeight: '500', fontWeight: '500',
color: 'base.200', color: 'base.400',
mt: 2, mt: 2,
insetInlineStart: 'unset', insetInlineStart: 'unset',
}; };