Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(generate): unify guidance section
Josh Corbett42dd4965bb77
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsxindex 28fd3eb28c..576fdb3572 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx@@ -7,7 +7,7 @@ import type {LoraModelConfig,} from '@features/generation/core/types';-import { Badge, HStack, Stack, Switch, Text } from '@chakra-ui/react';+import { Badge, HStack, Stack, Text } from '@chakra-ui/react';import {DEFAULT_LORA_WEIGHT_CONFIG,getDefaultLoraWeight,@@ -26,10 +26,10 @@ import type { GenerateSettingsUpdate } from './generateDebounce';import { useRegisterGenerateDraftFlusher } from './generateDraftRegistry';import { GenerationModelSelect as ModelSelect, useGenerationUi } from './GenerationUiContext';-import { GenerateCollapsibleSection } from './shared/GenerateCollapsibleSection';+import { GenerateToggleSwitch } from './shared/GenerateToggleSwitch';import { useDebouncedDraftValue } from './useDebouncedDraftValue';-interface GenerateConceptsSectionProps {+interface GenerateConceptsContentProps {settings: GenerateSettings;loraModels: LoraModelConfig[];projectId: string;@@ -49,22 +49,22 @@ const LORA_WEIGHT_DEBOUNCE_MS = 250;const isCompatibleLora = (lora: GenerateLora, selectedModel: GenerateModelConfig | undefined): boolean =>Boolean(selectedModel && isLoraCompatibleWithModel(lora.model, selectedModel));-export const GenerateConceptsSection = ({+/**+ * Concept (LoRA) conditioning, rendered inside the Guidance section (the+ * section chrome and combined badges live in `GenerateGuidanceSection`).+ */+export const GenerateConceptsContent = ({loraModels,onCommit,onCommitImmediate,projectId,selectedModel,settings,-}: GenerateConceptsSectionProps) => {+}: GenerateConceptsContentProps) => {const { t } = useTranslation();const loras = useMemo(() => syncGenerateLorasWithModels(settings.loras, loraModels), [loraModels, settings.loras]);const selectedLoraKeys = useMemo(() => new Set(loras.map((lora) => lora.model.key)), [loras]);- const activeCount = selectedModel- ? loras.filter((lora) => lora.isEnabled && isLoraCompatibleWithModel(lora.model, selectedModel)).length- : 0;-const addLora = (model: ModelConfig | null) => {if (!isLoraModelConfig(model) || selectedLoraKeys.has(model.key)) {return;@@ -95,61 +95,48 @@ export const GenerateConceptsSection = ({onCommitImmediate({ loras: loras.filter((lora) => lora.model.key !== modelKey) });};- const badges =- activeCount > 0 ? (- <Badge size="xs" variant="surface">- {t('widgets.generate.activeCount', { count: activeCount })}- </Badge>- ) : loras.length > 0 ? (- <Badge size="xs" variant="surface">- {t('widgets.generate.offCount', { count: loras.length })}- </Badge>- ) : null;-return (- <GenerateCollapsibleSection label={t('widgets.generate.concepts')} defaultOpen badges={badges} sectionId="concepts">- <Stack gap="2" p="2">- <Field- hint="concepts"- label={t('widgets.generate.addConcept')}- helpText={selectedModel ? undefined : t('widgets.generate.selectMainModelBeforeConcepts')}- >- <ModelSelect- excludeKeys={selectedLoraKeys}- filter={(model) =>- Boolean(selectedModel && isLoraModelConfig(model) && isLoraCompatibleWithModel(model, selectedModel))- }- modelTypes={['lora']}- placeholder={- selectedModel ? t('widgets.generate.searchCompatibleConcepts') : t('widgets.generate.selectModelFirst')- }- size="xs"- value={null}- onChange={addLora}- />- </Field>-- {loras.length === 0 ? (- <Text color="fg.subtle" fontSize="2xs">- {t('widgets.generate.addConceptsHelp')}- </Text>- ) : (- <Stack gap="2">- {loras.map((lora) => (- <LoraRow- key={lora.model.key}- isCompatible={isCompatibleLora(lora, selectedModel)}- lora={lora}- projectId={projectId}- onRemove={() => removeLora(lora.model.key)}- onToggle={(isEnabled) => updateLora(lora.model.key, { isEnabled })}- onWeightChange={(weight) => updateLora(lora.model.key, { weight })}- />- ))}- </Stack>- )}- </Stack>- </GenerateCollapsibleSection>+ <Stack gap="2">+ <Field+ hint="concepts"+ label={t('widgets.generate.addConcept')}+ helpText={selectedModel ? undefined : t('widgets.generate.selectMainModelBeforeConcepts')}+ >+ <ModelSelect+ excludeKeys={selectedLoraKeys}+ filter={(model) =>+ Boolean(selectedModel && isLoraModelConfig(model) && isLoraCompatibleWithModel(model, selectedModel))+ }+ modelTypes={['lora']}+ placeholder={+ selectedModel ? t('widgets.generate.searchCompatibleConcepts') : t('widgets.generate.selectModelFirst')+ }+ size="xs"+ value={null}+ onChange={addLora}+ />+ </Field>++ {loras.length === 0 ? (+ <Text color="fg.subtle" fontSize="2xs">+ {t('widgets.generate.addConceptsHelp')}+ </Text>+ ) : (+ <Stack gap="2">+ {loras.map((lora) => (+ <LoraRow+ key={lora.model.key}+ isCompatible={isCompatibleLora(lora, selectedModel)}+ lora={lora}+ projectId={projectId}+ onRemove={() => removeLora(lora.model.key)}+ onToggle={(isEnabled) => updateLora(lora.model.key, { isEnabled })}+ onWeightChange={(weight) => updateLora(lora.model.key, { weight })}+ />+ ))}+ </Stack>+ )}+ </Stack>);};@@ -223,22 +210,16 @@ const LoraRow = ({</Stack><HStack flexShrink="0" gap="1">- <Switch.Root- aria-label={+ <GenerateToggleSwitch+ checked={isActive}+ disabled={!isCompatible}+ label={isActive? t('widgets.generate.disableConcept', { name: lora.model.name }): t('widgets.generate.enableConcept', { name: lora.model.name })}- checked={isActive}- disabled={!isCompatible}- size="sm"- onCheckedChange={(event) => onToggle(event.checked)}- >- <Switch.HiddenInput />- <Switch.Control _checked={{ bg: 'accent.solid' }}>- <Switch.Thumb />- </Switch.Control>- </Switch.Root>+ onCheckedChange={onToggle}+ /><Tooltip content={t('widgets.generate.removeConcept')}><IconButtondiff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateGuidanceSection.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateGuidanceSection.tsxnew file mode 100644index 0000000000..391f576f35--- /dev/null+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateGuidanceSection.tsx@@ -0,0 +1,98 @@+import type { GenerationModelCatalogItem as ModelConfig } from '@features/generation/contracts';+import type { GenerateModelConfig, GenerateSettings, LoraModelConfig } from '@features/generation/core/types';+import type { GenerateSettingsUpdate } from '@features/generation/ui/generateDebounce';++import { Badge, Separator, Stack } from '@chakra-ui/react';+import { isReferenceImageSupported } from '@features/generation/core/baseGenerationPolicies';+import { isLoraCompatibleWithModel } from '@features/generation/core/settings';+import { useTranslation } from 'react-i18next';++import { GenerateConceptsContent } from './GenerateConceptsSection';+import { GenerateReferenceImagesContent } from './reference-images/GenerateReferenceImagesSection';+import { GenerateCollapsibleSection } from './shared/GenerateCollapsibleSection';++interface GenerateGuidanceSectionProps {+ loraModels: LoraModelConfig[];+ models: readonly ModelConfig[];+ projectId: string;+ selectedModel: GenerateModelConfig | undefined;+ settings: GenerateSettings;+ /** Debounced draft-update channel — reference-image edits ride the form's debounce. */+ onReferenceCommit: (update: GenerateSettingsUpdate) => void;+ /** Flushed update channel — concept rows debounce their own weight drafts first. */+ onConceptCommit: (update: GenerateSettingsUpdate) => void;+ onCommitImmediate: (patch: Partial<GenerateSettings>) => void;+}++/**+ * Creative conditioning in one place: reference images and concepts (LoRAs) are+ * the same kind of decision — a visual influence with a weight and a toggle —+ * so they share a section instead of two sibling accordions.+ */+export const GenerateGuidanceSection = ({+ loraModels,+ models,+ onCommitImmediate,+ onConceptCommit,+ onReferenceCommit,+ projectId,+ selectedModel,+ settings,+}: GenerateGuidanceSectionProps) => {+ const { t } = useTranslation();+ const referenceImagesSupported = isReferenceImageSupported(selectedModel);+ const referenceImageCount = settings.referenceImages.length;+ const activeReferenceImages = referenceImagesSupported+ ? settings.referenceImages.filter((image) => image.isEnabled).length+ : 0;+ const activeConcepts = selectedModel+ ? settings.loras.filter((lora) => lora.isEnabled && isLoraCompatibleWithModel(lora.model, selectedModel)).length+ : 0;+ const hasIncompatible =+ (!referenceImagesSupported && referenceImageCount > 0) ||+ settings.loras.some((lora) => selectedModel && !isLoraCompatibleWithModel(lora.model, selectedModel));+ const activeCount = activeReferenceImages + activeConcepts;+ const totalCount = referenceImageCount + settings.loras.length;++ const badges = (+ <>+ {hasIncompatible ? (+ <Badge colorPalette="orange" size="xs" variant="surface">+ {t('widgets.generate.incompatible')}+ </Badge>+ ) : null}+ {activeCount > 0 ? (+ <Badge size="xs" variant="surface">+ {t('widgets.generate.activeCount', { count: activeCount })}+ </Badge>+ ) : totalCount > 0 ? (+ <Badge size="xs" variant="surface">+ {t('widgets.generate.offCount', { count: totalCount })}+ </Badge>+ ) : null}+ </>+ );++ return (+ <GenerateCollapsibleSection label={t('widgets.generate.guidance')} defaultOpen badges={badges} sectionId="guidance">+ <Stack gap="2" p="2">+ <GenerateReferenceImagesContent+ models={models}+ selectedModel={selectedModel}+ settings={settings}+ onCommit={onReferenceCommit}+ onCommitImmediate={onCommitImmediate}+ />+ {referenceImagesSupported || referenceImageCount > 0 ? <Separator borderColor="bg.subtle" /> : null}+ <GenerateConceptsContent+ loraModels={loraModels}+ projectId={projectId}+ selectedModel={selectedModel}+ settings={settings}+ onCommit={onConceptCommit}+ onCommitImmediate={onCommitImmediate}+ />+ </Stack>+ </GenerateCollapsibleSection>+ );+};diff --git a/invokeai/frontend/webv2/src/features/generation/ui/reference-images/GenerateReferenceImagesSection.tsx b/invokeai/frontend/webv2/src/features/generation/ui/reference-images/GenerateReferenceImagesSection.tsxindex f742d126d2..ac75c05df8 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/reference-images/GenerateReferenceImagesSection.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/reference-images/GenerateReferenceImagesSection.tsx@@ -8,7 +8,7 @@ import type {import type { GenerateSettingsUpdate } from '@features/generation/ui/generateDebounce';import type { ChangeEvent } from 'react';-import { Badge, HStack, Input, Stack, Text } from '@chakra-ui/react';+import { HStack, Input, Stack, Text } from '@chakra-ui/react';import { useDndMonitor } from '@dnd-kit/core';import { galleryImages, galleryTransfers } from '@features/gallery';import { isGalleryImageDragData, useGalleryImageDroppable } from '@features/gallery/utility';@@ -22,7 +22,6 @@ import {import { generatedImageToReferenceImage, getEffectiveReferenceImage } from '@features/generation/core/referenceImage';import { clampDimension, deriveAspectRatioId } from '@features/generation/core/settings';import { useGenerationUi } from '@features/generation/ui/GenerationUiContext';-import { GenerateCollapsibleSection } from '@features/generation/ui/shared/GenerateCollapsibleSection';import {assertAccountScopeCurrent,captureAccountScope,@@ -30,14 +29,14 @@ import {} from '@platform/state/accountLifecycle';import { Button, DropZone } from '@platform/ui';import { UploadIcon } from 'lucide-react';-import { useCallback, useMemo, useRef } from 'react';+import { useCallback, useRef } from 'react';import { useTranslation } from 'react-i18next';import { ReferenceImageCard } from './ReferenceImageCard';const UPLOAD_ZONE_HOVER_STYLES = { bg: 'bg.muted', color: 'fg' };-interface GenerateReferenceImagesSectionProps {+interface GenerateReferenceImagesContentProps {models: readonly ModelConfig[];selectedModel: GenerateModelConfig | undefined;settings: GenerateSettings;@@ -45,13 +44,17 @@ interface GenerateReferenceImagesSectionProps {onCommitImmediate: (patch: Partial<GenerateSettings>) => void;}-export const GenerateReferenceImagesSection = ({+/**+ * Reference-image conditioning, rendered inside the Guidance section (the+ * section chrome and combined badges live in `GenerateGuidanceSection`).+ */+export const GenerateReferenceImagesContent = ({models,onCommit,onCommitImmediate,selectedModel,settings,-}: GenerateReferenceImagesSectionProps) => {+}: GenerateReferenceImagesContentProps) => {const { t } = useTranslation();const { gallery, notifications } = useGenerationUi();const fileInputRef = useRef<HTMLInputElement | null>(null);@@ -64,7 +67,6 @@ export const GenerateReferenceImagesSection = ({disabled: !canAdd,id: 'generate-reference-images',});- const activeCount = referenceImages.filter((image) => image.isEnabled).length;const referenceImageCount = referenceImages.length;const appendReferenceImages = useCallback(@@ -206,30 +208,6 @@ export const GenerateReferenceImagesSection = ({},});- const badges = useMemo(() => {- if (!isSupported) {- return referenceImageCount > 0 ? (- <Badge colorPalette="orange" size="xs" variant="surface">- {t('widgets.generate.incompatible')}- </Badge>- ) : null;- }-- if (activeCount > 0) {- return (- <Badge size="xs" variant="surface">- {t('widgets.generate.activeCount', { count: activeCount })}- </Badge>- );- }-- return referenceImageCount > 0 ? (- <Badge size="xs" variant="surface">- {t('widgets.generate.offCount', { count: referenceImageCount })}- </Badge>- ) : null;- }, [activeCount, isSupported, referenceImageCount, t]);-if (!isSupported && referenceImageCount === 0) {return null;}@@ -238,80 +216,59 @@ export const GenerateReferenceImagesSection = ({// project). No editable cards, no add paths — just the way out.if (!isSupported) {return (- <GenerateCollapsibleSection- label={t('widgets.generate.referenceImages')}- defaultOpen- badges={badges}- sectionId="reference-images"- >- <HStack gap="2" justify="space-between" p="2">- <Text color="fg.muted" fontSize="2xs" minW="0">- {t('widgets.generate.referenceImagesUnsupported')}- </Text>- <Button colorPalette="red" flexShrink="0" size="xs" variant="outline" onClick={clearReferenceImages}>- {t('widgets.generate.clearReferenceImages')}- </Button>- </HStack>- </GenerateCollapsibleSection>+ <HStack gap="2" justify="space-between">+ <Text color="fg.muted" fontSize="2xs" minW="0">+ {t('widgets.generate.referenceImagesUnsupported')}+ </Text>+ <Button colorPalette="red" flexShrink="0" size="xs" variant="outline" onClick={clearReferenceImages}>+ {t('widgets.generate.clearReferenceImages')}+ </Button>+ </HStack>);}return (- <GenerateCollapsibleSection- label={t('widgets.generate.referenceImages')}- defaultOpen- badges={badges}- sectionId="reference-images"- >- <Stack ref={setNodeRef} gap="2" p="2">- <HStack align="stretch" gap="2">- <DropZone- as="button"- alignItems="center"- cursor={canAdd ? 'pointer' : 'not-allowed'}- display="flex"- flex="1"- fontSize="2xs"- gap="2"- isOver={isOver}- justifyContent="center"- minH="12"- minW="0"- opacity={canAdd ? 1 : 0.6}- px="3"- _hover={canAdd ? UPLOAD_ZONE_HOVER_STYLES : undefined}- onClick={handleUploadZoneClick}- >- <UploadIcon size="14" />- {t('widgets.generate.referenceImagesHelp')}- </DropZone>- </HStack>-- {referenceImageCount > 0 ? (- <Stack gap="2">- {referenceImages.map((referenceImage, index) => (- <ReferenceImageCard- key={referenceImage.id}- index={index}- referenceImage={referenceImage}- selectedModel={selectedModel}- onPatch={patchReferenceImage}- onRemove={removeReferenceImage}- onUseSize={applyReferenceImageSize}- />- ))}- </Stack>- ) : null}-- <Input- ref={fileInputRef}- accept="image/*"- display="none"- multiple- type="file"- onChange={handleFileInputChange}- />- </Stack>- </GenerateCollapsibleSection>+ <Stack ref={setNodeRef} gap="2">+ <HStack align="stretch" gap="2">+ <DropZone+ as="button"+ alignItems="center"+ cursor={canAdd ? 'pointer' : 'not-allowed'}+ display="flex"+ flex="1"+ fontSize="2xs"+ gap="2"+ isOver={isOver}+ justifyContent="center"+ minH="12"+ minW="0"+ opacity={canAdd ? 1 : 0.6}+ px="3"+ _hover={canAdd ? UPLOAD_ZONE_HOVER_STYLES : undefined}+ onClick={handleUploadZoneClick}+ >+ <UploadIcon size="14" />+ {t('widgets.generate.referenceImagesHelp')}+ </DropZone>+ </HStack>++ {referenceImageCount > 0 ? (+ <Stack gap="2">+ {referenceImages.map((referenceImage, index) => (+ <ReferenceImageCard+ key={referenceImage.id}+ index={index}+ referenceImage={referenceImage}+ selectedModel={selectedModel}+ onPatch={patchReferenceImage}+ onRemove={removeReferenceImage}+ onUseSize={applyReferenceImageSize}+ />+ ))}+ </Stack>+ ) : null}++ <Input ref={fileInputRef} accept="image/*" display="none" multiple type="file" onChange={handleFileInputChange} />+ </Stack>);};