mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Improves code structure, comments, formatting, linting
This commit is contained in:
@ -1,85 +1,25 @@
|
|||||||
# Stable Diffusion Web UI
|
# Stable Diffusion Web UI
|
||||||
|
|
||||||
Demo at https://peaceful-otter-7a427f.netlify.app/ (not connected to back end)
|
## Build
|
||||||
|
|
||||||
much of this readme is just notes for myself during dev work
|
|
||||||
|
|
||||||
numpy rand: 0 to 4294967295
|
|
||||||
|
|
||||||
## Test and Build
|
|
||||||
|
|
||||||
from `frontend/`:
|
from `frontend/`:
|
||||||
|
|
||||||
- `yarn dev` runs `tsc-watch`, which runs `vite build` on successful `tsc` transpilation
|
- `yarn dev` runs vite dev server
|
||||||
|
- `yarn build-dev` builds dev
|
||||||
|
- `yarn build` builds prod
|
||||||
|
|
||||||
from `.`:
|
from `.`:
|
||||||
|
|
||||||
- `python backend/server.py` serves both frontend and backend at http://localhost:9090
|
- `python backend/server.py` serves both frontend and backend at http://localhost:9090
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
`backend/server.py` serves the UI and provides a [socket.io](https://github.com/socketio/socket.io) API via [flask-socketio](https://github.com/miguelgrinberg/flask-socketio).
|
|
||||||
|
|
||||||
### Server Listeners
|
|
||||||
|
|
||||||
The server listens for these socket.io events:
|
|
||||||
|
|
||||||
`cancel`
|
|
||||||
|
|
||||||
- Cancels in-progress image generation
|
|
||||||
- Returns ack only
|
|
||||||
|
|
||||||
`generateImage`
|
|
||||||
|
|
||||||
- Accepts object of image parameters
|
|
||||||
- Generates an image
|
|
||||||
- Returns ack only (image generation function sends progress and result via separate events)
|
|
||||||
|
|
||||||
`deleteImage`
|
|
||||||
|
|
||||||
- Accepts file path to image
|
|
||||||
- Deletes image
|
|
||||||
- Returns ack only
|
|
||||||
|
|
||||||
`deleteAllImages` WIP
|
|
||||||
|
|
||||||
- Deletes all images in `outputs/`
|
|
||||||
- Returns ack only
|
|
||||||
|
|
||||||
`requestAllImages`
|
|
||||||
|
|
||||||
- Returns array of all images in `outputs/`
|
|
||||||
|
|
||||||
`requestCapabilities` WIP
|
|
||||||
|
|
||||||
- Returns capabilities of server (torch device, GFPGAN and ESRGAN availability, ???)
|
|
||||||
|
|
||||||
`sendImage` WIP
|
|
||||||
|
|
||||||
- Accepts a File and attributes
|
|
||||||
- Saves image
|
|
||||||
- Used to save init images which are not generated images
|
|
||||||
|
|
||||||
### Server Emitters
|
|
||||||
|
|
||||||
`progress`
|
|
||||||
|
|
||||||
- Emitted during each step in generation
|
|
||||||
- Sends a number from 0 to 1 representing percentage of steps completed
|
|
||||||
|
|
||||||
`result` WIP
|
|
||||||
|
|
||||||
- Emitted when an image generation has completed
|
|
||||||
- Sends a object:
|
|
||||||
|
|
||||||
```
|
|
||||||
{
|
|
||||||
url: relative_file_path,
|
|
||||||
metadata: image_metadata_object
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- Search repo for "TODO"
|
- Search repo for "TODO"
|
||||||
- My one gripe with Chakra: no way to disable all animations right now and drop the dependence on `framer-motion`. I would prefer to save the ~30kb on bundle and have zero animations. This is on the Chakra roadmap. See https://github.com/chakra-ui/chakra-ui/pull/6368 for last discussion on this. Need to check in on this issue periodically.
|
- My one gripe with Chakra: no way to disable all animations right now and drop the dependence on
|
||||||
|
`framer-motion`. I would prefer to save the ~30kb on bundle and have zero animations. This is on
|
||||||
|
the Chakra roadmap. See https://github.com/chakra-ui/chakra-ui/pull/6368 for last discussion on
|
||||||
|
this. Need to check in on this issue periodically.
|
||||||
|
- More status info e.g. phase of processing, image we are on of the total count, etc
|
||||||
|
- Mobile friendly layout
|
||||||
|
- Proper image gallery/viewer/manager
|
||||||
|
- Instead of deleting images directly, use something like [send2trash](https://pypi.org/project/Send2Trash/)
|
||||||
|
694
frontend/dist/assets/index.3d2e59c5.js
vendored
Normal file
694
frontend/dist/assets/index.3d2e59c5.js
vendored
Normal file
File diff suppressed because one or more lines are too long
695
frontend/dist/assets/index.cc5cde43.js
vendored
695
frontend/dist/assets/index.cc5cde43.js
vendored
File diff suppressed because one or more lines are too long
2
frontend/dist/index.html
vendored
2
frontend/dist/index.html
vendored
@ -4,7 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Stable Diffusion Dream Server</title>
|
<title>Stable Diffusion Dream Server</title>
|
||||||
<script type="module" crossorigin src="/assets/index.cc5cde43.js"></script>
|
<script type="module" crossorigin src="/assets/index.3d2e59c5.js"></script>
|
||||||
<link rel="stylesheet" href="/assets/index.447eb2a9.css">
|
<link rel="stylesheet" href="/assets/index.447eb2a9.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "tsc-watch --onSuccess 'yarn run vite build -m development'",
|
"dev": "vite dev",
|
||||||
"hmr": "vite dev",
|
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"build-dev": "tsc && vite build -m development",
|
"build-dev": "tsc && vite build -m development",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Grid, GridItem } from '@chakra-ui/react';
|
import { Grid, GridItem } from '@chakra-ui/react';
|
||||||
import CurrentImage from './features/gallery/CurrentImage';
|
import CurrentImageDisplay from './features/gallery/CurrentImageDisplay';
|
||||||
import LogViewer from './features/system/LogViewer';
|
import LogViewer from './features/system/LogViewer';
|
||||||
import PromptInput from './features/sd/PromptInput';
|
import PromptInput from './features/sd/PromptInput';
|
||||||
import ProgressBar from './features/header/ProgressBar';
|
import ProgressBar from './features/header/ProgressBar';
|
||||||
@ -7,20 +7,23 @@ import { useEffect } from 'react';
|
|||||||
import { useAppDispatch } from './app/hooks';
|
import { useAppDispatch } from './app/hooks';
|
||||||
import { requestAllImages } from './app/socketio';
|
import { requestAllImages } from './app/socketio';
|
||||||
import ProcessButtons from './features/sd/ProcessButtons';
|
import ProcessButtons from './features/sd/ProcessButtons';
|
||||||
import ImageRoll from './features/gallery/ImageRoll';
|
import ImageGallery from './features/gallery/ImageGallery';
|
||||||
import SiteHeader from './features/header/SiteHeader';
|
import SiteHeader from './features/header/SiteHeader';
|
||||||
import OptionsAccordion from './features/sd/OptionsAccordion';
|
import OptionsAccordion from './features/sd/OptionsAccordion';
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
// Load images from the gallery once
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(requestAllImages());
|
dispatch(requestAllImages());
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Grid
|
<Grid
|
||||||
width='100vw'
|
width="100vw"
|
||||||
height='100vh'
|
height="100vh"
|
||||||
templateAreas={`
|
templateAreas={`
|
||||||
"header header header header"
|
"header header header header"
|
||||||
"progressBar progressBar progressBar progressBar"
|
"progressBar progressBar progressBar progressBar"
|
||||||
@ -36,7 +39,7 @@ const App = () => {
|
|||||||
<GridItem area={'progressBar'}>
|
<GridItem area={'progressBar'}>
|
||||||
<ProgressBar />
|
<ProgressBar />
|
||||||
</GridItem>
|
</GridItem>
|
||||||
<GridItem pl='2' area={'menu'} overflowY='scroll'>
|
<GridItem pl="2" area={'menu'} overflowY="scroll">
|
||||||
<OptionsAccordion />
|
<OptionsAccordion />
|
||||||
</GridItem>
|
</GridItem>
|
||||||
<GridItem area={'prompt'}>
|
<GridItem area={'prompt'}>
|
||||||
@ -46,10 +49,10 @@ const App = () => {
|
|||||||
<ProcessButtons />
|
<ProcessButtons />
|
||||||
</GridItem>
|
</GridItem>
|
||||||
<GridItem area={'currentImage'}>
|
<GridItem area={'currentImage'}>
|
||||||
<CurrentImage />
|
<CurrentImageDisplay />
|
||||||
</GridItem>
|
</GridItem>
|
||||||
<GridItem pr='2' area={'imageRoll'} overflowY='scroll'>
|
<GridItem pr="2" area={'imageRoll'} overflowY="scroll">
|
||||||
<ImageRoll />
|
<ImageGallery />
|
||||||
</GridItem>
|
</GridItem>
|
||||||
</Grid>
|
</Grid>
|
||||||
<LogViewer />
|
<LogViewer />
|
||||||
|
@ -32,7 +32,7 @@ export const frontendToBackendParameters = (
|
|||||||
maskPath,
|
maskPath,
|
||||||
shouldFitToWidthHeight,
|
shouldFitToWidthHeight,
|
||||||
shouldGenerateVariations,
|
shouldGenerateVariations,
|
||||||
variantAmount,
|
variationAmount,
|
||||||
seedWeights,
|
seedWeights,
|
||||||
shouldRunESRGAN,
|
shouldRunESRGAN,
|
||||||
upscalingLevel,
|
upscalingLevel,
|
||||||
@ -71,13 +71,13 @@ export const frontendToBackendParameters = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shouldGenerateVariations) {
|
if (shouldGenerateVariations) {
|
||||||
generationParameters.variation_amount = variantAmount;
|
generationParameters.variation_amount = variationAmount;
|
||||||
if (seedWeights) {
|
if (seedWeights) {
|
||||||
generationParameters.with_variations =
|
generationParameters.with_variations =
|
||||||
stringToSeedWeights(seedWeights);
|
stringToSeedWeights(seedWeights);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
generationParameters.variation_amount = 0;
|
generationParameters.variation_amount = 0.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let esrganParameters: false | { [k: string]: any } = false;
|
let esrganParameters: false | { [k: string]: any } = false;
|
||||||
@ -138,7 +138,7 @@ export const backendToFrontendParameters = (parameters: {
|
|||||||
|
|
||||||
if (variation_amount > 0) {
|
if (variation_amount > 0) {
|
||||||
sd.shouldGenerateVariations = true;
|
sd.shouldGenerateVariations = true;
|
||||||
sd.variantAmount = variation_amount;
|
sd.variationAmount = variation_amount;
|
||||||
if (with_variations) {
|
if (with_variations) {
|
||||||
sd.seedWeights = seedWeightsToString(with_variations);
|
sd.seedWeights = seedWeightsToString(with_variations);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,11 @@ interface Props extends ButtonProps {
|
|||||||
label: string;
|
label: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reusable customized button component. Originally was more customized - now probably unecessary.
|
||||||
|
*
|
||||||
|
* TODO: Get rid of this.
|
||||||
|
*/
|
||||||
const SDButton = (props: Props) => {
|
const SDButton = (props: Props) => {
|
||||||
const { label, size = 'sm', ...rest } = props;
|
const { label, size = 'sm', ...rest } = props;
|
||||||
return (
|
return (
|
||||||
|
@ -16,6 +16,9 @@ interface Props extends NumberInputProps {
|
|||||||
width?: string | number;
|
width?: string | number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customized Chakra FormControl + NumberInput multi-part component.
|
||||||
|
*/
|
||||||
const SDNumberInput = (props: Props) => {
|
const SDNumberInput = (props: Props) => {
|
||||||
const {
|
const {
|
||||||
label,
|
label,
|
||||||
@ -31,7 +34,7 @@ const SDNumberInput = (props: Props) => {
|
|||||||
<Flex gap={2} justifyContent={'space-between'} alignItems={'center'}>
|
<Flex gap={2} justifyContent={'space-between'} alignItems={'center'}>
|
||||||
{label && (
|
{label && (
|
||||||
<FormLabel marginBottom={1}>
|
<FormLabel marginBottom={1}>
|
||||||
<Text fontSize={fontSize} whiteSpace='nowrap'>
|
<Text fontSize={fontSize} whiteSpace="nowrap">
|
||||||
{label}
|
{label}
|
||||||
</Text>
|
</Text>
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
|
@ -13,7 +13,9 @@ interface Props extends SelectProps {
|
|||||||
| Array<number | string>
|
| Array<number | string>
|
||||||
| Array<{ key: string; value: string | number }>;
|
| Array<{ key: string; value: string | number }>;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Customized Chakra FormControl + Select multi-part component.
|
||||||
|
*/
|
||||||
const SDSelect = (props: Props) => {
|
const SDSelect = (props: Props) => {
|
||||||
const {
|
const {
|
||||||
label,
|
label,
|
||||||
@ -28,17 +30,14 @@ const SDSelect = (props: Props) => {
|
|||||||
return (
|
return (
|
||||||
<FormControl isDisabled={isDisabled}>
|
<FormControl isDisabled={isDisabled}>
|
||||||
<Flex justifyContent={'space-between'} alignItems={'center'}>
|
<Flex justifyContent={'space-between'} alignItems={'center'}>
|
||||||
<FormLabel
|
<FormLabel marginBottom={marginBottom}>
|
||||||
marginBottom={marginBottom}
|
|
||||||
>
|
|
||||||
<Text fontSize={fontSize} whiteSpace={whiteSpace}>
|
<Text fontSize={fontSize} whiteSpace={whiteSpace}>
|
||||||
{label}
|
{label}
|
||||||
</Text>
|
</Text>
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<Select fontSize={fontSize} size={size} {...rest}>
|
<Select fontSize={fontSize} size={size} {...rest}>
|
||||||
{validValues.map((opt) => {
|
{validValues.map((opt) => {
|
||||||
return typeof opt === 'string' ||
|
return typeof opt === 'string' || typeof opt === 'number' ? (
|
||||||
typeof opt === 'number' ? (
|
|
||||||
<option key={opt} value={opt}>
|
<option key={opt} value={opt}>
|
||||||
{opt}
|
{opt}
|
||||||
</option>
|
</option>
|
||||||
|
@ -11,6 +11,9 @@ interface Props extends SwitchProps {
|
|||||||
width?: string | number;
|
width?: string | number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Customized Chakra FormControl + Switch multi-part component.
|
||||||
|
*/
|
||||||
const SDSwitch = (props: Props) => {
|
const SDSwitch = (props: Props) => {
|
||||||
const {
|
const {
|
||||||
label,
|
label,
|
||||||
@ -28,7 +31,7 @@ const SDSwitch = (props: Props) => {
|
|||||||
fontSize={fontSize}
|
fontSize={fontSize}
|
||||||
marginBottom={1}
|
marginBottom={1}
|
||||||
flexGrow={2}
|
flexGrow={2}
|
||||||
whiteSpace='nowrap'
|
whiteSpace="nowrap"
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
|
@ -1,161 +0,0 @@
|
|||||||
import { Center, Flex, Image, useColorModeValue } from '@chakra-ui/react';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
|
||||||
import { RootState } from '../../app/store';
|
|
||||||
import { setAllParameters, setInitialImagePath, setSeed } from '../sd/sdSlice';
|
|
||||||
import { useState } from 'react';
|
|
||||||
import ImageMetadataViewer from './ImageMetadataViewer';
|
|
||||||
import DeleteImageModalButton from './DeleteImageModalButton';
|
|
||||||
import SDButton from '../../components/SDButton';
|
|
||||||
import { runESRGAN, runGFPGAN } from '../../app/socketio';
|
|
||||||
import { createSelector } from '@reduxjs/toolkit';
|
|
||||||
import { SystemState } from '../system/systemSlice';
|
|
||||||
import { isEqual } from 'lodash';
|
|
||||||
|
|
||||||
const height = 'calc(100vh - 238px)';
|
|
||||||
|
|
||||||
const systemSelector = createSelector(
|
|
||||||
(state: RootState) => state.system,
|
|
||||||
(system: SystemState) => {
|
|
||||||
return {
|
|
||||||
isProcessing: system.isProcessing,
|
|
||||||
isConnected: system.isConnected,
|
|
||||||
isGFPGANAvailable: system.isGFPGANAvailable,
|
|
||||||
isESRGANAvailable: system.isESRGANAvailable,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
{
|
|
||||||
memoizeOptions: {
|
|
||||||
resultEqualityCheck: isEqual,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const CurrentImage = () => {
|
|
||||||
const { currentImage, intermediateImage } = useAppSelector(
|
|
||||||
(state: RootState) => state.gallery
|
|
||||||
);
|
|
||||||
const { isProcessing, isConnected, isGFPGANAvailable, isESRGANAvailable } =
|
|
||||||
useAppSelector(systemSelector);
|
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
|
|
||||||
const bgColor = useColorModeValue(
|
|
||||||
'rgba(255, 255, 255, 0.85)',
|
|
||||||
'rgba(0, 0, 0, 0.8)'
|
|
||||||
);
|
|
||||||
|
|
||||||
const [shouldShowImageDetails, setShouldShowImageDetails] =
|
|
||||||
useState<boolean>(false);
|
|
||||||
|
|
||||||
const imageToDisplay = intermediateImage || currentImage;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Flex direction={'column'} rounded={'md'} borderWidth={1} p={2} gap={2}>
|
|
||||||
{imageToDisplay && (
|
|
||||||
<Flex gap={2}>
|
|
||||||
<SDButton
|
|
||||||
label='Use as initial image'
|
|
||||||
colorScheme={'gray'}
|
|
||||||
flexGrow={1}
|
|
||||||
variant={'outline'}
|
|
||||||
onClick={() =>
|
|
||||||
dispatch(setInitialImagePath(imageToDisplay.url))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<SDButton
|
|
||||||
label='Use all'
|
|
||||||
colorScheme={'gray'}
|
|
||||||
flexGrow={1}
|
|
||||||
variant={'outline'}
|
|
||||||
onClick={() =>
|
|
||||||
dispatch(setAllParameters(imageToDisplay.metadata))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<SDButton
|
|
||||||
label='Use seed'
|
|
||||||
colorScheme={'gray'}
|
|
||||||
flexGrow={1}
|
|
||||||
variant={'outline'}
|
|
||||||
isDisabled={!imageToDisplay.metadata.seed}
|
|
||||||
onClick={() =>
|
|
||||||
dispatch(setSeed(imageToDisplay.metadata.seed!))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<SDButton
|
|
||||||
label='Upscale'
|
|
||||||
colorScheme={'gray'}
|
|
||||||
flexGrow={1}
|
|
||||||
variant={'outline'}
|
|
||||||
isDisabled={
|
|
||||||
!isESRGANAvailable ||
|
|
||||||
Boolean(intermediateImage) ||
|
|
||||||
!(isConnected && !isProcessing)
|
|
||||||
}
|
|
||||||
onClick={() => dispatch(runESRGAN(imageToDisplay))}
|
|
||||||
/>
|
|
||||||
<SDButton
|
|
||||||
label='Fix faces'
|
|
||||||
colorScheme={'gray'}
|
|
||||||
flexGrow={1}
|
|
||||||
variant={'outline'}
|
|
||||||
isDisabled={
|
|
||||||
!isGFPGANAvailable ||
|
|
||||||
Boolean(intermediateImage) ||
|
|
||||||
!(isConnected && !isProcessing)
|
|
||||||
}
|
|
||||||
onClick={() => dispatch(runGFPGAN(imageToDisplay))}
|
|
||||||
/>
|
|
||||||
<SDButton
|
|
||||||
label='Details'
|
|
||||||
colorScheme={'gray'}
|
|
||||||
variant={shouldShowImageDetails ? 'solid' : 'outline'}
|
|
||||||
borderWidth={1}
|
|
||||||
flexGrow={1}
|
|
||||||
onClick={() =>
|
|
||||||
setShouldShowImageDetails(!shouldShowImageDetails)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<DeleteImageModalButton image={imageToDisplay}>
|
|
||||||
<SDButton
|
|
||||||
label='Delete'
|
|
||||||
colorScheme={'red'}
|
|
||||||
flexGrow={1}
|
|
||||||
variant={'outline'}
|
|
||||||
isDisabled={Boolean(intermediateImage)}
|
|
||||||
/>
|
|
||||||
</DeleteImageModalButton>
|
|
||||||
</Flex>
|
|
||||||
)}
|
|
||||||
<Center height={height} position={'relative'}>
|
|
||||||
{imageToDisplay && (
|
|
||||||
<Image
|
|
||||||
src={imageToDisplay.url}
|
|
||||||
fit='contain'
|
|
||||||
maxWidth={'100%'}
|
|
||||||
maxHeight={'100%'}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{imageToDisplay && shouldShowImageDetails && (
|
|
||||||
<Flex
|
|
||||||
width={'100%'}
|
|
||||||
height={'100%'}
|
|
||||||
position={'absolute'}
|
|
||||||
top={0}
|
|
||||||
left={0}
|
|
||||||
p={3}
|
|
||||||
boxSizing='border-box'
|
|
||||||
backgroundColor={bgColor}
|
|
||||||
overflow='scroll'
|
|
||||||
>
|
|
||||||
<ImageMetadataViewer image={imageToDisplay} />
|
|
||||||
</Flex>
|
|
||||||
)}
|
|
||||||
</Center>
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default CurrentImage;
|
|
141
frontend/src/features/gallery/CurrentImageButtons.tsx
Normal file
141
frontend/src/features/gallery/CurrentImageButtons.tsx
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
import { Flex } from '@chakra-ui/react';
|
||||||
|
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
||||||
|
import { RootState } from '../../app/store';
|
||||||
|
import { setAllParameters, setInitialImagePath, setSeed } from '../sd/sdSlice';
|
||||||
|
import DeleteImageModal from './DeleteImageModal';
|
||||||
|
import SDButton from '../../components/SDButton';
|
||||||
|
import { runESRGAN, runGFPGAN } from '../../app/socketio';
|
||||||
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
|
import { SystemState } from '../system/systemSlice';
|
||||||
|
import { isEqual } from 'lodash';
|
||||||
|
import { SDImage } from './gallerySlice';
|
||||||
|
|
||||||
|
const systemSelector = createSelector(
|
||||||
|
(state: RootState) => state.system,
|
||||||
|
(system: SystemState) => {
|
||||||
|
return {
|
||||||
|
isProcessing: system.isProcessing,
|
||||||
|
isConnected: system.isConnected,
|
||||||
|
isGFPGANAvailable: system.isGFPGANAvailable,
|
||||||
|
isESRGANAvailable: system.isESRGANAvailable,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
|
memoizeOptions: {
|
||||||
|
resultEqualityCheck: isEqual,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
type CurrentImageButtonsProps = {
|
||||||
|
image: SDImage;
|
||||||
|
shouldShowImageDetails: boolean;
|
||||||
|
setShouldShowImageDetails: (b: boolean) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Row of buttons for common actions:
|
||||||
|
* Use as init image, use all params, use seed, upscale, fix faces, details, delete.
|
||||||
|
*/
|
||||||
|
const CurrentImageButtons = ({
|
||||||
|
image,
|
||||||
|
shouldShowImageDetails,
|
||||||
|
setShouldShowImageDetails,
|
||||||
|
}: CurrentImageButtonsProps) => {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { intermediateImage } = useAppSelector(
|
||||||
|
(state: RootState) => state.gallery
|
||||||
|
);
|
||||||
|
const { isProcessing, isConnected, isGFPGANAvailable, isESRGANAvailable } =
|
||||||
|
useAppSelector(systemSelector);
|
||||||
|
|
||||||
|
const handleClickUseAsInitialImage = () =>
|
||||||
|
dispatch(setInitialImagePath(image.url));
|
||||||
|
|
||||||
|
const handleClickUseAllParameters = () =>
|
||||||
|
dispatch(setAllParameters(image.metadata));
|
||||||
|
|
||||||
|
// Non-null assertion: this button is disabled if there is no seed.
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
const handleClickUseSeed = () => dispatch(setSeed(image.metadata.seed!));
|
||||||
|
|
||||||
|
const handleClickUpscale = () => dispatch(runESRGAN(image));
|
||||||
|
|
||||||
|
const handleClickFixFaces = () => dispatch(runGFPGAN(image));
|
||||||
|
|
||||||
|
const handleClickShowImageDetails = () =>
|
||||||
|
setShouldShowImageDetails(!shouldShowImageDetails);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flex gap={2}>
|
||||||
|
<SDButton
|
||||||
|
label="Use as initial image"
|
||||||
|
colorScheme={'gray'}
|
||||||
|
flexGrow={1}
|
||||||
|
variant={'outline'}
|
||||||
|
onClick={handleClickUseAsInitialImage}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<SDButton
|
||||||
|
label="Use all"
|
||||||
|
colorScheme={'gray'}
|
||||||
|
flexGrow={1}
|
||||||
|
variant={'outline'}
|
||||||
|
onClick={handleClickUseAllParameters}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<SDButton
|
||||||
|
label="Use seed"
|
||||||
|
colorScheme={'gray'}
|
||||||
|
flexGrow={1}
|
||||||
|
variant={'outline'}
|
||||||
|
isDisabled={!image.metadata.seed}
|
||||||
|
onClick={handleClickUseSeed}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<SDButton
|
||||||
|
label="Upscale"
|
||||||
|
colorScheme={'gray'}
|
||||||
|
flexGrow={1}
|
||||||
|
variant={'outline'}
|
||||||
|
isDisabled={
|
||||||
|
!isESRGANAvailable ||
|
||||||
|
Boolean(intermediateImage) ||
|
||||||
|
!(isConnected && !isProcessing)
|
||||||
|
}
|
||||||
|
onClick={handleClickUpscale}
|
||||||
|
/>
|
||||||
|
<SDButton
|
||||||
|
label="Fix faces"
|
||||||
|
colorScheme={'gray'}
|
||||||
|
flexGrow={1}
|
||||||
|
variant={'outline'}
|
||||||
|
isDisabled={
|
||||||
|
!isGFPGANAvailable ||
|
||||||
|
Boolean(intermediateImage) ||
|
||||||
|
!(isConnected && !isProcessing)
|
||||||
|
}
|
||||||
|
onClick={handleClickFixFaces}
|
||||||
|
/>
|
||||||
|
<SDButton
|
||||||
|
label="Details"
|
||||||
|
colorScheme={'gray'}
|
||||||
|
variant={shouldShowImageDetails ? 'solid' : 'outline'}
|
||||||
|
borderWidth={1}
|
||||||
|
flexGrow={1}
|
||||||
|
onClick={handleClickShowImageDetails}
|
||||||
|
/>
|
||||||
|
<DeleteImageModal image={image}>
|
||||||
|
<SDButton
|
||||||
|
label="Delete"
|
||||||
|
colorScheme={'red'}
|
||||||
|
flexGrow={1}
|
||||||
|
variant={'outline'}
|
||||||
|
isDisabled={Boolean(intermediateImage)}
|
||||||
|
/>
|
||||||
|
</DeleteImageModal>
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CurrentImageButtons;
|
67
frontend/src/features/gallery/CurrentImageDisplay.tsx
Normal file
67
frontend/src/features/gallery/CurrentImageDisplay.tsx
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import { Center, Flex, Image, Text, useColorModeValue } from '@chakra-ui/react';
|
||||||
|
import { useAppSelector } from '../../app/hooks';
|
||||||
|
import { RootState } from '../../app/store';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import ImageMetadataViewer from './ImageMetadataViewer';
|
||||||
|
import CurrentImageButtons from './CurrentImageButtons';
|
||||||
|
|
||||||
|
// TODO: With CSS Grid I had a hard time centering the image in a grid item. This is needed for that.
|
||||||
|
const height = 'calc(100vh - 238px)';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the current image if there is one, plus associated actions.
|
||||||
|
*/
|
||||||
|
const CurrentImageDisplay = () => {
|
||||||
|
const { currentImage, intermediateImage } = useAppSelector(
|
||||||
|
(state: RootState) => state.gallery
|
||||||
|
);
|
||||||
|
|
||||||
|
const bgColor = useColorModeValue(
|
||||||
|
'rgba(255, 255, 255, 0.85)',
|
||||||
|
'rgba(0, 0, 0, 0.8)'
|
||||||
|
);
|
||||||
|
|
||||||
|
const [shouldShowImageDetails, setShouldShowImageDetails] =
|
||||||
|
useState<boolean>(false);
|
||||||
|
|
||||||
|
const imageToDisplay = intermediateImage || currentImage;
|
||||||
|
|
||||||
|
return imageToDisplay ? (
|
||||||
|
<Flex direction={'column'} borderWidth={1} rounded={'md'} p={2} gap={2}>
|
||||||
|
<CurrentImageButtons
|
||||||
|
image={imageToDisplay}
|
||||||
|
shouldShowImageDetails={shouldShowImageDetails}
|
||||||
|
setShouldShowImageDetails={setShouldShowImageDetails}
|
||||||
|
/>
|
||||||
|
<Center height={height} position={'relative'}>
|
||||||
|
<Image
|
||||||
|
src={imageToDisplay.url}
|
||||||
|
fit="contain"
|
||||||
|
maxWidth={'100%'}
|
||||||
|
maxHeight={'100%'}
|
||||||
|
/>
|
||||||
|
{shouldShowImageDetails && (
|
||||||
|
<Flex
|
||||||
|
width={'100%'}
|
||||||
|
height={'100%'}
|
||||||
|
position={'absolute'}
|
||||||
|
top={0}
|
||||||
|
left={0}
|
||||||
|
p={3}
|
||||||
|
boxSizing="border-box"
|
||||||
|
backgroundColor={bgColor}
|
||||||
|
overflow="scroll"
|
||||||
|
>
|
||||||
|
<ImageMetadataViewer image={imageToDisplay} />
|
||||||
|
</Flex>
|
||||||
|
)}
|
||||||
|
</Center>
|
||||||
|
</Flex>
|
||||||
|
) : (
|
||||||
|
<Center height={'100%'} position={'relative'}>
|
||||||
|
<Text size={'xl'}>No image selected</Text>
|
||||||
|
</Center>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CurrentImageDisplay;
|
121
frontend/src/features/gallery/DeleteImageModal.tsx
Normal file
121
frontend/src/features/gallery/DeleteImageModal.tsx
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
import {
|
||||||
|
Text,
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogBody,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogOverlay,
|
||||||
|
useDisclosure,
|
||||||
|
Button,
|
||||||
|
Switch,
|
||||||
|
FormControl,
|
||||||
|
FormLabel,
|
||||||
|
Flex,
|
||||||
|
} from '@chakra-ui/react';
|
||||||
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
|
import {
|
||||||
|
ChangeEvent,
|
||||||
|
cloneElement,
|
||||||
|
ReactElement,
|
||||||
|
SyntheticEvent,
|
||||||
|
useRef,
|
||||||
|
} from 'react';
|
||||||
|
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
||||||
|
import { deleteImage } from '../../app/socketio';
|
||||||
|
import { RootState } from '../../app/store';
|
||||||
|
import { setShouldConfirmOnDelete, SystemState } from '../system/systemSlice';
|
||||||
|
import { SDImage } from './gallerySlice';
|
||||||
|
|
||||||
|
interface DeleteImageModalProps {
|
||||||
|
/**
|
||||||
|
* Component which, on click, should delete the image/open the modal.
|
||||||
|
*/
|
||||||
|
children: ReactElement;
|
||||||
|
/**
|
||||||
|
* The image to delete.
|
||||||
|
*/
|
||||||
|
image: SDImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
const systemSelector = createSelector(
|
||||||
|
(state: RootState) => state.system,
|
||||||
|
(system: SystemState) => system.shouldConfirmOnDelete
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Needs a child, which will act as the button to delete an image.
|
||||||
|
* If system.shouldConfirmOnDelete is true, a confirmation modal is displayed.
|
||||||
|
* If it is false, the image is deleted immediately.
|
||||||
|
* The confirmation modal has a "Don't ask me again" switch to set the boolean.
|
||||||
|
*/
|
||||||
|
const DeleteImageModal = ({ image, children }: DeleteImageModalProps) => {
|
||||||
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const shouldConfirmOnDelete = useAppSelector(systemSelector);
|
||||||
|
const cancelRef = useRef<HTMLButtonElement>(null);
|
||||||
|
|
||||||
|
const handleClickDelete = (e: SyntheticEvent) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
shouldConfirmOnDelete ? onOpen() : handleDelete();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = () => {
|
||||||
|
dispatch(deleteImage(image));
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChangeShouldConfirmOnDelete = (
|
||||||
|
e: ChangeEvent<HTMLInputElement>
|
||||||
|
) => dispatch(setShouldConfirmOnDelete(!e.target.checked));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{cloneElement(children, {
|
||||||
|
// TODO: This feels wrong.
|
||||||
|
onClick: handleClickDelete,
|
||||||
|
})}
|
||||||
|
|
||||||
|
<AlertDialog
|
||||||
|
isOpen={isOpen}
|
||||||
|
leastDestructiveRef={cancelRef}
|
||||||
|
onClose={onClose}
|
||||||
|
>
|
||||||
|
<AlertDialogOverlay>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader fontSize="lg" fontWeight="bold">
|
||||||
|
Delete image
|
||||||
|
</AlertDialogHeader>
|
||||||
|
|
||||||
|
<AlertDialogBody>
|
||||||
|
<Flex direction={'column'} gap={5}>
|
||||||
|
<Text>
|
||||||
|
Are you sure? You can't undo this action afterwards.
|
||||||
|
</Text>
|
||||||
|
<FormControl>
|
||||||
|
<Flex alignItems={'center'}>
|
||||||
|
<FormLabel mb={0}>Don't ask me again</FormLabel>
|
||||||
|
<Switch
|
||||||
|
checked={!shouldConfirmOnDelete}
|
||||||
|
onChange={handleChangeShouldConfirmOnDelete}
|
||||||
|
/>
|
||||||
|
</Flex>
|
||||||
|
</FormControl>
|
||||||
|
</Flex>
|
||||||
|
</AlertDialogBody>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<Button ref={cancelRef} onClick={onClose}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button colorScheme="red" onClick={handleDelete} ml={3}>
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialogOverlay>
|
||||||
|
</AlertDialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DeleteImageModal;
|
@ -1,94 +0,0 @@
|
|||||||
import {
|
|
||||||
IconButtonProps,
|
|
||||||
Modal,
|
|
||||||
ModalBody,
|
|
||||||
ModalCloseButton,
|
|
||||||
ModalContent,
|
|
||||||
ModalFooter,
|
|
||||||
ModalHeader,
|
|
||||||
ModalOverlay,
|
|
||||||
Text,
|
|
||||||
useDisclosure,
|
|
||||||
} from '@chakra-ui/react';
|
|
||||||
import { createSelector } from '@reduxjs/toolkit';
|
|
||||||
import {
|
|
||||||
cloneElement,
|
|
||||||
ReactElement,
|
|
||||||
SyntheticEvent,
|
|
||||||
} from 'react';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
|
||||||
import { deleteImage } from '../../app/socketio';
|
|
||||||
import { RootState } from '../../app/store';
|
|
||||||
import SDButton from '../../components/SDButton';
|
|
||||||
import { setShouldConfirmOnDelete, SystemState } from '../system/systemSlice';
|
|
||||||
import { SDImage } from './gallerySlice';
|
|
||||||
|
|
||||||
interface Props extends IconButtonProps {
|
|
||||||
image: SDImage;
|
|
||||||
'aria-label': string;
|
|
||||||
children: ReactElement;
|
|
||||||
}
|
|
||||||
|
|
||||||
const systemSelector = createSelector(
|
|
||||||
(state: RootState) => state.system,
|
|
||||||
(system: SystemState) => system.shouldConfirmOnDelete
|
|
||||||
);
|
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: The modal and button to open it should be two different components,
|
|
||||||
but their state is closely related and I'm not sure how best to accomplish it.
|
|
||||||
*/
|
|
||||||
const DeleteImageModalButton = (props: Omit<Props, 'aria-label'>) => {
|
|
||||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
const shouldConfirmOnDelete = useAppSelector(systemSelector);
|
|
||||||
|
|
||||||
const handleClickDelete = (e: SyntheticEvent) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
shouldConfirmOnDelete ? onOpen() : handleDelete();
|
|
||||||
};
|
|
||||||
|
|
||||||
const { image, children } = props;
|
|
||||||
|
|
||||||
const handleDelete = () => {
|
|
||||||
dispatch(deleteImage(image));
|
|
||||||
onClose();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDeleteAndDontAsk = () => {
|
|
||||||
dispatch(deleteImage(image));
|
|
||||||
dispatch(setShouldConfirmOnDelete(false));
|
|
||||||
onClose();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{cloneElement(children, {
|
|
||||||
onClick: handleClickDelete,
|
|
||||||
})}
|
|
||||||
|
|
||||||
<Modal isOpen={isOpen} onClose={onClose}>
|
|
||||||
<ModalOverlay />
|
|
||||||
<ModalContent>
|
|
||||||
<ModalHeader>Are you sure you want to delete this image?</ModalHeader>
|
|
||||||
<ModalCloseButton />
|
|
||||||
<ModalBody>
|
|
||||||
<Text>It will be deleted forever!</Text>
|
|
||||||
</ModalBody>
|
|
||||||
|
|
||||||
<ModalFooter justifyContent={'space-between'}>
|
|
||||||
<SDButton label={'Yes'} colorScheme='red' onClick={handleDelete} />
|
|
||||||
<SDButton
|
|
||||||
label={"Yes, and don't ask me again"}
|
|
||||||
colorScheme='red'
|
|
||||||
onClick={handleDeleteAndDontAsk}
|
|
||||||
/>
|
|
||||||
<SDButton label='Cancel' colorScheme='blue' onClick={onClose} />
|
|
||||||
</ModalFooter>
|
|
||||||
</ModalContent>
|
|
||||||
</Modal>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DeleteImageModalButton;
|
|
131
frontend/src/features/gallery/HoverableImage.tsx
Normal file
131
frontend/src/features/gallery/HoverableImage.tsx
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
import {
|
||||||
|
Box,
|
||||||
|
Flex,
|
||||||
|
Icon,
|
||||||
|
IconButton,
|
||||||
|
Image,
|
||||||
|
useColorModeValue,
|
||||||
|
} from '@chakra-ui/react';
|
||||||
|
import { useAppDispatch } from '../../app/hooks';
|
||||||
|
import { SDImage, setCurrentImage } from './gallerySlice';
|
||||||
|
import { FaCheck, FaCopy, FaSeedling, FaTrash } from 'react-icons/fa';
|
||||||
|
import DeleteImageModal from './DeleteImageModal';
|
||||||
|
import { memo, SyntheticEvent, useState } from 'react';
|
||||||
|
import { setAllParameters, setSeed } from '../sd/sdSlice';
|
||||||
|
|
||||||
|
interface HoverableImageProps {
|
||||||
|
image: SDImage;
|
||||||
|
isSelected: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const memoEqualityCheck = (
|
||||||
|
prev: HoverableImageProps,
|
||||||
|
next: HoverableImageProps
|
||||||
|
) => prev.image.uuid === next.image.uuid && prev.isSelected === next.isSelected;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gallery image component with delete/use all/use seed buttons on hover.
|
||||||
|
*/
|
||||||
|
const HoverableImage = memo((props: HoverableImageProps) => {
|
||||||
|
const [isHovered, setIsHovered] = useState<boolean>(false);
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
const checkColor = useColorModeValue('green.600', 'green.300');
|
||||||
|
const bgColor = useColorModeValue('gray.200', 'gray.700');
|
||||||
|
const bgGradient = useColorModeValue(
|
||||||
|
'radial-gradient(circle, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0.7) 20%, rgba(0,0,0,0) 100%)',
|
||||||
|
'radial-gradient(circle, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.7) 20%, rgba(0,0,0,0) 100%)'
|
||||||
|
);
|
||||||
|
|
||||||
|
const { image, isSelected } = props;
|
||||||
|
const { url, uuid, metadata } = image;
|
||||||
|
|
||||||
|
const handleMouseOver = () => setIsHovered(true);
|
||||||
|
const handleMouseOut = () => setIsHovered(false);
|
||||||
|
|
||||||
|
const handleClickSetAllParameters = (e: SyntheticEvent) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
dispatch(setAllParameters(metadata));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClickSetSeed = (e: SyntheticEvent) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
// Non-null assertion: this button is not rendered unless this exists
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
dispatch(setSeed(image.metadata.seed!));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClickImage = () => dispatch(setCurrentImage(image));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box position={'relative'} key={uuid}>
|
||||||
|
<Image
|
||||||
|
width={120}
|
||||||
|
height={120}
|
||||||
|
objectFit="cover"
|
||||||
|
rounded={'md'}
|
||||||
|
src={url}
|
||||||
|
loading={'lazy'}
|
||||||
|
backgroundColor={bgColor}
|
||||||
|
/>
|
||||||
|
<Flex
|
||||||
|
cursor={'pointer'}
|
||||||
|
position={'absolute'}
|
||||||
|
top={0}
|
||||||
|
left={0}
|
||||||
|
rounded={'md'}
|
||||||
|
width="100%"
|
||||||
|
height="100%"
|
||||||
|
alignItems={'center'}
|
||||||
|
justifyContent={'center'}
|
||||||
|
background={isSelected ? bgGradient : undefined}
|
||||||
|
onClick={handleClickImage}
|
||||||
|
onMouseOver={handleMouseOver}
|
||||||
|
onMouseOut={handleMouseOut}
|
||||||
|
>
|
||||||
|
{isSelected && (
|
||||||
|
<Icon fill={checkColor} width={'50%'} height={'50%'} as={FaCheck} />
|
||||||
|
)}
|
||||||
|
{isHovered && (
|
||||||
|
<Flex
|
||||||
|
direction={'column'}
|
||||||
|
gap={1}
|
||||||
|
position={'absolute'}
|
||||||
|
top={1}
|
||||||
|
right={1}
|
||||||
|
>
|
||||||
|
<DeleteImageModal image={image}>
|
||||||
|
<IconButton
|
||||||
|
colorScheme="red"
|
||||||
|
aria-label="Delete image"
|
||||||
|
icon={<FaTrash />}
|
||||||
|
size="xs"
|
||||||
|
fontSize={15}
|
||||||
|
/>
|
||||||
|
</DeleteImageModal>
|
||||||
|
<IconButton
|
||||||
|
aria-label="Use all parameters"
|
||||||
|
colorScheme={'blue'}
|
||||||
|
icon={<FaCopy />}
|
||||||
|
size="xs"
|
||||||
|
fontSize={15}
|
||||||
|
onClickCapture={handleClickSetAllParameters}
|
||||||
|
/>
|
||||||
|
{image.metadata.seed && (
|
||||||
|
<IconButton
|
||||||
|
aria-label="Use seed"
|
||||||
|
colorScheme={'blue'}
|
||||||
|
icon={<FaSeedling />}
|
||||||
|
size="xs"
|
||||||
|
fontSize={16}
|
||||||
|
onClickCapture={handleClickSetSeed}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Flex>
|
||||||
|
)}
|
||||||
|
</Flex>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}, memoEqualityCheck);
|
||||||
|
|
||||||
|
export default HoverableImage;
|
35
frontend/src/features/gallery/ImageGallery.tsx
Normal file
35
frontend/src/features/gallery/ImageGallery.tsx
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { Flex } from '@chakra-ui/react';
|
||||||
|
import { RootState } from '../../app/store';
|
||||||
|
import { useAppSelector } from '../../app/hooks';
|
||||||
|
import HoverableImage from './HoverableImage';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple image gallery.
|
||||||
|
*/
|
||||||
|
const ImageGallery = () => {
|
||||||
|
const { images, currentImageUuid } = useAppSelector(
|
||||||
|
(state: RootState) => state.gallery
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* I don't like that this needs to rerender whenever the current image is changed.
|
||||||
|
* What if we have a large number of images? I suppose pagination (planned) will
|
||||||
|
* mitigate this issue.
|
||||||
|
*
|
||||||
|
* TODO: Refactor if performance complaints, or after migrating to new API which supports pagination.
|
||||||
|
*/
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flex gap={2} wrap="wrap" pb={2}>
|
||||||
|
{[...images].reverse().map((image) => {
|
||||||
|
const { uuid } = image;
|
||||||
|
const isSelected = currentImageUuid === uuid;
|
||||||
|
return (
|
||||||
|
<HoverableImage key={uuid} image={image} isSelected={isSelected} />
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ImageGallery;
|
@ -7,6 +7,7 @@ import {
|
|||||||
ListItem,
|
ListItem,
|
||||||
Text,
|
Text,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
|
import { memo } from 'react';
|
||||||
import { FaPlus } from 'react-icons/fa';
|
import { FaPlus } from 'react-icons/fa';
|
||||||
import { PARAMETERS } from '../../app/constants';
|
import { PARAMETERS } from '../../app/constants';
|
||||||
import { useAppDispatch } from '../../app/hooks';
|
import { useAppDispatch } from '../../app/hooks';
|
||||||
@ -14,13 +15,34 @@ import SDButton from '../../components/SDButton';
|
|||||||
import { setAllParameters, setParameter } from '../sd/sdSlice';
|
import { setAllParameters, setParameter } from '../sd/sdSlice';
|
||||||
import { SDImage, SDMetadata } from './gallerySlice';
|
import { SDImage, SDMetadata } from './gallerySlice';
|
||||||
|
|
||||||
type Props = {
|
type ImageMetadataViewerProps = {
|
||||||
image: SDImage;
|
image: SDImage;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ImageMetadataViewer = ({ image }: Props) => {
|
// TODO: I don't know if this is needed.
|
||||||
|
const memoEqualityCheck = (
|
||||||
|
prev: ImageMetadataViewerProps,
|
||||||
|
next: ImageMetadataViewerProps
|
||||||
|
) => prev.image.uuid === next.image.uuid;
|
||||||
|
|
||||||
|
// TODO: Show more interesting information in this component.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image metadata viewer overlays currently selected image and provides
|
||||||
|
* access to any of its metadata for use in processing.
|
||||||
|
*/
|
||||||
|
const ImageMetadataViewer = memo(({ image }: ImageMetadataViewerProps) => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build an array representing each item of metadata and a human-readable
|
||||||
|
* label for it e.g. "cfgScale" > "CFG Scale".
|
||||||
|
*
|
||||||
|
* This array is then used to render each item with a button to use that
|
||||||
|
* parameter in the processing settings.
|
||||||
|
*
|
||||||
|
* TODO: All this logic feels sloppy.
|
||||||
|
*/
|
||||||
const keys = Object.keys(PARAMETERS);
|
const keys = Object.keys(PARAMETERS);
|
||||||
|
|
||||||
const metadata: Array<{
|
const metadata: Array<{
|
||||||
@ -39,7 +61,7 @@ const ImageMetadataViewer = ({ image }: Props) => {
|
|||||||
return (
|
return (
|
||||||
<Flex gap={2} direction={'column'} overflowY={'scroll'} width={'100%'}>
|
<Flex gap={2} direction={'column'} overflowY={'scroll'} width={'100%'}>
|
||||||
<SDButton
|
<SDButton
|
||||||
label='Use all parameters'
|
label="Use all parameters"
|
||||||
colorScheme={'gray'}
|
colorScheme={'gray'}
|
||||||
padding={2}
|
padding={2}
|
||||||
isDisabled={metadata.length === 0}
|
isDisabled={metadata.length === 0}
|
||||||
@ -60,7 +82,7 @@ const ImageMetadataViewer = ({ image }: Props) => {
|
|||||||
<ListItem key={i} pb={1}>
|
<ListItem key={i} pb={1}>
|
||||||
<Flex gap={2}>
|
<Flex gap={2}>
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label='Use this parameter'
|
aria-label="Use this parameter"
|
||||||
icon={<FaPlus />}
|
icon={<FaPlus />}
|
||||||
size={'xs'}
|
size={'xs'}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
@ -72,25 +94,17 @@ const ImageMetadataViewer = ({ image }: Props) => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Text fontWeight={'semibold'}>
|
<Text fontWeight={'semibold'}>{label}:</Text>
|
||||||
{label}:
|
|
||||||
</Text>
|
|
||||||
|
|
||||||
{value === undefined ||
|
{value === undefined ||
|
||||||
value === null ||
|
value === null ||
|
||||||
value === '' ||
|
value === '' ||
|
||||||
value === 0 ? (
|
value === 0 ? (
|
||||||
<Text
|
<Text maxHeight={100} fontStyle={'italic'}>
|
||||||
maxHeight={100}
|
|
||||||
fontStyle={'italic'}
|
|
||||||
>
|
|
||||||
None
|
None
|
||||||
</Text>
|
</Text>
|
||||||
) : (
|
) : (
|
||||||
<Text
|
<Text maxHeight={100} overflowY={'scroll'}>
|
||||||
maxHeight={100}
|
|
||||||
overflowY={'scroll'}
|
|
||||||
>
|
|
||||||
{value.toString()}
|
{value.toString()}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
@ -101,24 +115,20 @@ const ImageMetadataViewer = ({ image }: Props) => {
|
|||||||
</List>
|
</List>
|
||||||
<Flex gap={2}>
|
<Flex gap={2}>
|
||||||
<Text fontWeight={'semibold'}>Raw:</Text>
|
<Text fontWeight={'semibold'}>Raw:</Text>
|
||||||
<Text
|
<Text maxHeight={100} overflowY={'scroll'} wordBreak={'break-all'}>
|
||||||
maxHeight={100}
|
|
||||||
overflowY={'scroll'}
|
|
||||||
wordBreak={'break-all'}
|
|
||||||
>
|
|
||||||
{JSON.stringify(image.metadata)}
|
{JSON.stringify(image.metadata)}
|
||||||
</Text>
|
</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<Center width={'100%'} pt={10}>
|
<Center width={'100%'} pt={10}>
|
||||||
<Text fontSize={'lg'} fontWeight='semibold'>
|
<Text fontSize={'lg'} fontWeight="semibold">
|
||||||
No metadata available
|
No metadata available
|
||||||
</Text>
|
</Text>
|
||||||
</Center>
|
</Center>
|
||||||
)}
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
};
|
}, memoEqualityCheck);
|
||||||
|
|
||||||
export default ImageMetadataViewer;
|
export default ImageMetadataViewer;
|
||||||
|
@ -1,150 +0,0 @@
|
|||||||
import {
|
|
||||||
Box,
|
|
||||||
Flex,
|
|
||||||
Icon,
|
|
||||||
IconButton,
|
|
||||||
Image,
|
|
||||||
useColorModeValue,
|
|
||||||
} from '@chakra-ui/react';
|
|
||||||
import { RootState } from '../../app/store';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
|
||||||
import { SDImage, setCurrentImage } from './gallerySlice';
|
|
||||||
import { FaCheck, FaCopy, FaSeedling, FaTrash } from 'react-icons/fa';
|
|
||||||
import DeleteImageModalButton from './DeleteImageModalButton';
|
|
||||||
import { memo, SyntheticEvent, useState } from 'react';
|
|
||||||
import { setAllParameters, setSeed } from '../sd/sdSlice';
|
|
||||||
|
|
||||||
interface HoverableImageProps {
|
|
||||||
image: SDImage;
|
|
||||||
isSelected: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const HoverableImage = memo(
|
|
||||||
(props: HoverableImageProps) => {
|
|
||||||
const [isHovered, setIsHovered] = useState<boolean>(false);
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
|
|
||||||
const checkColor = useColorModeValue('green.600', 'green.300');
|
|
||||||
const bgColor = useColorModeValue('gray.200', 'gray.700');
|
|
||||||
const bgGradient = useColorModeValue(
|
|
||||||
'radial-gradient(circle, rgba(255,255,255,0.7) 0%, rgba(255,255,255,0.7) 20%, rgba(0,0,0,0) 100%)',
|
|
||||||
'radial-gradient(circle, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0.7) 20%, rgba(0,0,0,0) 100%)'
|
|
||||||
);
|
|
||||||
|
|
||||||
const { image, isSelected } = props;
|
|
||||||
const { url, uuid, metadata } = image;
|
|
||||||
|
|
||||||
const handleMouseOver = () => setIsHovered(true);
|
|
||||||
const handleMouseOut = () => setIsHovered(false);
|
|
||||||
const handleClickSetAllParameters = (e: SyntheticEvent) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
dispatch(setAllParameters(metadata));
|
|
||||||
};
|
|
||||||
const handleClickSetSeed = (e: SyntheticEvent) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
dispatch(setSeed(image.metadata.seed!)); // component not rendered unless this exists
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box position={'relative'} key={uuid}>
|
|
||||||
<Image
|
|
||||||
width={120}
|
|
||||||
height={120}
|
|
||||||
objectFit='cover'
|
|
||||||
rounded={'md'}
|
|
||||||
src={url}
|
|
||||||
loading={'lazy'}
|
|
||||||
backgroundColor={bgColor}
|
|
||||||
/>
|
|
||||||
<Flex
|
|
||||||
cursor={'pointer'}
|
|
||||||
position={'absolute'}
|
|
||||||
top={0}
|
|
||||||
left={0}
|
|
||||||
rounded={'md'}
|
|
||||||
width='100%'
|
|
||||||
height='100%'
|
|
||||||
alignItems={'center'}
|
|
||||||
justifyContent={'center'}
|
|
||||||
background={isSelected ? bgGradient : undefined}
|
|
||||||
onClick={() => dispatch(setCurrentImage(image))}
|
|
||||||
onMouseOver={handleMouseOver}
|
|
||||||
onMouseOut={handleMouseOut}
|
|
||||||
>
|
|
||||||
{isSelected && (
|
|
||||||
<Icon
|
|
||||||
fill={checkColor}
|
|
||||||
width={'50%'}
|
|
||||||
height={'50%'}
|
|
||||||
as={FaCheck}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{isHovered && (
|
|
||||||
<Flex
|
|
||||||
direction={'column'}
|
|
||||||
gap={1}
|
|
||||||
position={'absolute'}
|
|
||||||
top={1}
|
|
||||||
right={1}
|
|
||||||
>
|
|
||||||
<DeleteImageModalButton image={image}>
|
|
||||||
<IconButton
|
|
||||||
colorScheme='red'
|
|
||||||
aria-label='Delete image'
|
|
||||||
icon={<FaTrash />}
|
|
||||||
size='xs'
|
|
||||||
fontSize={15}
|
|
||||||
/>
|
|
||||||
</DeleteImageModalButton>
|
|
||||||
<IconButton
|
|
||||||
aria-label='Use all parameters'
|
|
||||||
colorScheme={'blue'}
|
|
||||||
icon={<FaCopy />}
|
|
||||||
size='xs'
|
|
||||||
fontSize={15}
|
|
||||||
onClickCapture={handleClickSetAllParameters}
|
|
||||||
/>
|
|
||||||
{image.metadata.seed && (
|
|
||||||
<IconButton
|
|
||||||
aria-label='Use seed'
|
|
||||||
colorScheme={'blue'}
|
|
||||||
icon={<FaSeedling />}
|
|
||||||
size='xs'
|
|
||||||
fontSize={16}
|
|
||||||
onClickCapture={handleClickSetSeed}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Flex>
|
|
||||||
)}
|
|
||||||
</Flex>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
(prev, next) =>
|
|
||||||
prev.image.uuid === next.image.uuid &&
|
|
||||||
prev.isSelected === next.isSelected
|
|
||||||
);
|
|
||||||
|
|
||||||
const ImageRoll = () => {
|
|
||||||
const { images, currentImageUuid } = useAppSelector(
|
|
||||||
(state: RootState) => state.gallery
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Flex gap={2} wrap='wrap' pb={2}>
|
|
||||||
{[...images].reverse().map((image) => {
|
|
||||||
const { uuid } = image;
|
|
||||||
const isSelected = currentImageUuid === uuid;
|
|
||||||
return (
|
|
||||||
<HoverableImage
|
|
||||||
key={uuid}
|
|
||||||
image={image}
|
|
||||||
isSelected={isSelected}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ImageRoll;
|
|
@ -27,24 +27,36 @@ const systemSelector = createSelector(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Header, includes color mode toggle, settings button, status message.
|
||||||
|
*/
|
||||||
const SiteHeader = () => {
|
const SiteHeader = () => {
|
||||||
const { colorMode, toggleColorMode } = useColorMode();
|
const { colorMode, toggleColorMode } = useColorMode();
|
||||||
const { isConnected } = useAppSelector(systemSelector);
|
const { isConnected } = useAppSelector(systemSelector);
|
||||||
|
|
||||||
|
const statusMessage = isConnected
|
||||||
|
? `Connected to server`
|
||||||
|
: 'No connection to server';
|
||||||
|
|
||||||
|
const statusMessageTextColor = isConnected ? 'green.500' : 'red.500';
|
||||||
|
|
||||||
|
const colorModeIcon = colorMode == 'light' ? <FaMoon /> : <FaSun />;
|
||||||
|
|
||||||
|
// Make FaMoon and FaSun icon apparent size consistent
|
||||||
|
const colorModeIconFontSize = colorMode == 'light' ? 18 : 20;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex minWidth='max-content' alignItems='center' gap='1' pl={2} pr={1}>
|
<Flex minWidth="max-content" alignItems="center" gap="1" pl={2} pr={1}>
|
||||||
<Heading size={'lg'}>Stable Diffusion Dream Server</Heading>
|
<Heading size={'lg'}>Stable Diffusion Dream Server</Heading>
|
||||||
|
|
||||||
<Spacer />
|
<Spacer />
|
||||||
|
|
||||||
<Text textColor={isConnected ? 'green.500' : 'red.500'}>
|
<Text textColor={statusMessageTextColor}>{statusMessage}</Text>
|
||||||
{isConnected ? `Connected to server` : 'No connection to server'}
|
|
||||||
</Text>
|
|
||||||
|
|
||||||
<SettingsModal>
|
<SettingsModal>
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label='Settings'
|
aria-label="Settings"
|
||||||
variant='link'
|
variant="link"
|
||||||
fontSize={24}
|
fontSize={24}
|
||||||
size={'sm'}
|
size={'sm'}
|
||||||
icon={<MdSettings />}
|
icon={<MdSettings />}
|
||||||
@ -52,14 +64,14 @@ const SiteHeader = () => {
|
|||||||
</SettingsModal>
|
</SettingsModal>
|
||||||
|
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label='Link to Github Issues'
|
aria-label="Link to Github Issues"
|
||||||
variant='link'
|
variant="link"
|
||||||
fontSize={23}
|
fontSize={23}
|
||||||
size={'sm'}
|
size={'sm'}
|
||||||
icon={
|
icon={
|
||||||
<Link
|
<Link
|
||||||
isExternal
|
isExternal
|
||||||
href='http://github.com/lstein/stable-diffusion/issues'
|
href="http://github.com/lstein/stable-diffusion/issues"
|
||||||
>
|
>
|
||||||
<MdHelp />
|
<MdHelp />
|
||||||
</Link>
|
</Link>
|
||||||
@ -67,24 +79,24 @@ const SiteHeader = () => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label='Link to Github Repo'
|
aria-label="Link to Github Repo"
|
||||||
variant='link'
|
variant="link"
|
||||||
fontSize={20}
|
fontSize={20}
|
||||||
size={'sm'}
|
size={'sm'}
|
||||||
icon={
|
icon={
|
||||||
<Link isExternal href='http://github.com/lstein/stable-diffusion'>
|
<Link isExternal href="http://github.com/lstein/stable-diffusion">
|
||||||
<FaGithub />
|
<FaGithub />
|
||||||
</Link>
|
</Link>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label='Toggle Dark Mode'
|
aria-label="Toggle Dark Mode"
|
||||||
onClick={toggleColorMode}
|
onClick={toggleColorMode}
|
||||||
variant='link'
|
variant="link"
|
||||||
size={'sm'}
|
size={'sm'}
|
||||||
fontSize={colorMode == 'light' ? 18 : 20}
|
fontSize={colorModeIconFontSize}
|
||||||
icon={colorMode == 'light' ? <FaMoon /> : <FaSun />}
|
icon={colorModeIcon}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
|
@ -17,6 +17,7 @@ import { UPSCALING_LEVELS } from '../../app/constants';
|
|||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
import { isEqual } from 'lodash';
|
import { isEqual } from 'lodash';
|
||||||
import { SystemState } from '../system/systemSlice';
|
import { SystemState } from '../system/systemSlice';
|
||||||
|
import { ChangeEvent } from 'react';
|
||||||
|
|
||||||
const sdSelector = createSelector(
|
const sdSelector = createSelector(
|
||||||
(state: RootState) => state.sd,
|
(state: RootState) => state.sd,
|
||||||
@ -46,35 +47,37 @@ const systemSelector = createSelector(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const ESRGANOptions = () => {
|
|
||||||
const { upscalingLevel, upscalingStrength } = useAppSelector(sdSelector);
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays upscaling/ESRGAN options (level and strength).
|
||||||
|
*/
|
||||||
|
const ESRGANOptions = () => {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { upscalingLevel, upscalingStrength } = useAppSelector(sdSelector);
|
||||||
const { isESRGANAvailable } = useAppSelector(systemSelector);
|
const { isESRGANAvailable } = useAppSelector(systemSelector);
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const handleChangeLevel = (e: ChangeEvent<HTMLSelectElement>) =>
|
||||||
|
dispatch(setUpscalingLevel(Number(e.target.value) as UpscalingLevel));
|
||||||
|
|
||||||
|
const handleChangeStrength = (v: string | number) =>
|
||||||
|
dispatch(setUpscalingStrength(Number(v)));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex direction={'column'} gap={2}>
|
<Flex direction={'column'} gap={2}>
|
||||||
<SDSelect
|
<SDSelect
|
||||||
isDisabled={!isESRGANAvailable}
|
isDisabled={!isESRGANAvailable}
|
||||||
label='Scale'
|
label="Scale"
|
||||||
value={upscalingLevel}
|
value={upscalingLevel}
|
||||||
onChange={(e) =>
|
onChange={handleChangeLevel}
|
||||||
dispatch(
|
|
||||||
setUpscalingLevel(
|
|
||||||
Number(e.target.value) as UpscalingLevel
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
validValues={UPSCALING_LEVELS}
|
validValues={UPSCALING_LEVELS}
|
||||||
/>
|
/>
|
||||||
<SDNumberInput
|
<SDNumberInput
|
||||||
isDisabled={!isESRGANAvailable}
|
isDisabled={!isESRGANAvailable}
|
||||||
label='Strength'
|
label="Strength"
|
||||||
step={0.05}
|
step={0.05}
|
||||||
min={0}
|
min={0}
|
||||||
max={1}
|
max={1}
|
||||||
onChange={(v) => dispatch(setUpscalingStrength(Number(v)))}
|
onChange={handleChangeStrength}
|
||||||
value={upscalingStrength}
|
value={upscalingStrength}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
@ -38,22 +38,27 @@ const systemSelector = createSelector(
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const GFPGANOptions = () => {
|
|
||||||
const { gfpganStrength } = useAppSelector(sdSelector);
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays face-fixing/GFPGAN options (strength).
|
||||||
|
*/
|
||||||
|
const GFPGANOptions = () => {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { gfpganStrength } = useAppSelector(sdSelector);
|
||||||
const { isGFPGANAvailable } = useAppSelector(systemSelector);
|
const { isGFPGANAvailable } = useAppSelector(systemSelector);
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const handleChangeStrength = (v: string | number) =>
|
||||||
|
dispatch(setGfpganStrength(Number(v)));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex direction={'column'} gap={2}>
|
<Flex direction={'column'} gap={2}>
|
||||||
<SDNumberInput
|
<SDNumberInput
|
||||||
isDisabled={!isGFPGANAvailable}
|
isDisabled={!isGFPGANAvailable}
|
||||||
label='Strength'
|
label="Strength"
|
||||||
step={0.05}
|
step={0.05}
|
||||||
min={0}
|
min={0}
|
||||||
max={1}
|
max={1}
|
||||||
onChange={(v) => dispatch(setGfpganStrength(Number(v)))}
|
onChange={handleChangeStrength}
|
||||||
value={gfpganStrength}
|
value={gfpganStrength}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { Flex } from '@chakra-ui/react';
|
import { Flex } from '@chakra-ui/react';
|
||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
|
import { ChangeEvent } from 'react';
|
||||||
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
||||||
import { RootState } from '../../app/store';
|
import { RootState } from '../../app/store';
|
||||||
import SDNumberInput from '../../components/SDNumberInput';
|
import SDNumberInput from '../../components/SDNumberInput';
|
||||||
import SDSwitch from '../../components/SDSwitch';
|
import SDSwitch from '../../components/SDSwitch';
|
||||||
import InitImage from './InitImage';
|
import InitAndMaskImage from './InitAndMaskImage';
|
||||||
import {
|
import {
|
||||||
SDState,
|
SDState,
|
||||||
setImg2imgStrength,
|
setImg2imgStrength,
|
||||||
@ -15,38 +16,42 @@ const sdSelector = createSelector(
|
|||||||
(state: RootState) => state.sd,
|
(state: RootState) => state.sd,
|
||||||
(sd: SDState) => {
|
(sd: SDState) => {
|
||||||
return {
|
return {
|
||||||
initialImagePath: sd.initialImagePath,
|
|
||||||
img2imgStrength: sd.img2imgStrength,
|
img2imgStrength: sd.img2imgStrength,
|
||||||
shouldFitToWidthHeight: sd.shouldFitToWidthHeight,
|
shouldFitToWidthHeight: sd.shouldFitToWidthHeight,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for img2img generation (strength, fit, init/mask upload).
|
||||||
|
*/
|
||||||
const ImageToImageOptions = () => {
|
const ImageToImageOptions = () => {
|
||||||
const { initialImagePath, img2imgStrength, shouldFitToWidthHeight } =
|
const dispatch = useAppDispatch();
|
||||||
|
const { img2imgStrength, shouldFitToWidthHeight } =
|
||||||
useAppSelector(sdSelector);
|
useAppSelector(sdSelector);
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const handleChangeStrength = (v: string | number) =>
|
||||||
|
dispatch(setImg2imgStrength(Number(v)));
|
||||||
|
|
||||||
|
const handleChangeFit = (e: ChangeEvent<HTMLInputElement>) =>
|
||||||
|
dispatch(setShouldFitToWidthHeight(e.target.checked));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex direction={'column'} gap={2}>
|
<Flex direction={'column'} gap={2}>
|
||||||
<SDNumberInput
|
<SDNumberInput
|
||||||
isDisabled={!initialImagePath}
|
label="Strength"
|
||||||
label='Strength'
|
|
||||||
step={0.01}
|
step={0.01}
|
||||||
min={0}
|
min={0}
|
||||||
max={1}
|
max={1}
|
||||||
onChange={(v) => dispatch(setImg2imgStrength(Number(v)))}
|
onChange={handleChangeStrength}
|
||||||
value={img2imgStrength}
|
value={img2imgStrength}
|
||||||
/>
|
/>
|
||||||
<SDSwitch
|
<SDSwitch
|
||||||
isDisabled={!initialImagePath}
|
label="Fit initial image to output size"
|
||||||
label='Fit initial image to output size'
|
|
||||||
isChecked={shouldFitToWidthHeight}
|
isChecked={shouldFitToWidthHeight}
|
||||||
onChange={(e) =>
|
onChange={handleChangeFit}
|
||||||
dispatch(setShouldFitToWidthHeight(e.target.checked))
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<InitImage />
|
<InitAndMaskImage />
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
63
frontend/src/features/sd/ImageUploader.tsx
Normal file
63
frontend/src/features/sd/ImageUploader.tsx
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import { cloneElement, ReactElement, SyntheticEvent, useCallback } from 'react';
|
||||||
|
import { FileRejection, useDropzone } from 'react-dropzone';
|
||||||
|
|
||||||
|
type ImageUploaderProps = {
|
||||||
|
/**
|
||||||
|
* Component which, on click, should open the upload interface.
|
||||||
|
*/
|
||||||
|
children: ReactElement;
|
||||||
|
/**
|
||||||
|
* Callback to handle uploading the selected file.
|
||||||
|
*/
|
||||||
|
fileAcceptedCallback: (file: File) => void;
|
||||||
|
/**
|
||||||
|
* Callback to handle a file being rejected.
|
||||||
|
*/
|
||||||
|
fileRejectionCallback: (rejection: FileRejection) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File upload using react-dropzone.
|
||||||
|
* Needs a child to be the button to activate the upload interface.
|
||||||
|
*/
|
||||||
|
const ImageUploader = ({
|
||||||
|
children,
|
||||||
|
fileAcceptedCallback,
|
||||||
|
fileRejectionCallback,
|
||||||
|
}: ImageUploaderProps) => {
|
||||||
|
const onDrop = useCallback(
|
||||||
|
(acceptedFiles: Array<File>, fileRejections: Array<FileRejection>) => {
|
||||||
|
fileRejections.forEach((rejection: FileRejection) => {
|
||||||
|
fileRejectionCallback(rejection);
|
||||||
|
});
|
||||||
|
|
||||||
|
acceptedFiles.forEach((file: File) => {
|
||||||
|
fileAcceptedCallback(file);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[fileAcceptedCallback, fileRejectionCallback]
|
||||||
|
);
|
||||||
|
|
||||||
|
const { getRootProps, getInputProps, open } = useDropzone({
|
||||||
|
onDrop,
|
||||||
|
accept: {
|
||||||
|
'image/jpeg': ['.jpg', '.jpeg', '.png'],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleClickUploadIcon = (e: SyntheticEvent) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
open();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div {...getRootProps()}>
|
||||||
|
<input {...getInputProps({ multiple: false })} />
|
||||||
|
{cloneElement(children, {
|
||||||
|
onClick: handleClickUploadIcon,
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ImageUploader;
|
57
frontend/src/features/sd/InitAndMaskImage.tsx
Normal file
57
frontend/src/features/sd/InitAndMaskImage.tsx
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import { Flex, Image } from '@chakra-ui/react';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useAppSelector } from '../../app/hooks';
|
||||||
|
import { RootState } from '../../app/store';
|
||||||
|
import { SDState } from '../../features/sd/sdSlice';
|
||||||
|
import './InitAndMaskImage.css';
|
||||||
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
|
import { isEqual } from 'lodash';
|
||||||
|
import InitAndMaskUploadButtons from './InitAndMaskUploadButtons';
|
||||||
|
|
||||||
|
const sdSelector = createSelector(
|
||||||
|
(state: RootState) => state.sd,
|
||||||
|
(sd: SDState) => {
|
||||||
|
return {
|
||||||
|
initialImagePath: sd.initialImagePath,
|
||||||
|
maskPath: sd.maskPath,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{ memoizeOptions: { resultEqualityCheck: isEqual } }
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays init and mask images and buttons to upload/delete them.
|
||||||
|
*/
|
||||||
|
const InitAndMaskImage = () => {
|
||||||
|
const { initialImagePath, maskPath } = useAppSelector(sdSelector);
|
||||||
|
const [shouldShowMask, setShouldShowMask] = useState<boolean>(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flex direction={'column'} alignItems={'center'} gap={2}>
|
||||||
|
<InitAndMaskUploadButtons setShouldShowMask={setShouldShowMask} />
|
||||||
|
{initialImagePath && (
|
||||||
|
<Flex position={'relative'} width={'100%'}>
|
||||||
|
<Image
|
||||||
|
fit={'contain'}
|
||||||
|
src={initialImagePath}
|
||||||
|
rounded={'md'}
|
||||||
|
className={'checkerboard'}
|
||||||
|
/>
|
||||||
|
{shouldShowMask && maskPath && (
|
||||||
|
<Image
|
||||||
|
position={'absolute'}
|
||||||
|
top={0}
|
||||||
|
left={0}
|
||||||
|
fit={'contain'}
|
||||||
|
src={maskPath}
|
||||||
|
rounded={'md'}
|
||||||
|
zIndex={1}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Flex>
|
||||||
|
)}
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InitAndMaskImage;
|
131
frontend/src/features/sd/InitAndMaskUploadButtons.tsx
Normal file
131
frontend/src/features/sd/InitAndMaskUploadButtons.tsx
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
import { Button, Flex, IconButton, useToast } from '@chakra-ui/react';
|
||||||
|
import { SyntheticEvent, useCallback } from 'react';
|
||||||
|
import { FaTrash } from 'react-icons/fa';
|
||||||
|
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
||||||
|
import { RootState } from '../../app/store';
|
||||||
|
import {
|
||||||
|
SDState,
|
||||||
|
setInitialImagePath,
|
||||||
|
setMaskPath,
|
||||||
|
} from '../../features/sd/sdSlice';
|
||||||
|
import { uploadInitialImage, uploadMaskImage } from '../../app/socketio';
|
||||||
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
|
import { isEqual } from 'lodash';
|
||||||
|
import ImageUploader from './ImageUploader';
|
||||||
|
import { FileRejection } from 'react-dropzone';
|
||||||
|
|
||||||
|
const sdSelector = createSelector(
|
||||||
|
(state: RootState) => state.sd,
|
||||||
|
(sd: SDState) => {
|
||||||
|
return {
|
||||||
|
initialImagePath: sd.initialImagePath,
|
||||||
|
maskPath: sd.maskPath,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
{ memoizeOptions: { resultEqualityCheck: isEqual } }
|
||||||
|
);
|
||||||
|
|
||||||
|
type InitAndMaskUploadButtonsProps = {
|
||||||
|
setShouldShowMask: (b: boolean) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Init and mask image upload buttons.
|
||||||
|
*/
|
||||||
|
const InitAndMaskUploadButtons = ({
|
||||||
|
setShouldShowMask,
|
||||||
|
}: InitAndMaskUploadButtonsProps) => {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { initialImagePath } = useAppSelector(sdSelector);
|
||||||
|
|
||||||
|
// Use a toast to alert user when a file upload is rejected
|
||||||
|
const toast = useToast();
|
||||||
|
|
||||||
|
// Clear the init and mask images
|
||||||
|
const handleClickResetInitialImageAndMask = (e: SyntheticEvent) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
dispatch(setInitialImagePath(''));
|
||||||
|
dispatch(setMaskPath(''));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle hover to view initial image and mask image
|
||||||
|
const handleMouseOverInitialImageUploadButton = () =>
|
||||||
|
setShouldShowMask(false);
|
||||||
|
const handleMouseOutInitialImageUploadButton = () => setShouldShowMask(true);
|
||||||
|
|
||||||
|
const handleMouseOverMaskUploadButton = () => setShouldShowMask(true);
|
||||||
|
const handleMouseOutMaskUploadButton = () => setShouldShowMask(true);
|
||||||
|
|
||||||
|
// Callbacks to for handling file upload attempts
|
||||||
|
const initImageFileAcceptedCallback = useCallback(
|
||||||
|
(file: File) => dispatch(uploadInitialImage(file)),
|
||||||
|
[dispatch]
|
||||||
|
);
|
||||||
|
|
||||||
|
const maskImageFileAcceptedCallback = useCallback(
|
||||||
|
(file: File) => dispatch(uploadMaskImage(file)),
|
||||||
|
[dispatch]
|
||||||
|
);
|
||||||
|
|
||||||
|
const fileRejectionCallback = useCallback(
|
||||||
|
(rejection: FileRejection) => {
|
||||||
|
const msg = rejection.errors.reduce(
|
||||||
|
(acc: string, cur: { message: string }) => acc + '\n' + cur.message,
|
||||||
|
''
|
||||||
|
);
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: 'Upload failed',
|
||||||
|
description: msg,
|
||||||
|
status: 'error',
|
||||||
|
isClosable: true,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[toast]
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flex gap={2} justifyContent={'space-between'} width={'100%'}>
|
||||||
|
<ImageUploader
|
||||||
|
fileAcceptedCallback={initImageFileAcceptedCallback}
|
||||||
|
fileRejectionCallback={fileRejectionCallback}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
size={'sm'}
|
||||||
|
fontSize={'md'}
|
||||||
|
fontWeight={'normal'}
|
||||||
|
onMouseOver={handleMouseOverInitialImageUploadButton}
|
||||||
|
onMouseOut={handleMouseOutInitialImageUploadButton}
|
||||||
|
>
|
||||||
|
Upload Image
|
||||||
|
</Button>
|
||||||
|
</ImageUploader>
|
||||||
|
|
||||||
|
<ImageUploader
|
||||||
|
fileAcceptedCallback={maskImageFileAcceptedCallback}
|
||||||
|
fileRejectionCallback={fileRejectionCallback}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
isDisabled={!initialImagePath}
|
||||||
|
size={'sm'}
|
||||||
|
fontSize={'md'}
|
||||||
|
fontWeight={'normal'}
|
||||||
|
onMouseOver={handleMouseOverMaskUploadButton}
|
||||||
|
onMouseOut={handleMouseOutMaskUploadButton}
|
||||||
|
>
|
||||||
|
Upload Mask
|
||||||
|
</Button>
|
||||||
|
</ImageUploader>
|
||||||
|
|
||||||
|
<IconButton
|
||||||
|
isDisabled={!initialImagePath}
|
||||||
|
size={'sm'}
|
||||||
|
aria-label={'Reset initial image and mask'}
|
||||||
|
onClick={handleClickResetInitialImageAndMask}
|
||||||
|
icon={<FaTrash />}
|
||||||
|
/>
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InitAndMaskUploadButtons;
|
@ -1,155 +0,0 @@
|
|||||||
import {
|
|
||||||
Button,
|
|
||||||
Flex,
|
|
||||||
IconButton,
|
|
||||||
Image,
|
|
||||||
useToast,
|
|
||||||
} from '@chakra-ui/react';
|
|
||||||
import { SyntheticEvent, useCallback, useState } from 'react';
|
|
||||||
import { FileRejection, useDropzone } from 'react-dropzone';
|
|
||||||
import { FaTrash } from 'react-icons/fa';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
|
||||||
import { RootState } from '../../app/store';
|
|
||||||
import {
|
|
||||||
SDState,
|
|
||||||
setInitialImagePath,
|
|
||||||
setMaskPath,
|
|
||||||
} from '../../features/sd/sdSlice';
|
|
||||||
import MaskUploader from './MaskUploader';
|
|
||||||
import './InitImage.css';
|
|
||||||
import { uploadInitialImage } from '../../app/socketio';
|
|
||||||
import { createSelector } from '@reduxjs/toolkit';
|
|
||||||
import { isEqual } from 'lodash';
|
|
||||||
|
|
||||||
const sdSelector = createSelector(
|
|
||||||
(state: RootState) => state.sd,
|
|
||||||
(sd: SDState) => {
|
|
||||||
return {
|
|
||||||
initialImagePath: sd.initialImagePath,
|
|
||||||
maskPath: sd.maskPath,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
{ memoizeOptions: { resultEqualityCheck: isEqual } }
|
|
||||||
);
|
|
||||||
|
|
||||||
const InitImage = () => {
|
|
||||||
const toast = useToast();
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
const { initialImagePath, maskPath } = useAppSelector(sdSelector);
|
|
||||||
|
|
||||||
const onDrop = useCallback(
|
|
||||||
(acceptedFiles: Array<File>, fileRejections: Array<FileRejection>) => {
|
|
||||||
fileRejections.forEach((rejection: FileRejection) => {
|
|
||||||
const msg = rejection.errors.reduce(
|
|
||||||
(acc: string, cur: { message: string }) => acc + '\n' + cur.message,
|
|
||||||
''
|
|
||||||
);
|
|
||||||
|
|
||||||
toast({
|
|
||||||
title: 'Upload failed',
|
|
||||||
description: msg,
|
|
||||||
status: 'error',
|
|
||||||
isClosable: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
acceptedFiles.forEach((file: File) => {
|
|
||||||
dispatch(uploadInitialImage(file));
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[dispatch, toast]
|
|
||||||
);
|
|
||||||
|
|
||||||
const { getRootProps, getInputProps, open } = useDropzone({
|
|
||||||
onDrop,
|
|
||||||
accept: {
|
|
||||||
'image/jpeg': ['.jpg', '.jpeg', '.png'],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const [shouldShowMask, setShouldShowMask] = useState<boolean>(false);
|
|
||||||
const handleClickUploadIcon = (e: SyntheticEvent) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
open();
|
|
||||||
};
|
|
||||||
const handleClickResetInitialImageAndMask = (e: SyntheticEvent) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
dispatch(setInitialImagePath(''));
|
|
||||||
dispatch(setMaskPath(''));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleMouseOverInitialImageUploadButton = () =>
|
|
||||||
setShouldShowMask(false);
|
|
||||||
const handleMouseOutInitialImageUploadButton = () => setShouldShowMask(true);
|
|
||||||
|
|
||||||
const handleMouseOverMaskUploadButton = () => setShouldShowMask(true);
|
|
||||||
const handleMouseOutMaskUploadButton = () => setShouldShowMask(true);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Flex
|
|
||||||
{...getRootProps({
|
|
||||||
onClick: initialImagePath ? (e) => e.stopPropagation() : undefined,
|
|
||||||
})}
|
|
||||||
direction={'column'}
|
|
||||||
alignItems={'center'}
|
|
||||||
gap={2}
|
|
||||||
>
|
|
||||||
<input {...getInputProps({ multiple: false })} />
|
|
||||||
<Flex gap={2} justifyContent={'space-between'} width={'100%'}>
|
|
||||||
<Button
|
|
||||||
size={'sm'}
|
|
||||||
fontSize={'md'}
|
|
||||||
fontWeight={'normal'}
|
|
||||||
onClick={handleClickUploadIcon}
|
|
||||||
onMouseOver={handleMouseOverInitialImageUploadButton}
|
|
||||||
onMouseOut={handleMouseOutInitialImageUploadButton}
|
|
||||||
>
|
|
||||||
Upload Image
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<MaskUploader>
|
|
||||||
<Button
|
|
||||||
size={'sm'}
|
|
||||||
fontSize={'md'}
|
|
||||||
fontWeight={'normal'}
|
|
||||||
onClick={handleClickUploadIcon}
|
|
||||||
onMouseOver={handleMouseOverMaskUploadButton}
|
|
||||||
onMouseOut={handleMouseOutMaskUploadButton}
|
|
||||||
>
|
|
||||||
Upload Mask
|
|
||||||
</Button>
|
|
||||||
</MaskUploader>
|
|
||||||
<IconButton
|
|
||||||
size={'sm'}
|
|
||||||
aria-label={'Reset initial image and mask'}
|
|
||||||
onClick={handleClickResetInitialImageAndMask}
|
|
||||||
icon={<FaTrash />}
|
|
||||||
/>
|
|
||||||
</Flex>
|
|
||||||
{initialImagePath && (
|
|
||||||
<Flex position={'relative'} width={'100%'}>
|
|
||||||
<Image
|
|
||||||
fit={'contain'}
|
|
||||||
src={initialImagePath}
|
|
||||||
rounded={'md'}
|
|
||||||
className={'checkerboard'}
|
|
||||||
/>
|
|
||||||
{shouldShowMask && maskPath && (
|
|
||||||
<Image
|
|
||||||
position={'absolute'}
|
|
||||||
top={0}
|
|
||||||
left={0}
|
|
||||||
fit={'contain'}
|
|
||||||
src={maskPath}
|
|
||||||
rounded={'md'}
|
|
||||||
zIndex={1}
|
|
||||||
className={'checkerboard'}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Flex>
|
|
||||||
)}
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default InitImage;
|
|
@ -1,61 +0,0 @@
|
|||||||
import { useToast } from '@chakra-ui/react';
|
|
||||||
import { cloneElement, ReactElement, SyntheticEvent, useCallback } from 'react';
|
|
||||||
import { FileRejection, useDropzone } from 'react-dropzone';
|
|
||||||
import { useAppDispatch } from '../../app/hooks';
|
|
||||||
import { uploadMaskImage } from '../../app/socketio';
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
children: ReactElement;
|
|
||||||
};
|
|
||||||
|
|
||||||
const MaskUploader = ({ children }: Props) => {
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
const toast = useToast();
|
|
||||||
|
|
||||||
const onDrop = useCallback(
|
|
||||||
(acceptedFiles: Array<File>, fileRejections: Array<FileRejection>) => {
|
|
||||||
fileRejections.forEach((rejection: FileRejection) => {
|
|
||||||
const msg = rejection.errors.reduce(
|
|
||||||
(acc: string, cur: { message: string }) =>
|
|
||||||
acc + '\n' + cur.message,
|
|
||||||
''
|
|
||||||
);
|
|
||||||
|
|
||||||
toast({
|
|
||||||
title: 'Upload failed',
|
|
||||||
description: msg,
|
|
||||||
status: 'error',
|
|
||||||
isClosable: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
acceptedFiles.forEach((file: File) => {
|
|
||||||
dispatch(uploadMaskImage(file));
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[dispatch, toast]
|
|
||||||
);
|
|
||||||
|
|
||||||
const { getRootProps, getInputProps, open } = useDropzone({
|
|
||||||
onDrop,
|
|
||||||
accept: {
|
|
||||||
'image/jpeg': ['.jpg', '.jpeg', '.png'],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const handleClickUploadIcon = (e: SyntheticEvent) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
open();
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div {...getRootProps()}>
|
|
||||||
<input {...getInputProps({ multiple: false })} />
|
|
||||||
{cloneElement(children, {
|
|
||||||
onClick: handleClickUploadIcon,
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MaskUploader;
|
|
@ -8,6 +8,7 @@ import {
|
|||||||
AccordionIcon,
|
AccordionIcon,
|
||||||
AccordionPanel,
|
AccordionPanel,
|
||||||
Switch,
|
Switch,
|
||||||
|
ExpandedIndex,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
|
|
||||||
import { RootState } from '../../app/store';
|
import { RootState } from '../../app/store';
|
||||||
@ -28,6 +29,7 @@ import ESRGANOptions from './ESRGANOptions';
|
|||||||
import GFPGANOptions from './GFPGANOptions';
|
import GFPGANOptions from './GFPGANOptions';
|
||||||
import OutputOptions from './OutputOptions';
|
import OutputOptions from './OutputOptions';
|
||||||
import ImageToImageOptions from './ImageToImageOptions';
|
import ImageToImageOptions from './ImageToImageOptions';
|
||||||
|
import { ChangeEvent } from 'react';
|
||||||
|
|
||||||
const sdSelector = createSelector(
|
const sdSelector = createSelector(
|
||||||
(state: RootState) => state.sd,
|
(state: RootState) => state.sd,
|
||||||
@ -62,6 +64,9 @@ const systemSelector = createSelector(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main container for generation and processing parameters.
|
||||||
|
*/
|
||||||
const OptionsAccordion = () => {
|
const OptionsAccordion = () => {
|
||||||
const {
|
const {
|
||||||
shouldRunESRGAN,
|
shouldRunESRGAN,
|
||||||
@ -75,19 +80,32 @@ const OptionsAccordion = () => {
|
|||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores accordion state in redux so preferred UI setup is retained.
|
||||||
|
*/
|
||||||
|
const handleChangeAccordionState = (openAccordions: ExpandedIndex) =>
|
||||||
|
dispatch(setOpenAccordions(openAccordions));
|
||||||
|
|
||||||
|
const handleChangeShouldRunESRGAN = (e: ChangeEvent<HTMLInputElement>) =>
|
||||||
|
dispatch(setShouldRunESRGAN(e.target.checked));
|
||||||
|
|
||||||
|
const handleChangeShouldRunGFPGAN = (e: ChangeEvent<HTMLInputElement>) =>
|
||||||
|
dispatch(setShouldRunGFPGAN(e.target.checked));
|
||||||
|
|
||||||
|
const handleChangeShouldUseInitImage = (e: ChangeEvent<HTMLInputElement>) =>
|
||||||
|
dispatch(setShouldUseInitImage(e.target.checked));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Accordion
|
<Accordion
|
||||||
defaultIndex={openAccordions}
|
defaultIndex={openAccordions}
|
||||||
allowMultiple
|
allowMultiple
|
||||||
reduceMotion
|
reduceMotion
|
||||||
onChange={(openAccordions) =>
|
onChange={handleChangeAccordionState}
|
||||||
dispatch(setOpenAccordions(openAccordions))
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<AccordionItem>
|
<AccordionItem>
|
||||||
<h2>
|
<h2>
|
||||||
<AccordionButton>
|
<AccordionButton>
|
||||||
<Box flex='1' textAlign='left'>
|
<Box flex="1" textAlign="left">
|
||||||
Seed & Variation
|
Seed & Variation
|
||||||
</Box>
|
</Box>
|
||||||
<AccordionIcon />
|
<AccordionIcon />
|
||||||
@ -100,7 +118,7 @@ const OptionsAccordion = () => {
|
|||||||
<AccordionItem>
|
<AccordionItem>
|
||||||
<h2>
|
<h2>
|
||||||
<AccordionButton>
|
<AccordionButton>
|
||||||
<Box flex='1' textAlign='left'>
|
<Box flex="1" textAlign="left">
|
||||||
Sampler
|
Sampler
|
||||||
</Box>
|
</Box>
|
||||||
<AccordionIcon />
|
<AccordionIcon />
|
||||||
@ -123,11 +141,7 @@ const OptionsAccordion = () => {
|
|||||||
<Switch
|
<Switch
|
||||||
isDisabled={!isESRGANAvailable}
|
isDisabled={!isESRGANAvailable}
|
||||||
isChecked={shouldRunESRGAN}
|
isChecked={shouldRunESRGAN}
|
||||||
onChange={(e) =>
|
onChange={handleChangeShouldRunESRGAN}
|
||||||
dispatch(
|
|
||||||
setShouldRunESRGAN(e.target.checked)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
<AccordionIcon />
|
<AccordionIcon />
|
||||||
@ -150,11 +164,7 @@ const OptionsAccordion = () => {
|
|||||||
<Switch
|
<Switch
|
||||||
isDisabled={!isGFPGANAvailable}
|
isDisabled={!isGFPGANAvailable}
|
||||||
isChecked={shouldRunGFPGAN}
|
isChecked={shouldRunGFPGAN}
|
||||||
onChange={(e) =>
|
onChange={handleChangeShouldRunGFPGAN}
|
||||||
dispatch(
|
|
||||||
setShouldRunGFPGAN(e.target.checked)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
<AccordionIcon />
|
<AccordionIcon />
|
||||||
@ -177,11 +187,7 @@ const OptionsAccordion = () => {
|
|||||||
<Switch
|
<Switch
|
||||||
isDisabled={!initialImagePath}
|
isDisabled={!initialImagePath}
|
||||||
isChecked={shouldUseInitImage}
|
isChecked={shouldUseInitImage}
|
||||||
onChange={(e) =>
|
onChange={handleChangeShouldUseInitImage}
|
||||||
dispatch(
|
|
||||||
setShouldUseInitImage(e.target.checked)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
<AccordionIcon />
|
<AccordionIcon />
|
||||||
@ -194,7 +200,7 @@ const OptionsAccordion = () => {
|
|||||||
<AccordionItem>
|
<AccordionItem>
|
||||||
<h2>
|
<h2>
|
||||||
<AccordionButton>
|
<AccordionButton>
|
||||||
<Box flex='1' textAlign='left'>
|
<Box flex="1" textAlign="left">
|
||||||
Output
|
Output
|
||||||
</Box>
|
</Box>
|
||||||
<AccordionIcon />
|
<AccordionIcon />
|
||||||
|
@ -11,6 +11,7 @@ import { HEIGHTS, WIDTHS } from '../../app/constants';
|
|||||||
import SDSwitch from '../../components/SDSwitch';
|
import SDSwitch from '../../components/SDSwitch';
|
||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
import { isEqual } from 'lodash';
|
import { isEqual } from 'lodash';
|
||||||
|
import { ChangeEvent } from 'react';
|
||||||
|
|
||||||
const sdSelector = createSelector(
|
const sdSelector = createSelector(
|
||||||
(state: RootState) => state.sd,
|
(state: RootState) => state.sd,
|
||||||
@ -28,36 +29,45 @@ const sdSelector = createSelector(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image output options. Includes width, height, seamless tiling.
|
||||||
|
*/
|
||||||
const OutputOptions = () => {
|
const OutputOptions = () => {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
const { height, width, seamless } = useAppSelector(sdSelector);
|
const { height, width, seamless } = useAppSelector(sdSelector);
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const handleChangeWidth = (e: ChangeEvent<HTMLSelectElement>) =>
|
||||||
|
dispatch(setWidth(Number(e.target.value)));
|
||||||
|
|
||||||
|
const handleChangeHeight = (e: ChangeEvent<HTMLSelectElement>) =>
|
||||||
|
dispatch(setHeight(Number(e.target.value)));
|
||||||
|
|
||||||
|
const handleChangeSeamless = (e: ChangeEvent<HTMLInputElement>) =>
|
||||||
|
dispatch(setSeamless(e.target.checked));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex gap={2} direction={'column'}>
|
<Flex gap={2} direction={'column'}>
|
||||||
<Flex gap={2}>
|
<Flex gap={2}>
|
||||||
<SDSelect
|
<SDSelect
|
||||||
label='Width'
|
label="Width"
|
||||||
value={width}
|
value={width}
|
||||||
flexGrow={1}
|
flexGrow={1}
|
||||||
onChange={(e) => dispatch(setWidth(Number(e.target.value)))}
|
onChange={handleChangeWidth}
|
||||||
validValues={WIDTHS}
|
validValues={WIDTHS}
|
||||||
/>
|
/>
|
||||||
<SDSelect
|
<SDSelect
|
||||||
label='Height'
|
label="Height"
|
||||||
value={height}
|
value={height}
|
||||||
flexGrow={1}
|
flexGrow={1}
|
||||||
onChange={(e) =>
|
onChange={handleChangeHeight}
|
||||||
dispatch(setHeight(Number(e.target.value)))
|
|
||||||
}
|
|
||||||
validValues={HEIGHTS}
|
validValues={HEIGHTS}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
<SDSwitch
|
<SDSwitch
|
||||||
label='Seamless tiling'
|
label="Seamless tiling"
|
||||||
fontSize={'md'}
|
fontSize={'md'}
|
||||||
isChecked={seamless}
|
isChecked={seamless}
|
||||||
onChange={(e) => dispatch(setSeamless(e.target.checked))}
|
onChange={handleChangeSeamless}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
|
@ -23,33 +23,43 @@ const systemSelector = createSelector(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Buttons to start and cancel image generation.
|
||||||
|
*/
|
||||||
const ProcessButtons = () => {
|
const ProcessButtons = () => {
|
||||||
const { isProcessing, isConnected } = useAppSelector(systemSelector);
|
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
const { isProcessing, isConnected } = useAppSelector(systemSelector);
|
||||||
const isReady = useCheckParameters();
|
const isReady = useCheckParameters();
|
||||||
|
|
||||||
|
const handleClickGenerate = () => dispatch(generateImage());
|
||||||
|
|
||||||
|
const handleClickCancel = () => dispatch(cancelProcessing());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex gap={2} direction={'column'} alignItems={'space-between'} height={'100%'}>
|
<Flex
|
||||||
|
gap={2}
|
||||||
|
direction={'column'}
|
||||||
|
alignItems={'space-between'}
|
||||||
|
height={'100%'}
|
||||||
|
>
|
||||||
<SDButton
|
<SDButton
|
||||||
label='Generate'
|
label="Generate"
|
||||||
type='submit'
|
type="submit"
|
||||||
colorScheme='green'
|
colorScheme="green"
|
||||||
flexGrow={1}
|
flexGrow={1}
|
||||||
isDisabled={!isReady}
|
isDisabled={!isReady}
|
||||||
fontSize={'md'}
|
fontSize={'md'}
|
||||||
size={'md'}
|
size={'md'}
|
||||||
onClick={() => dispatch(generateImage())}
|
onClick={handleClickGenerate}
|
||||||
/>
|
/>
|
||||||
<SDButton
|
<SDButton
|
||||||
label='Cancel'
|
label="Cancel"
|
||||||
colorScheme='red'
|
colorScheme="red"
|
||||||
flexGrow={1}
|
flexGrow={1}
|
||||||
fontSize={'md'}
|
fontSize={'md'}
|
||||||
size={'md'}
|
size={'md'}
|
||||||
isDisabled={!isConnected || !isProcessing}
|
isDisabled={!isConnected || !isProcessing}
|
||||||
onClick={() => dispatch(cancelProcessing())}
|
onClick={handleClickCancel}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
|
@ -1,21 +1,28 @@
|
|||||||
import { Textarea } from '@chakra-ui/react';
|
import { Textarea } from '@chakra-ui/react';
|
||||||
|
import { ChangeEvent } from 'react';
|
||||||
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
||||||
import { RootState } from '../../app/store';
|
import { RootState } from '../../app/store';
|
||||||
import { setPrompt } from '../sd/sdSlice';
|
import { setPrompt } from '../sd/sdSlice';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prompt input text area.
|
||||||
|
*/
|
||||||
const PromptInput = () => {
|
const PromptInput = () => {
|
||||||
const { prompt } = useAppSelector((state: RootState) => state.sd);
|
const { prompt } = useAppSelector((state: RootState) => state.sd);
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
const handleChangePrompt = (e: ChangeEvent<HTMLTextAreaElement>) =>
|
||||||
|
dispatch(setPrompt(e.target.value));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Textarea
|
<Textarea
|
||||||
id='prompt'
|
id="prompt"
|
||||||
name='prompt'
|
name="prompt"
|
||||||
resize='none'
|
resize="none"
|
||||||
size={'lg'}
|
size={'lg'}
|
||||||
height={'100%'}
|
height={'100%'}
|
||||||
isInvalid={!prompt.length}
|
isInvalid={!prompt.length}
|
||||||
onChange={(e) => dispatch(setPrompt(e.target.value))}
|
onChange={handleChangePrompt}
|
||||||
value={prompt}
|
value={prompt}
|
||||||
placeholder="I'm dreaming of..."
|
placeholder="I'm dreaming of..."
|
||||||
/>
|
/>
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
import {
|
|
||||||
Slider,
|
|
||||||
SliderTrack,
|
|
||||||
SliderFilledTrack,
|
|
||||||
SliderThumb,
|
|
||||||
FormControl,
|
|
||||||
FormLabel,
|
|
||||||
Text,
|
|
||||||
Flex,
|
|
||||||
SliderProps,
|
|
||||||
} from '@chakra-ui/react';
|
|
||||||
|
|
||||||
interface Props extends SliderProps {
|
|
||||||
label: string;
|
|
||||||
value: number;
|
|
||||||
fontSize?: number | string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SDSlider = ({
|
|
||||||
label,
|
|
||||||
value,
|
|
||||||
fontSize = 'sm',
|
|
||||||
onChange,
|
|
||||||
...rest
|
|
||||||
}: Props) => {
|
|
||||||
return (
|
|
||||||
<FormControl>
|
|
||||||
<Flex gap={2}>
|
|
||||||
<FormLabel marginInlineEnd={0} marginBottom={1}>
|
|
||||||
<Text fontSize={fontSize} whiteSpace='nowrap'>
|
|
||||||
{label}
|
|
||||||
</Text>
|
|
||||||
</FormLabel>
|
|
||||||
<Slider
|
|
||||||
aria-label={label}
|
|
||||||
focusThumbOnChange={true}
|
|
||||||
value={value}
|
|
||||||
onChange={onChange}
|
|
||||||
{...rest}
|
|
||||||
>
|
|
||||||
<SliderTrack>
|
|
||||||
<SliderFilledTrack />
|
|
||||||
</SliderTrack>
|
|
||||||
<SliderThumb />
|
|
||||||
</Slider>
|
|
||||||
</Flex>
|
|
||||||
</FormControl>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SDSlider;
|
|
@ -11,6 +11,7 @@ import SDSelect from '../../components/SDSelect';
|
|||||||
import { SAMPLERS } from '../../app/constants';
|
import { SAMPLERS } from '../../app/constants';
|
||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
import { isEqual } from 'lodash';
|
import { isEqual } from 'lodash';
|
||||||
|
import { ChangeEvent } from 'react';
|
||||||
|
|
||||||
const sdSelector = createSelector(
|
const sdSelector = createSelector(
|
||||||
(state: RootState) => state.sd,
|
(state: RootState) => state.sd,
|
||||||
@ -28,31 +29,42 @@ const sdSelector = createSelector(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sampler options. Includes steps, CFG scale, sampler.
|
||||||
|
*/
|
||||||
const SamplerOptions = () => {
|
const SamplerOptions = () => {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
const { steps, cfgScale, sampler } = useAppSelector(sdSelector);
|
const { steps, cfgScale, sampler } = useAppSelector(sdSelector);
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const handleChangeSteps = (v: string | number) =>
|
||||||
|
dispatch(setSteps(Number(v)));
|
||||||
|
|
||||||
|
const handleChangeCfgScale = (v: string | number) =>
|
||||||
|
dispatch(setCfgScale(Number(v)));
|
||||||
|
|
||||||
|
const handleChangeSampler = (e: ChangeEvent<HTMLSelectElement>) =>
|
||||||
|
dispatch(setSampler(e.target.value));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex gap={2} direction={'column'}>
|
<Flex gap={2} direction={'column'}>
|
||||||
<SDNumberInput
|
<SDNumberInput
|
||||||
label='Steps'
|
label="Steps"
|
||||||
min={1}
|
min={1}
|
||||||
step={1}
|
step={1}
|
||||||
precision={0}
|
precision={0}
|
||||||
onChange={(v) => dispatch(setSteps(Number(v)))}
|
onChange={handleChangeSteps}
|
||||||
value={steps}
|
value={steps}
|
||||||
/>
|
/>
|
||||||
<SDNumberInput
|
<SDNumberInput
|
||||||
label='CFG scale'
|
label="CFG scale"
|
||||||
step={0.5}
|
step={0.5}
|
||||||
onChange={(v) => dispatch(setCfgScale(Number(v)))}
|
onChange={handleChangeCfgScale}
|
||||||
value={cfgScale}
|
value={cfgScale}
|
||||||
/>
|
/>
|
||||||
<SDSelect
|
<SDSelect
|
||||||
label='Sampler'
|
label="Sampler"
|
||||||
value={sampler}
|
value={sampler}
|
||||||
onChange={(e) => dispatch(setSampler(e.target.value))}
|
onChange={handleChangeSampler}
|
||||||
validValues={SAMPLERS}
|
validValues={SAMPLERS}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
@ -9,28 +9,29 @@ import {
|
|||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
import { isEqual } from 'lodash';
|
import { isEqual } from 'lodash';
|
||||||
|
import { ChangeEvent } from 'react';
|
||||||
import { NUMPY_RAND_MAX, NUMPY_RAND_MIN } from '../../app/constants';
|
import { NUMPY_RAND_MAX, NUMPY_RAND_MIN } from '../../app/constants';
|
||||||
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
||||||
import { RootState } from '../../app/store';
|
import { RootState } from '../../app/store';
|
||||||
import SDNumberInput from '../../components/SDNumberInput';
|
import SDNumberInput from '../../components/SDNumberInput';
|
||||||
import SDSwitch from '../../components/SDSwitch';
|
import SDSwitch from '../../components/SDSwitch';
|
||||||
import {
|
import {
|
||||||
randomizeSeed,
|
|
||||||
SDState,
|
SDState,
|
||||||
setIterations,
|
setIterations,
|
||||||
setSeed,
|
setSeed,
|
||||||
setSeedWeights,
|
setSeedWeights,
|
||||||
setShouldGenerateVariations,
|
setShouldGenerateVariations,
|
||||||
setShouldRandomizeSeed,
|
setShouldRandomizeSeed,
|
||||||
setVariantAmount,
|
setVariationAmount,
|
||||||
} from './sdSlice';
|
} from './sdSlice';
|
||||||
|
import randomInt from './util/randomInt';
|
||||||
import { validateSeedWeights } from './util/seedWeightPairs';
|
import { validateSeedWeights } from './util/seedWeightPairs';
|
||||||
|
|
||||||
const sdSelector = createSelector(
|
const sdSelector = createSelector(
|
||||||
(state: RootState) => state.sd,
|
(state: RootState) => state.sd,
|
||||||
(sd: SDState) => {
|
(sd: SDState) => {
|
||||||
return {
|
return {
|
||||||
variantAmount: sd.variantAmount,
|
variationAmount: sd.variationAmount,
|
||||||
seedWeights: sd.seedWeights,
|
seedWeights: sd.seedWeights,
|
||||||
shouldGenerateVariations: sd.shouldGenerateVariations,
|
shouldGenerateVariations: sd.shouldGenerateVariations,
|
||||||
shouldRandomizeSeed: sd.shouldRandomizeSeed,
|
shouldRandomizeSeed: sd.shouldRandomizeSeed,
|
||||||
@ -45,10 +46,13 @@ const sdSelector = createSelector(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Seed & variation options. Includes iteration, seed, seed randomization, variation options.
|
||||||
|
*/
|
||||||
const SeedVariationOptions = () => {
|
const SeedVariationOptions = () => {
|
||||||
const {
|
const {
|
||||||
shouldGenerateVariations,
|
shouldGenerateVariations,
|
||||||
variantAmount,
|
variationAmount,
|
||||||
seedWeights,
|
seedWeights,
|
||||||
shouldRandomizeSeed,
|
shouldRandomizeSeed,
|
||||||
seed,
|
seed,
|
||||||
@ -57,26 +61,45 @@ const SeedVariationOptions = () => {
|
|||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
const handleChangeIterations = (v: string | number) =>
|
||||||
|
dispatch(setIterations(Number(v)));
|
||||||
|
|
||||||
|
const handleChangeShouldRandomizeSeed = (e: ChangeEvent<HTMLInputElement>) =>
|
||||||
|
dispatch(setShouldRandomizeSeed(e.target.checked));
|
||||||
|
|
||||||
|
const handleChangeSeed = (v: string | number) => dispatch(setSeed(Number(v)));
|
||||||
|
|
||||||
|
const handleClickRandomizeSeed = () =>
|
||||||
|
dispatch(setSeed(randomInt(NUMPY_RAND_MIN, NUMPY_RAND_MAX)));
|
||||||
|
|
||||||
|
const handleChangeShouldGenerateVariations = (
|
||||||
|
e: ChangeEvent<HTMLInputElement>
|
||||||
|
) => dispatch(setShouldGenerateVariations(e.target.checked));
|
||||||
|
|
||||||
|
const handleChangevariationAmount = (v: string | number) =>
|
||||||
|
dispatch(setVariationAmount(Number(v)));
|
||||||
|
|
||||||
|
const handleChangeSeedWeights = (e: ChangeEvent<HTMLInputElement>) =>
|
||||||
|
dispatch(setSeedWeights(e.target.value));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex gap={2} direction={'column'}>
|
<Flex gap={2} direction={'column'}>
|
||||||
<SDNumberInput
|
<SDNumberInput
|
||||||
label='Images to generate'
|
label="Images to generate"
|
||||||
step={1}
|
step={1}
|
||||||
min={1}
|
min={1}
|
||||||
precision={0}
|
precision={0}
|
||||||
onChange={(v) => dispatch(setIterations(Number(v)))}
|
onChange={handleChangeIterations}
|
||||||
value={iterations}
|
value={iterations}
|
||||||
/>
|
/>
|
||||||
<SDSwitch
|
<SDSwitch
|
||||||
label='Randomize seed on generation'
|
label="Randomize seed on generation"
|
||||||
isChecked={shouldRandomizeSeed}
|
isChecked={shouldRandomizeSeed}
|
||||||
onChange={(e) =>
|
onChange={handleChangeShouldRandomizeSeed}
|
||||||
dispatch(setShouldRandomizeSeed(e.target.checked))
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<Flex gap={2}>
|
<Flex gap={2}>
|
||||||
<SDNumberInput
|
<SDNumberInput
|
||||||
label='Seed'
|
label="Seed"
|
||||||
step={1}
|
step={1}
|
||||||
precision={0}
|
precision={0}
|
||||||
flexGrow={1}
|
flexGrow={1}
|
||||||
@ -84,13 +107,13 @@ const SeedVariationOptions = () => {
|
|||||||
max={NUMPY_RAND_MAX}
|
max={NUMPY_RAND_MAX}
|
||||||
isDisabled={shouldRandomizeSeed}
|
isDisabled={shouldRandomizeSeed}
|
||||||
isInvalid={seed < 0 && shouldGenerateVariations}
|
isInvalid={seed < 0 && shouldGenerateVariations}
|
||||||
onChange={(v) => dispatch(setSeed(Number(v)))}
|
onChange={handleChangeSeed}
|
||||||
value={seed}
|
value={seed}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
size={'sm'}
|
size={'sm'}
|
||||||
isDisabled={shouldRandomizeSeed}
|
isDisabled={shouldRandomizeSeed}
|
||||||
onClick={() => dispatch(randomizeSeed())}
|
onClick={handleClickRandomizeSeed}
|
||||||
>
|
>
|
||||||
<Text pl={2} pr={2}>
|
<Text pl={2} pr={2}>
|
||||||
Shuffle
|
Shuffle
|
||||||
@ -98,21 +121,18 @@ const SeedVariationOptions = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Flex>
|
</Flex>
|
||||||
<SDSwitch
|
<SDSwitch
|
||||||
label='Generate variations'
|
label="Generate variations"
|
||||||
isChecked={shouldGenerateVariations}
|
isChecked={shouldGenerateVariations}
|
||||||
width={'auto'}
|
width={'auto'}
|
||||||
onChange={(e) =>
|
onChange={handleChangeShouldGenerateVariations}
|
||||||
dispatch(setShouldGenerateVariations(e.target.checked))
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<SDNumberInput
|
<SDNumberInput
|
||||||
label='Variation amount'
|
label="Variation amount"
|
||||||
value={variantAmount}
|
value={variationAmount}
|
||||||
step={0.01}
|
step={0.01}
|
||||||
min={0}
|
min={0}
|
||||||
max={1}
|
max={1}
|
||||||
isDisabled={!shouldGenerateVariations}
|
onChange={handleChangevariationAmount}
|
||||||
onChange={(v) => dispatch(setVariantAmount(Number(v)))}
|
|
||||||
/>
|
/>
|
||||||
<FormControl
|
<FormControl
|
||||||
isInvalid={
|
isInvalid={
|
||||||
@ -120,20 +140,15 @@ const SeedVariationOptions = () => {
|
|||||||
!(validateSeedWeights(seedWeights) || seedWeights === '')
|
!(validateSeedWeights(seedWeights) || seedWeights === '')
|
||||||
}
|
}
|
||||||
flexGrow={1}
|
flexGrow={1}
|
||||||
isDisabled={!shouldGenerateVariations}
|
|
||||||
>
|
>
|
||||||
<HStack>
|
<HStack>
|
||||||
<FormLabel marginInlineEnd={0} marginBottom={1}>
|
<FormLabel marginInlineEnd={0} marginBottom={1}>
|
||||||
<Text whiteSpace='nowrap'>
|
<Text whiteSpace="nowrap">Seed Weights</Text>
|
||||||
Seed Weights
|
|
||||||
</Text>
|
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<Input
|
<Input
|
||||||
size={'sm'}
|
size={'sm'}
|
||||||
value={seedWeights}
|
value={seedWeights}
|
||||||
onChange={(e) =>
|
onChange={handleChangeSeedWeights}
|
||||||
dispatch(setSeedWeights(e.target.value))
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</HStack>
|
</HStack>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
@ -1,92 +0,0 @@
|
|||||||
import {
|
|
||||||
Flex,
|
|
||||||
FormControl,
|
|
||||||
FormLabel,
|
|
||||||
HStack,
|
|
||||||
Input,
|
|
||||||
Text,
|
|
||||||
} from '@chakra-ui/react';
|
|
||||||
import { createSelector } from '@reduxjs/toolkit';
|
|
||||||
import { isEqual } from 'lodash';
|
|
||||||
import { useAppDispatch, useAppSelector } from '../../app/hooks';
|
|
||||||
import { RootState } from '../../app/store';
|
|
||||||
import SDNumberInput from '../../components/SDNumberInput';
|
|
||||||
import SDSwitch from '../../components/SDSwitch';
|
|
||||||
import {
|
|
||||||
SDState,
|
|
||||||
setSeedWeights,
|
|
||||||
setShouldGenerateVariations,
|
|
||||||
setVariantAmount,
|
|
||||||
} from './sdSlice';
|
|
||||||
import { validateSeedWeights } from './util/seedWeightPairs';
|
|
||||||
|
|
||||||
const sdSelector = createSelector(
|
|
||||||
(state: RootState) => state.sd,
|
|
||||||
(sd: SDState) => {
|
|
||||||
return {
|
|
||||||
variantAmount: sd.variantAmount,
|
|
||||||
seedWeights: sd.seedWeights,
|
|
||||||
shouldGenerateVariations: sd.shouldGenerateVariations,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
{
|
|
||||||
memoizeOptions: {
|
|
||||||
resultEqualityCheck: isEqual,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const Variant = () => {
|
|
||||||
const { shouldGenerateVariations, variantAmount, seedWeights } =
|
|
||||||
useAppSelector(sdSelector);
|
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Flex gap={2} alignItems={'center'} pl={1}>
|
|
||||||
<SDSwitch
|
|
||||||
label='Generate variations'
|
|
||||||
isChecked={shouldGenerateVariations}
|
|
||||||
width={'auto'}
|
|
||||||
onChange={(e) =>
|
|
||||||
dispatch(setShouldGenerateVariations(e.target.checked))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<SDNumberInput
|
|
||||||
label='Amount'
|
|
||||||
value={variantAmount}
|
|
||||||
step={0.01}
|
|
||||||
min={0}
|
|
||||||
max={1}
|
|
||||||
width={240}
|
|
||||||
isDisabled={!shouldGenerateVariations}
|
|
||||||
onChange={(v) => dispatch(setVariantAmount(Number(v)))}
|
|
||||||
/>
|
|
||||||
<FormControl
|
|
||||||
isInvalid={
|
|
||||||
shouldGenerateVariations &&
|
|
||||||
!(validateSeedWeights(seedWeights) || seedWeights === '')
|
|
||||||
}
|
|
||||||
flexGrow={1}
|
|
||||||
isDisabled={!shouldGenerateVariations}
|
|
||||||
>
|
|
||||||
<HStack>
|
|
||||||
<FormLabel marginInlineEnd={0} marginBottom={1}>
|
|
||||||
<Text fontSize={'sm'} whiteSpace='nowrap'>
|
|
||||||
Seed Weights
|
|
||||||
</Text>
|
|
||||||
</FormLabel>
|
|
||||||
<Input
|
|
||||||
size={'sm'}
|
|
||||||
value={seedWeights}
|
|
||||||
onChange={(e) =>
|
|
||||||
dispatch(setSeedWeights(e.target.value))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</HStack>
|
|
||||||
</FormControl>
|
|
||||||
</Flex>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Variant;
|
|
@ -1,8 +1,6 @@
|
|||||||
import { createSlice } from '@reduxjs/toolkit';
|
import { createSlice } from '@reduxjs/toolkit';
|
||||||
import type { PayloadAction } from '@reduxjs/toolkit';
|
import type { PayloadAction } from '@reduxjs/toolkit';
|
||||||
import { SDMetadata } from '../gallery/gallerySlice';
|
import { SDMetadata } from '../gallery/gallerySlice';
|
||||||
import randomInt from './util/randomInt';
|
|
||||||
import { NUMPY_RAND_MAX, NUMPY_RAND_MIN } from '../../app/constants';
|
|
||||||
|
|
||||||
const calculateRealSteps = (
|
const calculateRealSteps = (
|
||||||
steps: number,
|
steps: number,
|
||||||
@ -12,7 +10,7 @@ const calculateRealSteps = (
|
|||||||
return hasInitImage ? Math.floor(strength * steps) : steps;
|
return hasInitImage ? Math.floor(strength * steps) : steps;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type UpscalingLevel = 0 | 2 | 3 | 4;
|
export type UpscalingLevel = 0 | 2 | 4;
|
||||||
|
|
||||||
export interface SDState {
|
export interface SDState {
|
||||||
prompt: string;
|
prompt: string;
|
||||||
@ -34,7 +32,7 @@ export interface SDState {
|
|||||||
seamless: boolean;
|
seamless: boolean;
|
||||||
shouldFitToWidthHeight: boolean;
|
shouldFitToWidthHeight: boolean;
|
||||||
shouldGenerateVariations: boolean;
|
shouldGenerateVariations: boolean;
|
||||||
variantAmount: number;
|
variationAmount: number;
|
||||||
seedWeights: string;
|
seedWeights: string;
|
||||||
shouldRunESRGAN: boolean;
|
shouldRunESRGAN: boolean;
|
||||||
shouldRunGFPGAN: boolean;
|
shouldRunGFPGAN: boolean;
|
||||||
@ -58,7 +56,7 @@ const initialSDState: SDState = {
|
|||||||
maskPath: '',
|
maskPath: '',
|
||||||
shouldFitToWidthHeight: true,
|
shouldFitToWidthHeight: true,
|
||||||
shouldGenerateVariations: false,
|
shouldGenerateVariations: false,
|
||||||
variantAmount: 0.1,
|
variationAmount: 0.1,
|
||||||
seedWeights: '',
|
seedWeights: '',
|
||||||
shouldRunESRGAN: false,
|
shouldRunESRGAN: false,
|
||||||
upscalingLevel: 4,
|
upscalingLevel: 4,
|
||||||
@ -151,9 +149,6 @@ export const sdSlice = createSlice({
|
|||||||
resetSeed: (state) => {
|
resetSeed: (state) => {
|
||||||
state.seed = -1;
|
state.seed = -1;
|
||||||
},
|
},
|
||||||
randomizeSeed: (state) => {
|
|
||||||
state.seed = randomInt(NUMPY_RAND_MIN, NUMPY_RAND_MAX);
|
|
||||||
},
|
|
||||||
setParameter: (
|
setParameter: (
|
||||||
state,
|
state,
|
||||||
action: PayloadAction<{ key: string; value: string | number | boolean }>
|
action: PayloadAction<{ key: string; value: string | number | boolean }>
|
||||||
@ -171,8 +166,8 @@ export const sdSlice = createSlice({
|
|||||||
setShouldGenerateVariations: (state, action: PayloadAction<boolean>) => {
|
setShouldGenerateVariations: (state, action: PayloadAction<boolean>) => {
|
||||||
state.shouldGenerateVariations = action.payload;
|
state.shouldGenerateVariations = action.payload;
|
||||||
},
|
},
|
||||||
setVariantAmount: (state, action: PayloadAction<number>) => {
|
setVariationAmount: (state, action: PayloadAction<number>) => {
|
||||||
state.variantAmount = action.payload;
|
state.variationAmount = action.payload;
|
||||||
},
|
},
|
||||||
setSeedWeights: (state, action: PayloadAction<string>) => {
|
setSeedWeights: (state, action: PayloadAction<string>) => {
|
||||||
state.seedWeights = action.payload;
|
state.seedWeights = action.payload;
|
||||||
@ -267,13 +262,12 @@ export const {
|
|||||||
setInitialImagePath,
|
setInitialImagePath,
|
||||||
setMaskPath,
|
setMaskPath,
|
||||||
resetSeed,
|
resetSeed,
|
||||||
randomizeSeed,
|
|
||||||
resetSDState,
|
resetSDState,
|
||||||
setShouldFitToWidthHeight,
|
setShouldFitToWidthHeight,
|
||||||
setParameter,
|
setParameter,
|
||||||
setShouldGenerateVariations,
|
setShouldGenerateVariations,
|
||||||
setSeedWeights,
|
setSeedWeights,
|
||||||
setVariantAmount,
|
setVariationAmount,
|
||||||
setAllParameters,
|
setAllParameters,
|
||||||
setShouldRunGFPGAN,
|
setShouldRunGFPGAN,
|
||||||
setShouldRunESRGAN,
|
setShouldRunESRGAN,
|
||||||
|
@ -18,6 +18,7 @@ const logSelector = createSelector(
|
|||||||
(system: SystemState) => system.log,
|
(system: SystemState) => system.log,
|
||||||
{
|
{
|
||||||
memoizeOptions: {
|
memoizeOptions: {
|
||||||
|
// We don't need a deep equality check for this selector.
|
||||||
resultEqualityCheck: (a, b) => a.length === b.length,
|
resultEqualityCheck: (a, b) => a.length === b.length,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -35,22 +36,26 @@ const systemSelector = createSelector(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic log viewer, floats on bottom of page.
|
||||||
|
*/
|
||||||
const LogViewer = () => {
|
const LogViewer = () => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const bg = useColorModeValue('gray.50', 'gray.900');
|
|
||||||
const borderColor = useColorModeValue('gray.500', 'gray.500');
|
|
||||||
const [shouldAutoscroll, setShouldAutoscroll] = useState<boolean>(true);
|
|
||||||
|
|
||||||
const log = useAppSelector(logSelector);
|
const log = useAppSelector(logSelector);
|
||||||
const { shouldShowLogViewer } = useAppSelector(systemSelector);
|
const { shouldShowLogViewer } = useAppSelector(systemSelector);
|
||||||
|
|
||||||
|
const bg = useColorModeValue('gray.50', 'gray.900');
|
||||||
|
const borderColor = useColorModeValue('gray.500', 'gray.500');
|
||||||
|
|
||||||
|
// Rudimentary autoscroll
|
||||||
|
const [shouldAutoscroll, setShouldAutoscroll] = useState<boolean>(true);
|
||||||
const viewerRef = useRef<HTMLDivElement>(null);
|
const viewerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (viewerRef.current !== null && shouldAutoscroll) {
|
if (viewerRef.current !== null && shouldAutoscroll) {
|
||||||
viewerRef.current.scrollTop = viewerRef.current.scrollHeight;
|
viewerRef.current.scrollTop = viewerRef.current.scrollHeight;
|
||||||
}
|
}
|
||||||
});
|
}, [shouldAutoscroll]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -59,26 +64,26 @@ const LogViewer = () => {
|
|||||||
position={'fixed'}
|
position={'fixed'}
|
||||||
left={0}
|
left={0}
|
||||||
bottom={0}
|
bottom={0}
|
||||||
height='200px'
|
height="200px" // TODO: Make the log viewer resizeable.
|
||||||
width='100vw'
|
width="100vw"
|
||||||
overflow='auto'
|
overflow="auto"
|
||||||
direction='column'
|
direction="column"
|
||||||
fontFamily='monospace'
|
fontFamily="monospace"
|
||||||
fontSize='sm'
|
fontSize="sm"
|
||||||
pl={12}
|
pl={12}
|
||||||
pr={2}
|
pr={2}
|
||||||
pb={2}
|
pb={2}
|
||||||
borderTopWidth='4px'
|
borderTopWidth="4px"
|
||||||
borderColor={borderColor}
|
borderColor={borderColor}
|
||||||
background={bg}
|
background={bg}
|
||||||
ref={viewerRef}
|
ref={viewerRef}
|
||||||
>
|
>
|
||||||
{log.map((entry, i) => (
|
{log.map((entry, i) => (
|
||||||
<Flex gap={2} key={i}>
|
<Flex gap={2} key={i}>
|
||||||
<Text fontSize='sm' fontWeight={'semibold'}>
|
<Text fontSize="sm" fontWeight={'semibold'}>
|
||||||
{entry.timestamp}:
|
{entry.timestamp}:
|
||||||
</Text>
|
</Text>
|
||||||
<Text fontSize='sm' wordBreak={'break-all'}>
|
<Text fontSize="sm" wordBreak={'break-all'}>
|
||||||
{entry.message}
|
{entry.message}
|
||||||
</Text>
|
</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
@ -86,17 +91,13 @@ const LogViewer = () => {
|
|||||||
</Flex>
|
</Flex>
|
||||||
)}
|
)}
|
||||||
{shouldShowLogViewer && (
|
{shouldShowLogViewer && (
|
||||||
<Tooltip
|
<Tooltip label={shouldAutoscroll ? 'Autoscroll on' : 'Autoscroll off'}>
|
||||||
label={
|
|
||||||
shouldAutoscroll ? 'Autoscroll on' : 'Autoscroll off'
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<IconButton
|
<IconButton
|
||||||
size='sm'
|
size="sm"
|
||||||
position={'fixed'}
|
position={'fixed'}
|
||||||
left={2}
|
left={2}
|
||||||
bottom={12}
|
bottom={12}
|
||||||
aria-label='Toggle autoscroll'
|
aria-label="Toggle autoscroll"
|
||||||
variant={'solid'}
|
variant={'solid'}
|
||||||
colorScheme={shouldAutoscroll ? 'blue' : 'gray'}
|
colorScheme={shouldAutoscroll ? 'blue' : 'gray'}
|
||||||
icon={<FaAngleDoubleDown />}
|
icon={<FaAngleDoubleDown />}
|
||||||
@ -106,16 +107,14 @@ const LogViewer = () => {
|
|||||||
)}
|
)}
|
||||||
<Tooltip label={shouldShowLogViewer ? 'Hide logs' : 'Show logs'}>
|
<Tooltip label={shouldShowLogViewer ? 'Hide logs' : 'Show logs'}>
|
||||||
<IconButton
|
<IconButton
|
||||||
size='sm'
|
size="sm"
|
||||||
position={'fixed'}
|
position={'fixed'}
|
||||||
left={2}
|
left={2}
|
||||||
bottom={2}
|
bottom={2}
|
||||||
variant={'solid'}
|
variant={'solid'}
|
||||||
aria-label='Toggle Log Viewer'
|
aria-label="Toggle Log Viewer"
|
||||||
icon={shouldShowLogViewer ? <FaMinus /> : <FaCode />}
|
icon={shouldShowLogViewer ? <FaMinus /> : <FaCode />}
|
||||||
onClick={() =>
|
onClick={() => dispatch(setShouldShowLogViewer(!shouldShowLogViewer))}
|
||||||
dispatch(setShouldShowLogViewer(!shouldShowLogViewer))
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</>
|
</>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
Button,
|
||||||
Flex,
|
Flex,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
@ -22,7 +23,6 @@ import {
|
|||||||
SystemState,
|
SystemState,
|
||||||
} from './systemSlice';
|
} from './systemSlice';
|
||||||
import { RootState } from '../../app/store';
|
import { RootState } from '../../app/store';
|
||||||
import SDButton from '../../components/SDButton';
|
|
||||||
import { persistor } from '../../main';
|
import { persistor } from '../../main';
|
||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
import { isEqual } from 'lodash';
|
import { isEqual } from 'lodash';
|
||||||
@ -39,11 +39,18 @@ const systemSelector = createSelector(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
type Props = {
|
type SettingsModalProps = {
|
||||||
|
/* The button to open the Settings Modal */
|
||||||
children: ReactElement;
|
children: ReactElement;
|
||||||
};
|
};
|
||||||
|
|
||||||
const SettingsModal = ({ children }: Props) => {
|
/**
|
||||||
|
* Modal for app settings. Also provides Reset functionality in which the
|
||||||
|
* app's localstorage is wiped via redux-persist.
|
||||||
|
*
|
||||||
|
* Secondary post-reset modal is included here.
|
||||||
|
*/
|
||||||
|
const SettingsModal = ({ children }: SettingsModalProps) => {
|
||||||
const {
|
const {
|
||||||
isOpen: isSettingsModalOpen,
|
isOpen: isSettingsModalOpen,
|
||||||
onOpen: onSettingsModalOpen,
|
onOpen: onSettingsModalOpen,
|
||||||
@ -61,6 +68,10 @@ const SettingsModal = ({ children }: Props) => {
|
|||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets localstorage, then opens a secondary modal informing user to
|
||||||
|
* refresh their browser.
|
||||||
|
* */
|
||||||
const handleClickResetWebUI = () => {
|
const handleClickResetWebUI = () => {
|
||||||
persistor.purge().then(() => {
|
persistor.purge().then(() => {
|
||||||
onSettingsModalClose();
|
onSettingsModalClose();
|
||||||
@ -80,7 +91,7 @@ const SettingsModal = ({ children }: Props) => {
|
|||||||
<ModalHeader>Settings</ModalHeader>
|
<ModalHeader>Settings</ModalHeader>
|
||||||
<ModalCloseButton />
|
<ModalCloseButton />
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<Flex gap={5} direction='column'>
|
<Flex gap={5} direction="column">
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<HStack>
|
<HStack>
|
||||||
<FormLabel marginBottom={1}>
|
<FormLabel marginBottom={1}>
|
||||||
@ -89,28 +100,18 @@ const SettingsModal = ({ children }: Props) => {
|
|||||||
<Switch
|
<Switch
|
||||||
isChecked={shouldDisplayInProgress}
|
isChecked={shouldDisplayInProgress}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
dispatch(
|
dispatch(setShouldDisplayInProgress(e.target.checked))
|
||||||
setShouldDisplayInProgress(
|
|
||||||
e.target.checked
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</HStack>
|
</HStack>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<HStack>
|
<HStack>
|
||||||
<FormLabel marginBottom={1}>
|
<FormLabel marginBottom={1}>Confirm on delete</FormLabel>
|
||||||
Confirm on delete
|
|
||||||
</FormLabel>
|
|
||||||
<Switch
|
<Switch
|
||||||
isChecked={shouldConfirmOnDelete}
|
isChecked={shouldConfirmOnDelete}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
dispatch(
|
dispatch(setShouldConfirmOnDelete(e.target.checked))
|
||||||
setShouldConfirmOnDelete(
|
|
||||||
e.target.checked
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</HStack>
|
</HStack>
|
||||||
@ -118,29 +119,23 @@ const SettingsModal = ({ children }: Props) => {
|
|||||||
|
|
||||||
<Heading size={'md'}>Reset Web UI</Heading>
|
<Heading size={'md'}>Reset Web UI</Heading>
|
||||||
<Text>
|
<Text>
|
||||||
Resetting the web UI only resets the browser's
|
Resetting the web UI only resets the browser's local cache of
|
||||||
local cache of your images and remembered
|
your images and remembered settings. It does not delete any
|
||||||
settings. It does not delete any images from
|
images from disk.
|
||||||
disk.
|
|
||||||
</Text>
|
</Text>
|
||||||
<Text>
|
<Text>
|
||||||
If images aren't showing up in the gallery or
|
If images aren't showing up in the gallery or something else
|
||||||
something else isn't working, please try
|
isn't working, please try resetting before submitting an issue
|
||||||
resetting before submitting an issue on GitHub.
|
on GitHub.
|
||||||
</Text>
|
</Text>
|
||||||
<SDButton
|
<Button colorScheme="red" onClick={handleClickResetWebUI}>
|
||||||
label='Reset Web UI'
|
Reset Web UI
|
||||||
colorScheme='red'
|
</Button>
|
||||||
onClick={handleClickResetWebUI}
|
|
||||||
/>
|
|
||||||
</Flex>
|
</Flex>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
|
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<SDButton
|
<Button onClick={onSettingsModalClose}>Close</Button>
|
||||||
label='Close'
|
|
||||||
onClick={onSettingsModalClose}
|
|
||||||
/>
|
|
||||||
</ModalFooter>
|
</ModalFooter>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
@ -151,13 +146,12 @@ const SettingsModal = ({ children }: Props) => {
|
|||||||
onClose={onRefreshModalClose}
|
onClose={onRefreshModalClose}
|
||||||
isCentered
|
isCentered
|
||||||
>
|
>
|
||||||
<ModalOverlay bg='blackAlpha.300' backdropFilter='blur(40px)' />
|
<ModalOverlay bg="blackAlpha.300" backdropFilter="blur(40px)" />
|
||||||
<ModalContent>
|
<ModalContent>
|
||||||
<ModalBody pb={6} pt={6}>
|
<ModalBody pb={6} pt={6}>
|
||||||
<Flex justifyContent={'center'}>
|
<Flex justifyContent={'center'}>
|
||||||
<Text fontSize={'lg'}>
|
<Text fontSize={'lg'}>
|
||||||
Web UI has been reset. Refresh the page to
|
Web UI has been reset. Refresh the page to reload.
|
||||||
reload.
|
|
||||||
</Text>
|
</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
|
@ -41,14 +41,11 @@ const systemSelector = createSelector(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/**
|
||||||
Checks relevant pieces of state to confirm generation will not deterministically fail.
|
* Checks relevant pieces of state to confirm generation will not deterministically fail.
|
||||||
|
* This is used to prevent the 'Generate' button from being clicked.
|
||||||
This is used to prevent the 'Generate' button from being clicked.
|
|
||||||
|
|
||||||
Other parameter values may cause failure but we rely on input validation for those.
|
|
||||||
*/
|
*/
|
||||||
const useCheckParameters = () => {
|
const useCheckParameters = (): boolean => {
|
||||||
const {
|
const {
|
||||||
prompt,
|
prompt,
|
||||||
shouldGenerateVariations,
|
shouldGenerateVariations,
|
||||||
@ -85,8 +82,7 @@ const useCheckParameters = () => {
|
|||||||
// Cannot generate variations without valid seed weights
|
// Cannot generate variations without valid seed weights
|
||||||
if (
|
if (
|
||||||
shouldGenerateVariations &&
|
shouldGenerateVariations &&
|
||||||
(!(validateSeedWeights(seedWeights) || seedWeights === '') ||
|
(!(validateSeedWeights(seedWeights) || seedWeights === '') || seed === -1)
|
||||||
seed === -1)
|
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user