From 9df94489e17d6bc05789b69bcb6c108efc404ea2 Mon Sep 17 00:00:00 2001 From: Qing Date: Wed, 3 Jan 2024 09:03:04 +0800 Subject: [PATCH] update --- lama_cleaner/api.py | 19 +++++++++---------- .../model/power_paint/pipeline_powerpaint.py | 2 +- web_app/src/components/Cropper.tsx | 4 +++- web_app/src/components/DiffusionProgress.tsx | 5 ++--- web_app/src/components/Editor.tsx | 2 +- web_app/src/components/Extender.tsx | 4 +++- web_app/src/lib/states.ts | 7 +++++++ 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/lama_cleaner/api.py b/lama_cleaner/api.py index a559326..434926c 100644 --- a/lama_cleaner/api.py +++ b/lama_cleaner/api.py @@ -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}") diff --git a/lama_cleaner/model/power_paint/pipeline_powerpaint.py b/lama_cleaner/model/power_paint/pipeline_powerpaint.py index 9b7f8c5..13c1d27 100644 --- a/lama_cleaner/model/power_paint/pipeline_powerpaint.py +++ b/lama_cleaner/model/power_paint/pipeline_powerpaint.py @@ -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 = {} diff --git a/web_app/src/components/Cropper.tsx b/web_app/src/components/Cropper.tsx index b80c81b..94f5c96 100644 --- a/web_app/src/components/Cropper.tsx +++ b/web_app/src/components/Cropper.tsx @@ -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 } diff --git a/web_app/src/components/DiffusionProgress.tsx b/web_app/src/components/DiffusionProgress.tsx index 9828c56..3585146 100644 --- a/web_app/src/components/DiffusionProgress.tsx +++ b/web_app/src/components/DiffusionProgress.tsx @@ -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) { diff --git a/web_app/src/components/Editor.tsx b/web_app/src/components/Editor.tsx index 0767d82..d8e2709 100644 --- a/web_app/src/components/Editor.tsx +++ b/web_app/src/components/Editor.tsx @@ -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) { diff --git a/web_app/src/components/Extender.tsx b/web_app/src/components/Extender.tsx index a2d5cf9..409a855 100644 --- a/web_app/src/components/Extender.tsx +++ b/web_app/src/components/Extender.tsx @@ -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 } diff --git a/web_app/src/lib/states.ts b/web_app/src/lib/states.ts index 7814962..cf0bcb0 100644 --- a/web_app/src/lib/states.ts +++ b/web_app/src/lib/states.ts @@ -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()( return get().isInpainting || get().isPluginRunning }, + isSD: (): boolean => { + return get().settings.model.model_type !== MODEL_TYPE_INPAINT + }, + // undo/redo undoDisabled: (): boolean => {