From 643f7bbd01019df52d4942fde4e3ea4155e6cf74 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Sun, 5 Mar 2023 14:29:29 -0600 Subject: [PATCH] feat(gui): add warning when model does not support inpainting (#54) --- gui/src/components/tab/Inpaint.tsx | 23 +++++++++++++++++++++-- gui/src/strings/de.ts | 5 +++++ gui/src/strings/en.ts | 5 +++++ gui/src/strings/es.ts | 5 +++++ gui/src/strings/fr.ts | 5 +++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/gui/src/components/tab/Inpaint.tsx b/gui/src/components/tab/Inpaint.tsx index b3268c64..8d289035 100644 --- a/gui/src/components/tab/Inpaint.tsx +++ b/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'; @@ -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); @@ -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); @@ -71,8 +80,17 @@ export function Inpaint() { onSuccess: () => query.invalidateQueries({ queryKey: 'ready' }), }); + function renderBanner() { + if (supportsInpaint()) { + return undefined; + } else { + return {t('error.inpaint.support')}; + } + } + return + {renderBanner()} ; diff --git a/gui/src/strings/de.ts b/gui/src/strings/de.ts index 26a04e73..3c2a08b6 100644 --- a/gui/src/strings/de.ts +++ b/gui/src/strings/de.ts @@ -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.', diff --git a/gui/src/strings/en.ts b/gui/src/strings/en.ts index 24467588..913e6c85 100644 --- a/gui/src/strings/en.ts +++ b/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.', diff --git a/gui/src/strings/es.ts b/gui/src/strings/es.ts index 6ca861af..2b353a4f 100644 --- a/gui/src/strings/es.ts +++ b/gui/src/strings/es.ts @@ -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.', diff --git a/gui/src/strings/fr.ts b/gui/src/strings/fr.ts index 653cd23d..e43e4999 100644 --- a/gui/src/strings/fr.ts +++ b/gui/src/strings/fr.ts @@ -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.',