Skip to content

Commit

Permalink
feat(gui): add warning when model does not support inpainting (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Mar 5, 2023
1 parent 468870e commit 643f7bb
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
23 changes: 21 additions & 2 deletions gui/src/components/tab/Inpaint.tsx
@@ -1,5 +1,5 @@
import { doesExist, mustExist } from '@apextoaster/js-utils';
import { Box, Button, FormControl, FormControlLabel, InputLabel, MenuItem, Select, Stack } from '@mui/material';
import { Alert, Box, Button, FormControl, FormControlLabel, InputLabel, MenuItem, Select, Stack } from '@mui/material';
import * as React from 'react';
import { useContext } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -51,6 +51,14 @@ export function Inpaint() {
}
}

function preventInpaint(): boolean {
return doesExist(source) === false || doesExist(mask) === false;
}

function supportsInpaint(): boolean {
return diffusionModel.includes('inpaint');
}

const state = mustExist(useContext(StateContext));
const fillColor = useStore(state, (s) => s.inpaint.fillColor);
const filter = useStore(state, (s) => s.inpaint.filter);
Expand All @@ -59,6 +67,7 @@ export function Inpaint() {
const source = useStore(state, (s) => s.inpaint.source);
const strength = useStore(state, (s) => s.inpaint.strength);
const tileOrder = useStore(state, (s) => s.inpaint.tileOrder);
const diffusionModel = useStore(state, (s) => s.model.model);

// eslint-disable-next-line @typescript-eslint/unbound-method
const setInpaint = useStore(state, (s) => s.setInpaint);
Expand All @@ -71,8 +80,17 @@ export function Inpaint() {
onSuccess: () => query.invalidateQueries({ queryKey: 'ready' }),
});

function renderBanner() {
if (supportsInpaint()) {
return undefined;
} else {
return <Alert severity="warning">{t('error.inpaint.support')}</Alert>;
}
}

return <Box>
<Stack spacing={2}>
{renderBanner()}
<ImageInput
filter={IMAGE_FILTER}
image={source}
Expand Down Expand Up @@ -191,9 +209,10 @@ export function Inpaint() {
<OutpaintControl />
<UpscaleControl />
<Button
disabled={doesExist(source) === false || doesExist(mask) === false}
disabled={preventInpaint()}
variant='contained'
onClick={() => upload.mutate()}
color={supportsInpaint() ? undefined : 'warning'}
>{t('generate')}</Button>
</Stack>
</Box>;
Expand Down
5 changes: 5 additions & 0 deletions gui/src/strings/de.ts
Expand Up @@ -6,6 +6,11 @@
export const I18N_STRINGS_DE = {
de: {
translation: {
error: {
inpaint: {
support: '',
},
},
generate: 'Erzeugen',
history: {
empty: 'Keine neuere Geschichte. Drücken Sie Generieren, um ein Bild zu erstellen.',
Expand Down
5 changes: 5 additions & 0 deletions gui/src/strings/en.ts
@@ -1,6 +1,11 @@
export const I18N_STRINGS_EN = {
en: {
translation: {
error: {
inpaint: {
support: 'This diffusion model may not support inpainting.',
},
},
generate: 'Generate',
history: {
empty: 'No recent history. Press Generate to create an image.',
Expand Down
5 changes: 5 additions & 0 deletions gui/src/strings/es.ts
Expand Up @@ -6,6 +6,11 @@
export const I18N_STRINGS_ES = {
es: {
translation: {
error: {
inpaint: {
support: '',
},
},
generate: 'Generar',
history: {
empty: 'Sin antecedentes recientes. Presiona generar para crear una nueva imagen.',
Expand Down
5 changes: 5 additions & 0 deletions gui/src/strings/fr.ts
Expand Up @@ -6,6 +6,11 @@
export const I18N_STRINGS_FR = {
fr: {
translation: {
error: {
inpaint: {
support: '',
},
},
generate: 'générer',
history: {
empty: 'pas d\'histoire récente. appuyez sur générer pour créer une image.',
Expand Down

0 comments on commit 643f7bb

Please sign in to comment.