auto save result image when --output-dir exists

This commit is contained in:
Qing
2023-02-19 14:31:00 +08:00
parent 88a37ea904
commit 774f470e58
8 changed files with 103 additions and 38 deletions

View File

@@ -8,12 +8,14 @@ import {
enableFileManagerState,
fileState,
isDisableModelSwitchState,
isEnableAutoSavingState,
toastState,
} from './store/Atoms'
import { keepGUIAlive } from './utils'
import Header from './components/Header/Header'
import useHotKey from './hooks/useHotkey'
import {
getEnableAutoSaving,
getEnableFileManager,
getIsDisableModelSwitch,
isDesktop,
@@ -34,6 +36,7 @@ function App() {
const userInputImage = useInputImage()
const setIsDisableModelSwitch = useSetRecoilState(isDisableModelSwitchState)
const setEnableFileManager = useSetRecoilState(enableFileManagerState)
const setIsEnableAutoSavingState = useSetRecoilState(isEnableAutoSavingState)
// Set Input Image
useEffect(() => {
@@ -66,7 +69,17 @@ function App() {
setEnableFileManager(isEnabled === 'true')
}
fetchData2()
}, [setEnableFileManager, setIsDisableModelSwitch])
const fetchData3 = async () => {
const isEnabled = await getEnableAutoSaving().then(res => res.text())
setIsEnableAutoSavingState(isEnabled === 'true')
}
fetchData3()
}, [
setEnableFileManager,
setIsDisableModelSwitch,
setIsEnableAutoSavingState,
])
// Dark Mode Hotkey
useHotKey(

View File

@@ -122,6 +122,12 @@ export function getEnableFileManager() {
})
}
export function getEnableAutoSaving() {
return fetch(`${API_ENDPOINT}/is_enable_auto_saving`, {
method: 'GET',
})
}
export function switchModel(name: string) {
const fd = new FormData()
fd.append('name', name)

View File

@@ -20,7 +20,6 @@ import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'
import { useWindowSize, useKey, useKeyPressEvent } from 'react-use'
import inpaint, {
downloadToOutput,
makeGif,
postInteractiveSeg,
} from '../../adapters/inpainting'
import Button from '../shared/Button'
@@ -45,12 +44,11 @@ import {
imageWidthState,
interactiveSegClicksState,
isDiffusionModelsState,
isEnableAutoSavingState,
isInpaintingState,
isInteractiveSegRunningState,
isInteractiveSegState,
isPaintByExampleState,
isPix2PixState,
isSDState,
negativePropmtState,
propmtState,
runManuallyState,
@@ -184,6 +182,7 @@ export default function Editor() {
const [redoCurLines, setRedoCurLines] = useState<Line[]>([])
const [redoLineGroups, setRedoLineGroups] = useState<LineGroup[]>([])
const enableFileManager = useRecoilValue(enableFileManagerState)
const isEnableAutoSaving = useRecoilValue(isEnableAutoSavingState)
const setImageWidth = useSetRecoilState(imageWidthState)
const setImageHeight = useSetRecoilState(imageHeightState)
@@ -1101,7 +1100,7 @@ export default function Editor() {
if (file === undefined) {
return
}
if (enableFileManager && renders.length > 0) {
if ((enableFileManager || isEnableAutoSaving) && renders.length > 0) {
try {
downloadToOutput(renders[renders.length - 1], file.name, file.type)
setToastState({

View File

@@ -41,6 +41,7 @@ interface AppState {
disableShortCuts: boolean
isInpainting: boolean
isDisableModelSwitch: boolean
isEnableAutoSaving: boolean
isInteractiveSeg: boolean
isInteractiveSegRunning: boolean
interactiveSegClicks: number[][]
@@ -58,6 +59,7 @@ export const appState = atom<AppState>({
disableShortCuts: false,
isInpainting: false,
isDisableModelSwitch: false,
isEnableAutoSaving: false,
isInteractiveSeg: false,
isInteractiveSegRunning: false,
interactiveSegClicks: [],
@@ -221,6 +223,18 @@ export const isDisableModelSwitchState = selector({
},
})
export const isEnableAutoSavingState = selector({
key: 'isEnableAutoSavingState',
get: ({ get }) => {
const app = get(appState)
return app.isEnableAutoSaving
},
set: ({ get, set }, newValue: any) => {
const app = get(appState)
set(appState, { ...app, isEnableAutoSaving: newValue })
},
})
export const croperState = atom<Rect>({
key: 'croperState',
default: {