Adds support for inpaint_replace

This commit is contained in:
psychedelicious 2022-10-28 02:04:32 +11:00
parent 4039e9e368
commit 4cf9c965d4
11 changed files with 575 additions and 1009 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

517
frontend/dist/assets/index.4150d00b.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,9 +5,9 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>InvokeAI - A Stable Diffusion Toolkit</title>
<link rel="shortcut icon" type="icon" href="/assets/favicon.0d253ced.ico" />
<script type="module" crossorigin src="/assets/index.38ff1a03.js"></script>
<link rel="stylesheet" href="/assets/index.8391cc9a.css">
<link rel="shortcut icon" type="icon" href="./assets/favicon.0d253ced.ico" />
<script type="module" crossorigin src="./assets/index.4150d00b.js"></script>
<link rel="stylesheet" href="./assets/index.44f7d837.css">
</head>
<body>

View File

@ -102,6 +102,8 @@ export const frontendToBackendParameters = (
boundingBoxCoordinate: { x, y },
boundingBoxDimensions: { width, height },
shouldShowBoundingBox,
inpaintReplace,
shouldUseInpaintReplace,
} = inpaintingState;
let bx = x,
@ -123,6 +125,10 @@ export const frontendToBackendParameters = (
height: bheight,
};
if (shouldUseInpaintReplace) {
generationParameters.inpaint_replace = inpaintReplace;
}
generationParameters.init_img = imageToProcessUrl;
generationParameters.strength = img2imgStrength;
generationParameters.fit = false;

View File

@ -1,6 +1,6 @@
import { useToast } from '@chakra-ui/react';
import { createSelector } from '@reduxjs/toolkit';
import React from 'react';
import React, { ChangeEvent } from 'react';
import {
RootState,
useAppDispatch,
@ -10,17 +10,24 @@ import IAIButton from '../../../../common/components/IAIButton';
import {
InpaintingState,
setClearBrushHistory,
setInpaintReplace,
setShouldUseInpaintReplace,
} from '../../../tabs/Inpainting/inpaintingSlice';
import BoundingBoxSettings from './BoundingBoxSettings';
import _ from 'lodash';
import IAINumberInput from '../../../../common/components/IAINumberInput';
import IAISwitch from '../../../../common/components/IAISwitch';
const inpaintingSelector = createSelector(
(state: RootState) => state.inpainting,
(inpainting: InpaintingState) => {
const { pastLines, futureLines } = inpainting;
const { pastLines, futureLines, inpaintReplace, shouldUseInpaintReplace } =
inpainting;
return {
pastLines,
futureLines,
inpaintReplace,
shouldUseInpaintReplace,
};
},
{
@ -34,7 +41,8 @@ export default function InpaintingSettings() {
const dispatch = useAppDispatch();
const toast = useToast();
const { pastLines, futureLines } = useAppSelector(inpaintingSelector);
const { pastLines, futureLines, inpaintReplace, shouldUseInpaintReplace } =
useAppSelector(inpaintingSelector);
const handleClearBrushHistory = () => {
dispatch(setClearBrushHistory());
@ -54,6 +62,28 @@ export default function InpaintingSettings() {
tooltip="Clears brush stroke history"
disabled={futureLines.length > 0 || pastLines.length > 0 ? false : true}
/>
<div style={{ display: 'flex', alignItems: 'center' }}>
<IAINumberInput
label="Inpaint Replace"
value={inpaintReplace}
min={0}
max={1.0}
step={0.05}
width={'auto'}
formControlProps={{ style: { paddingRight: '1rem' } }}
isInteger={false}
isDisabled={!shouldUseInpaintReplace}
onChange={(v: number) => {
dispatch(setInpaintReplace(v));
}}
/>
<IAISwitch
isChecked={shouldUseInpaintReplace}
onChange={(e: ChangeEvent<HTMLInputElement>) =>
dispatch(setShouldUseInpaintReplace(e.target.checked))
}
/>
</div>
</>
);
}

View File

@ -53,6 +53,8 @@ export interface InpaintingState {
needsRepaint: boolean;
stageScale: number;
isDrawing: boolean;
shouldUseInpaintReplace: boolean;
inpaintReplace: number;
}
const initialInpaintingState: InpaintingState = {
@ -79,6 +81,8 @@ const initialInpaintingState: InpaintingState = {
needsRepaint: false,
isDrawing: false,
stageScale: 1,
shouldUseInpaintReplace: false,
inpaintReplace: 0.5,
};
const initialState: InpaintingState = initialInpaintingState;
@ -251,7 +255,7 @@ export const inpaintingSlice = createSlice({
64,
roundedCanvasHeight
);
console.log(overflowX, boundingBoxX, boundingBoxX - overflowX);
const overflowCorrectedX =
overflowX > 0 ? boundingBoxX - overflowX : boundingBoxX;
@ -319,6 +323,12 @@ export const inpaintingSlice = createSlice({
state.pastLines = [];
state.futureLines = [];
},
setShouldUseInpaintReplace: (state, action: PayloadAction<boolean>) => {
state.shouldUseInpaintReplace = action.payload;
},
setInpaintReplace: (state, action: PayloadAction<number>) => {
state.inpaintReplace = action.payload;
},
},
});
@ -352,6 +362,8 @@ export const {
setShouldShowBrush,
setShouldShowBoundingBox,
setClearBrushHistory,
setShouldUseInpaintReplace,
setInpaintReplace,
} = inpaintingSlice.actions;
export default inpaintingSlice.reducer;

View File

@ -3,6 +3,8 @@ import { MaskLine } from '../inpaintingSlice';
/**
* Converts canvas into pixel buffer and checks if it is empty (all pixels full alpha).
*
* I DON' THINK THIS WORKS ACTUALLY
*/
const checkIsMaskEmpty = (image: HTMLImageElement, lines: MaskLine[]) => {
const offscreenContainer = document.createElement('div');