From cc06f30e9aeb93b854f1b8249b2664901607c6d7 Mon Sep 17 00:00:00 2001 From: Qing Date: Fri, 5 Jan 2024 15:38:34 +0800 Subject: [PATCH] beta1 --- iopaint/batch_processing.py | 1 + iopaint/cli.py | 45 ++++++++++++++++++++++++++++--------- iopaint/download.py | 4 +--- iopaint/runtime.py | 1 + requirements.txt | 3 +-- setup.py | 6 ++--- 6 files changed, 41 insertions(+), 19 deletions(-) diff --git a/iopaint/batch_processing.py b/iopaint/batch_processing.py index a32ea48..2f8e082 100644 --- a/iopaint/batch_processing.py +++ b/iopaint/batch_processing.py @@ -48,6 +48,7 @@ def batch_inpaint( f"invalid --output: when image is a directory, output should be a directory" ) exit(-1) + output.mkdir(parents=True, exist_ok=True) image_paths = glob_images(image) mask_paths = glob_images(mask) diff --git a/iopaint/cli.py b/iopaint/cli.py index 6804bf0..be505b3 100644 --- a/iopaint/cli.py +++ b/iopaint/cli.py @@ -7,7 +7,6 @@ from loguru import logger from typer import Option from iopaint.const import * -from iopaint.download import cli_download_model, scan_models from iopaint.runtime import setup_model_dir, dump_environment_info, check_device typer_app = typer.Typer(pretty_exceptions_show_locals=False, add_completion=False) @@ -25,16 +24,29 @@ def download( model: str = Option( ..., help="Model id on HuggingFace e.g: runwayml/stable-diffusion-inpainting" ), - model_dir: Path = Option(DEFAULT_MODEL_DIR, help=MODEL_DIR_HELP, file_okay=False), + model_dir: Path = Option( + DEFAULT_MODEL_DIR, + help=MODEL_DIR_HELP, + file_okay=False, + callback=setup_model_dir, + ), ): - cli_download_model(model, model_dir) + from iopaint.download import cli_download_model + + cli_download_model(model) @typer_app.command(name="list", help="List downloaded models") def list_model( - model_dir: Path = Option(DEFAULT_MODEL_DIR, help=MODEL_DIR_HELP, file_okay=False), + model_dir: Path = Option( + DEFAULT_MODEL_DIR, + help=MODEL_DIR_HELP, + file_okay=False, + callback=setup_model_dir, + ), ): - setup_model_dir(model_dir) + from iopaint.download import scan_models + scanned_models = scan_models() for it in scanned_models: print(it.name) @@ -59,13 +71,19 @@ def run( concat: bool = Option( False, help="Concat original image, mask and output images into one image" ), - model_dir: Path = Option(DEFAULT_MODEL_DIR, help=MODEL_DIR_HELP, file_okay=False), + model_dir: Path = Option( + DEFAULT_MODEL_DIR, + help=MODEL_DIR_HELP, + file_okay=False, + callback=setup_model_dir, + ), ): - setup_model_dir(model_dir) + from iopaint.download import cli_download_model, scan_models + scanned_models = scan_models() if model not in [it.name for it in scanned_models]: logger.info(f"{model} not found in {model_dir}, try to downloading") - cli_download_model(model, model_dir) + cli_download_model(model) from iopaint.batch_processing import batch_inpaint @@ -82,7 +100,11 @@ def start( f"You can use download command to download other SD/SDXL normal/inpainting models on huggingface", ), model_dir: Path = Option( - DEFAULT_MODEL_DIR, help=MODEL_DIR_HELP, dir_okay=True, file_okay=False + DEFAULT_MODEL_DIR, + help=MODEL_DIR_HELP, + dir_okay=True, + file_okay=False, + callback=setup_model_dir, ), no_half: bool = Option(False, help=NO_HALF_HELP), cpu_offload: bool = Option(False, help=CPU_OFFLOAD_HELP), @@ -125,16 +147,17 @@ def start( output_dir.mkdir(parents=True) model_dir = model_dir.expanduser().absolute() - setup_model_dir(model_dir) if local_files_only: os.environ["TRANSFORMERS_OFFLINE"] = "1" os.environ["HF_HUB_OFFLINE"] = "1" + from iopaint.download import cli_download_model, scan_models + scanned_models = scan_models() if model not in [it.name for it in scanned_models]: logger.info(f"{model} not found in {model_dir}, try to downloading") - cli_download_model(model, model_dir) + cli_download_model(model) from iopaint.api import Api from iopaint.schema import ApiConfig diff --git a/iopaint/download.py b/iopaint/download.py index 654a1ff..8afb44e 100644 --- a/iopaint/download.py +++ b/iopaint/download.py @@ -15,11 +15,9 @@ from iopaint.const import ( ) from iopaint.model.utils import handle_from_pretrained_exceptions from iopaint.model_info import ModelInfo, ModelType -from iopaint.runtime import setup_model_dir -def cli_download_model(model: str, model_dir: Path): - setup_model_dir(model_dir) +def cli_download_model(model: str): from iopaint.model import models if model in models and models[model].is_erase_model: diff --git a/iopaint/runtime.py b/iopaint/runtime.py index 268678b..950716f 100644 --- a/iopaint/runtime.py +++ b/iopaint/runtime.py @@ -84,3 +84,4 @@ def setup_model_dir(model_dir: Path): if not model_dir.exists(): logger.info(f"Create model directory: {model_dir}") model_dir.mkdir(exist_ok=True, parents=True) + return model_dir diff --git a/requirements.txt b/requirements.txt index 54907f3..649af09 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ torch>=2.0.0 opencv-python diffusers==0.25.0 -transformers==4.34.1 +transformers>=4.35.1 safetensors controlnet-aux==0.0.3 fastapi==0.108.0 @@ -11,6 +11,5 @@ pydantic rich loguru yacs -gradio piexif==1.1.3 omegaconf \ No newline at end of file diff --git a/setup.py b/setup.py index fc79fb2..727d953 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,8 @@ import setuptools from pathlib import Path -web_files = Path("iopaint/app/build/").glob("**/*") -web_files = [str(it).replace("lama_cleaner/", "") for it in web_files] +web_files = Path("iopaint/web_app").glob("**/*") +web_files = [str(it).replace("iopaint/", "") for it in web_files] with open("README.md", "r", encoding="utf-8") as fh: long_description = fh.read() @@ -21,7 +21,7 @@ def load_requirements(): # https://setuptools.readthedocs.io/en/latest/setuptools.html#including-data-files setuptools.setup( name="IOPaint", - version="1.0.0", + version="1.0.0-beta.1", author="PanicByte", author_email="cwq1913@gmail.com", description="Image inpainting, outpainting tool powered by SOTA AI Model",