mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat: Add Embedding Select To Linear UI
This commit is contained in:
parent
c8cb43ff2d
commit
8c9266359d
@ -49,6 +49,8 @@ const IAIMantineMultiSelect = (props: IAIMultiSelectProps) => {
|
|||||||
borderWidth: '2px',
|
borderWidth: '2px',
|
||||||
borderColor: mode(base200, base800)(colorMode),
|
borderColor: mode(base200, base800)(colorMode),
|
||||||
color: mode(base900, base100)(colorMode),
|
color: mode(base900, base100)(colorMode),
|
||||||
|
paddingTop: 6,
|
||||||
|
paddingBottom: 6,
|
||||||
paddingRight: 24,
|
paddingRight: 24,
|
||||||
fontWeight: 600,
|
fontWeight: 600,
|
||||||
'&:hover': { borderColor: mode(base300, base600)(colorMode) },
|
'&:hover': { borderColor: mode(base300, base600)(colorMode) },
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
import { Flex } from '@chakra-ui/react';
|
||||||
|
import IAICollapse from 'common/components/IAICollapse';
|
||||||
|
import ParamEmbeddingSelect from './ParamEmbeddingSelect';
|
||||||
|
|
||||||
|
export default function ParamEmbeddingCollapse() {
|
||||||
|
return (
|
||||||
|
<IAICollapse label="Embeddings">
|
||||||
|
<Flex sx={{ flexDir: 'column', gap: 2 }}>
|
||||||
|
<ParamEmbeddingSelect />
|
||||||
|
</Flex>
|
||||||
|
</IAICollapse>
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,128 @@
|
|||||||
|
import { Flex, Text } from '@chakra-ui/react';
|
||||||
|
import { RootState } from 'app/store/store';
|
||||||
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
|
import IAIButton from 'common/components/IAIButton';
|
||||||
|
import IAIMantineMultiSelect from 'common/components/IAIMantineMultiSelect';
|
||||||
|
import {
|
||||||
|
setNegativePrompt,
|
||||||
|
setPositivePrompt,
|
||||||
|
} from 'features/parameters/store/generationSlice';
|
||||||
|
import { forEach, join, map } from 'lodash-es';
|
||||||
|
import { forwardRef, useMemo, useState } from 'react';
|
||||||
|
import { useGetTextualInversionModelsQuery } from 'services/api/endpoints/models';
|
||||||
|
|
||||||
|
type EmbeddingSelectItem = {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
description?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function ParamEmbeddingSelect() {
|
||||||
|
const { data: embeddingQueryData } = useGetTextualInversionModelsQuery();
|
||||||
|
const [selectedEmbeddings, setSelectedEmbeddings] = useState<
|
||||||
|
string[] | undefined
|
||||||
|
>(undefined);
|
||||||
|
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
const positivePrompt = useAppSelector(
|
||||||
|
(state: RootState) => state.generation.positivePrompt
|
||||||
|
);
|
||||||
|
|
||||||
|
const negativePrompt = useAppSelector(
|
||||||
|
(state: RootState) => state.generation.negativePrompt
|
||||||
|
);
|
||||||
|
|
||||||
|
const data = useMemo(() => {
|
||||||
|
if (!embeddingQueryData) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const data: EmbeddingSelectItem[] = [];
|
||||||
|
|
||||||
|
forEach(embeddingQueryData.entities, (embedding, _) => {
|
||||||
|
if (!embedding) return;
|
||||||
|
|
||||||
|
data.push({
|
||||||
|
value: embedding.name,
|
||||||
|
label: embedding.name,
|
||||||
|
description: embedding.description,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}, [embeddingQueryData]);
|
||||||
|
|
||||||
|
const handlePositiveAdd = () => {
|
||||||
|
if (!selectedEmbeddings) return;
|
||||||
|
const parsedEmbeddings = join(
|
||||||
|
map(selectedEmbeddings, (embedding) => `<${embedding}>`),
|
||||||
|
' '
|
||||||
|
);
|
||||||
|
dispatch(setPositivePrompt(`${positivePrompt} ${parsedEmbeddings}`));
|
||||||
|
setSelectedEmbeddings([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNegativeAdd = () => {
|
||||||
|
if (!selectedEmbeddings) return;
|
||||||
|
const parsedEmbeddings = join(
|
||||||
|
map(selectedEmbeddings, (embedding) => `<${embedding}>`),
|
||||||
|
' '
|
||||||
|
);
|
||||||
|
dispatch(setNegativePrompt(`${negativePrompt} ${parsedEmbeddings}`));
|
||||||
|
setSelectedEmbeddings([]);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flex gap={2} flexDirection="column">
|
||||||
|
<IAIMantineMultiSelect
|
||||||
|
placeholder="Pick Embedding"
|
||||||
|
value={selectedEmbeddings}
|
||||||
|
onChange={(v) => setSelectedEmbeddings(v)}
|
||||||
|
data={data}
|
||||||
|
maxDropdownHeight={400}
|
||||||
|
nothingFound="No matching Embeddings"
|
||||||
|
itemComponent={SelectItem}
|
||||||
|
disabled={data.length === 0}
|
||||||
|
filter={(value, selected, item: EmbeddingSelectItem) =>
|
||||||
|
item.label.toLowerCase().includes(value.toLowerCase().trim()) ||
|
||||||
|
item.value.toLowerCase().includes(value.toLowerCase().trim())
|
||||||
|
}
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
<Flex gap={2}>
|
||||||
|
<IAIButton size="sm" w="100%" onClick={handlePositiveAdd}>
|
||||||
|
Add To Positive
|
||||||
|
</IAIButton>
|
||||||
|
<IAIButton size="sm" w="100%" onClick={handleNegativeAdd}>
|
||||||
|
Add To Negative
|
||||||
|
</IAIButton>
|
||||||
|
</Flex>
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ItemProps extends React.ComponentPropsWithoutRef<'div'> {
|
||||||
|
value: string;
|
||||||
|
label: string;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SelectItem = forwardRef<HTMLDivElement, ItemProps>(
|
||||||
|
({ label, description, ...others }: ItemProps, ref) => {
|
||||||
|
return (
|
||||||
|
<div ref={ref} {...others}>
|
||||||
|
<div>
|
||||||
|
<Text>{label}</Text>
|
||||||
|
{description && (
|
||||||
|
<Text size="xs" color="base.600">
|
||||||
|
{description}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
SelectItem.displayName = 'SelectItem';
|
@ -1,4 +1,5 @@
|
|||||||
import ParamDynamicPromptsCollapse from 'features/dynamicPrompts/components/ParamDynamicPromptsCollapse';
|
import ParamDynamicPromptsCollapse from 'features/dynamicPrompts/components/ParamDynamicPromptsCollapse';
|
||||||
|
import ParamEmbeddingCollapse from 'features/embedding/components/ParamEmbeddingCollapse';
|
||||||
import ParamLoraCollapse from 'features/lora/components/ParamLoraCollapse';
|
import ParamLoraCollapse from 'features/lora/components/ParamLoraCollapse';
|
||||||
import ParamControlNetCollapse from 'features/parameters/components/Parameters/ControlNet/ParamControlNetCollapse';
|
import ParamControlNetCollapse from 'features/parameters/components/Parameters/ControlNet/ParamControlNetCollapse';
|
||||||
import ParamNegativeConditioning from 'features/parameters/components/Parameters/Core/ParamNegativeConditioning';
|
import ParamNegativeConditioning from 'features/parameters/components/Parameters/Core/ParamNegativeConditioning';
|
||||||
@ -18,6 +19,7 @@ const ImageToImageTabParameters = () => {
|
|||||||
<ParamNegativeConditioning />
|
<ParamNegativeConditioning />
|
||||||
<ProcessButtons />
|
<ProcessButtons />
|
||||||
<ImageToImageTabCoreParameters />
|
<ImageToImageTabCoreParameters />
|
||||||
|
<ParamEmbeddingCollapse />
|
||||||
<ParamLoraCollapse />
|
<ParamLoraCollapse />
|
||||||
<ParamDynamicPromptsCollapse />
|
<ParamDynamicPromptsCollapse />
|
||||||
<ParamControlNetCollapse />
|
<ParamControlNetCollapse />
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import ParamDynamicPromptsCollapse from 'features/dynamicPrompts/components/ParamDynamicPromptsCollapse';
|
import ParamDynamicPromptsCollapse from 'features/dynamicPrompts/components/ParamDynamicPromptsCollapse';
|
||||||
|
import ParamEmbeddingCollapse from 'features/embedding/components/ParamEmbeddingCollapse';
|
||||||
import ParamLoraCollapse from 'features/lora/components/ParamLoraCollapse';
|
import ParamLoraCollapse from 'features/lora/components/ParamLoraCollapse';
|
||||||
import ParamControlNetCollapse from 'features/parameters/components/Parameters/ControlNet/ParamControlNetCollapse';
|
import ParamControlNetCollapse from 'features/parameters/components/Parameters/ControlNet/ParamControlNetCollapse';
|
||||||
import ParamNegativeConditioning from 'features/parameters/components/Parameters/Core/ParamNegativeConditioning';
|
import ParamNegativeConditioning from 'features/parameters/components/Parameters/Core/ParamNegativeConditioning';
|
||||||
@ -19,6 +20,7 @@ const TextToImageTabParameters = () => {
|
|||||||
<ParamNegativeConditioning />
|
<ParamNegativeConditioning />
|
||||||
<ProcessButtons />
|
<ProcessButtons />
|
||||||
<TextToImageTabCoreParameters />
|
<TextToImageTabCoreParameters />
|
||||||
|
<ParamEmbeddingCollapse />
|
||||||
<ParamLoraCollapse />
|
<ParamLoraCollapse />
|
||||||
<ParamDynamicPromptsCollapse />
|
<ParamDynamicPromptsCollapse />
|
||||||
<ParamControlNetCollapse />
|
<ParamControlNetCollapse />
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import ParamDynamicPromptsCollapse from 'features/dynamicPrompts/components/ParamDynamicPromptsCollapse';
|
import ParamDynamicPromptsCollapse from 'features/dynamicPrompts/components/ParamDynamicPromptsCollapse';
|
||||||
|
import ParamEmbeddingCollapse from 'features/embedding/components/ParamEmbeddingCollapse';
|
||||||
import ParamLoraCollapse from 'features/lora/components/ParamLoraCollapse';
|
import ParamLoraCollapse from 'features/lora/components/ParamLoraCollapse';
|
||||||
import ParamInfillAndScalingCollapse from 'features/parameters/components/Parameters/Canvas/InfillAndScaling/ParamInfillAndScalingCollapse';
|
import ParamInfillAndScalingCollapse from 'features/parameters/components/Parameters/Canvas/InfillAndScaling/ParamInfillAndScalingCollapse';
|
||||||
import ParamSeamCorrectionCollapse from 'features/parameters/components/Parameters/Canvas/SeamCorrection/ParamSeamCorrectionCollapse';
|
import ParamSeamCorrectionCollapse from 'features/parameters/components/Parameters/Canvas/SeamCorrection/ParamSeamCorrectionCollapse';
|
||||||
@ -18,6 +19,7 @@ const UnifiedCanvasParameters = () => {
|
|||||||
<ParamNegativeConditioning />
|
<ParamNegativeConditioning />
|
||||||
<ProcessButtons />
|
<ProcessButtons />
|
||||||
<UnifiedCanvasCoreParameters />
|
<UnifiedCanvasCoreParameters />
|
||||||
|
<ParamEmbeddingCollapse />
|
||||||
<ParamLoraCollapse />
|
<ParamLoraCollapse />
|
||||||
<ParamDynamicPromptsCollapse />
|
<ParamDynamicPromptsCollapse />
|
||||||
<ParamControlNetCollapse />
|
<ParamControlNetCollapse />
|
||||||
|
Loading…
Reference in New Issue
Block a user