This commit is contained in:
Qing 2024-01-03 09:03:04 +08:00
parent aca85543ca
commit 9df94489e1
7 changed files with 26 additions and 17 deletions

View File

@ -1,3 +1,4 @@
import asyncio
import os
import threading
import time
@ -6,22 +7,21 @@ from pathlib import Path
from typing import Optional, Dict, List
import cv2
import socketio
import asyncio
from socketio import AsyncServer
import torch
import numpy as np
from loguru import logger
from PIL import Image
import socketio
import torch
import uvicorn
from PIL import Image
from fastapi import APIRouter, FastAPI, Request, UploadFile
from fastapi.encoders import jsonable_encoder
from fastapi.exceptions import HTTPException
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse, FileResponse, Response
from fastapi.staticfiles import StaticFiles
from loguru import logger
from socketio import AsyncServer
from lama_cleaner.file_manager import FileManager
from lama_cleaner.helper import (
load_img,
decode_base64_to_image,
@ -33,7 +33,7 @@ from lama_cleaner.helper import (
from lama_cleaner.model.utils import torch_gc
from lama_cleaner.model_info import ModelInfo
from lama_cleaner.model_manager import ModelManager
from lama_cleaner.plugins import build_plugins, InteractiveSeg, RemoveBG, AnimeSeg
from lama_cleaner.plugins import build_plugins
from lama_cleaner.plugins.base_plugin import BasePlugin
from lama_cleaner.schema import (
GenInfoResponse,
@ -45,7 +45,6 @@ from lama_cleaner.schema import (
SDSampler,
PluginInfo,
)
from lama_cleaner.file_manager import FileManager
CURRENT_DIR = Path(__file__).parent.absolute().resolve()
WEB_APP_DIR = CURRENT_DIR / "web_app"
@ -118,7 +117,7 @@ def api_middleware(app: FastAPI):
global_sio: AsyncServer = None
def diffuser_callback(pipe, step: int, timestep: int, callback_kwargs: Dict):
def diffuser_callback(pipe, step: int, timestep: int, callback_kwargs: Dict = {}):
# self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict
# logger.info(f"diffusion callback: step={step}, timestep={timestep}")

View File

@ -1193,7 +1193,7 @@ class StableDiffusionInpaintPipeline(
):
progress_bar.update()
if callback is not None and i % callback_steps == 0:
callback(i, t, latents)
callback(self, i, t, {})
if not output_type == "latent":
condition_kwargs = {}

View File

@ -66,6 +66,7 @@ const Cropper = (props: Props) => {
imageWidth,
imageHeight,
isInpainting,
isSD,
{ x, y, width, height },
setX,
setY,
@ -77,6 +78,7 @@ const Cropper = (props: Props) => {
state.imageWidth,
state.imageHeight,
state.isInpainting,
state.isSD(),
state.cropperState,
state.setCropperX,
state.setCropperY,
@ -377,7 +379,7 @@ const Cropper = (props: Props) => {
)
}
if (show === false) {
if (show === false || !isSD) {
return null
}

View File

@ -2,7 +2,6 @@ import * as React from "react"
import io from "socket.io-client"
import { Progress } from "./ui/progress"
import { useStore } from "@/lib/states"
import { MODEL_TYPE_INPAINT } from "@/lib/const"
export const API_ENDPOINT = import.meta.env.VITE_BACKEND
? import.meta.env.VITE_BACKEND
@ -10,16 +9,16 @@ export const API_ENDPOINT = import.meta.env.VITE_BACKEND
const socket = io(API_ENDPOINT)
const DiffusionProgress = () => {
const [settings, isInpainting] = useStore((state) => [
const [settings, isInpainting, isSD] = useStore((state) => [
state.settings,
state.isInpainting,
state.isSD(),
])
const [isConnected, setIsConnected] = React.useState(false)
const [step, setStep] = React.useState(0)
const progress = Math.min(Math.round((step / settings.sdSteps) * 100), 100)
const isSD = settings.model.model_type !== MODEL_TYPE_INPAINT
React.useEffect(() => {
if (!isSD) {

View File

@ -604,7 +604,7 @@ export default function Editor(props: EditorProps) {
)
useHotKey(
"ctrl+c, cmd+c",
"ctrl+c,meta+c",
async () => {
const hasPermission = await askWritePermission()
if (hasPermission && renders.length > 0) {

View File

@ -48,6 +48,7 @@ const Extender = (props: Props) => {
isInpainting,
imageHeight,
imageWdith,
isSD,
{ x, y, width, height },
setX,
setY,
@ -60,6 +61,7 @@ const Extender = (props: Props) => {
state.isInpainting,
state.imageHeight,
state.imageWidth,
state.isSD(),
state.extenderState,
state.setExtenderX,
state.setExtenderY,
@ -391,7 +393,7 @@ const Extender = (props: Props) => {
)
}
if (show === false) {
if (show === false || !isSD) {
return null
}

View File

@ -161,6 +161,8 @@ type AppAction = {
getBrushSize: () => number
setImageSize: (width: number, height: number) => void
isSD: () => boolean
setCropperX: (newValue: number) => void
setCropperY: (newValue: number) => void
setCropperWidth: (newValue: number) => void
@ -170,6 +172,7 @@ type AppAction = {
setExtenderY: (newValue: number) => void
setExtenderWidth: (newValue: number) => void
setExtenderHeight: (newValue: number) => void
setIsCropperExtenderResizing: (newValue: boolean) => void
updateExtenderDirection: (newValue: ExtenderDirection) => void
resetExtender: (width: number, height: number) => void
@ -618,6 +621,10 @@ export const useStore = createWithEqualityFn<AppState & AppAction>()(
return get().isInpainting || get().isPluginRunning
},
isSD: (): boolean => {
return get().settings.model.model_type !== MODEL_TYPE_INPAINT
},
// undo/redo
undoDisabled: (): boolean => {