feat(ui): refactor control adapters

Control adapters logic/state/ui is now generalized to hold controlnet, ip_adapter and t2i_adapter. In the future, other control adapter types can be added.

TODO:
- Limit IP adapter to 1
- Add T2I adapter to linear graphs
- Fix autoprocess
- T2I metadata saving & recall
- Improve on control adapters UI
This commit is contained in:
psychedelicious
2023-10-05 22:40:21 +11:00
parent 9c720da021
commit 9508e0c9db
70 changed files with 1860 additions and 1236 deletions

View File

@ -15,7 +15,7 @@ type UseImageUploadButtonArgs = {
* @example
* const { getUploadButtonProps, getUploadInputProps, openUploader } = useImageUploadButton({
* postUploadAction: {
* type: 'SET_CONTROLNET_IMAGE',
* type: 'SET_CONTROL_ADAPTER_IMAGE',
* controlNetId: '12345',
* },
* isDisabled: getIsUploadDisabled(),

View File

@ -2,16 +2,18 @@ import { createSelector } from '@reduxjs/toolkit';
import { stateSelector } from 'app/store/store';
import { useAppSelector } from 'app/store/storeHooks';
import { defaultSelectorOptions } from 'app/store/util/defaultMemoizeOptions';
import { selectControlAdapterAll } from 'features/controlNet/store/controlAdaptersSlice';
import { isControlNetOrT2IAdapter } from 'features/controlNet/store/types';
import { isInvocationNode } from 'features/nodes/types/types';
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
import i18n from 'i18next';
import { forEach, map } from 'lodash-es';
import { forEach } from 'lodash-es';
import { getConnectedEdges } from 'reactflow';
const selector = createSelector(
[stateSelector, activeTabNameSelector],
(
{ controlNet, generation, system, nodes, dynamicPrompts },
{ controlAdapters, generation, system, nodes, dynamicPrompts },
activeTabName
) => {
const { initialImage, model } = generation;
@ -87,30 +89,29 @@ const selector = createSelector(
reasons.push(i18n.t('parameters.invoke.noModelSelected'));
}
if (controlNet.isEnabled) {
map(controlNet.controlNets).forEach((controlNet, i) => {
if (!controlNet.isEnabled) {
return;
}
if (!controlNet.model) {
reasons.push(
i18n.t('parameters.invoke.noModelForControlNet', { index: i + 1 })
);
}
selectControlAdapterAll(controlAdapters).forEach((ca, i) => {
if (!ca.isEnabled) {
return;
}
if (!ca.model) {
reasons.push(
i18n.t('parameters.invoke.noModelForControlNet', { index: i + 1 })
);
}
if (
!controlNet.controlImage ||
(!controlNet.processedControlImage &&
controlNet.processorType !== 'none')
) {
reasons.push(
i18n.t('parameters.invoke.noControlImageForControlNet', {
index: i + 1,
})
);
}
});
}
if (
!ca.controlImage ||
(isControlNetOrT2IAdapter(ca) &&
!ca.processedControlImage &&
ca.processorType !== 'none')
) {
reasons.push(
i18n.t('parameters.invoke.noControlImageForControlNet', {
index: i + 1,
})
);
}
});
}
return { isReady: !reasons.length, reasons };