This commit is contained in:
Qing 2024-01-05 15:38:34 +08:00
parent a95dd10ceb
commit cc06f30e9a
6 changed files with 41 additions and 19 deletions

View File

@ -48,6 +48,7 @@ def batch_inpaint(
f"invalid --output: when image is a directory, output should be a directory" f"invalid --output: when image is a directory, output should be a directory"
) )
exit(-1) exit(-1)
output.mkdir(parents=True, exist_ok=True)
image_paths = glob_images(image) image_paths = glob_images(image)
mask_paths = glob_images(mask) mask_paths = glob_images(mask)

View File

@ -7,7 +7,6 @@ from loguru import logger
from typer import Option from typer import Option
from iopaint.const import * 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 from iopaint.runtime import setup_model_dir, dump_environment_info, check_device
typer_app = typer.Typer(pretty_exceptions_show_locals=False, add_completion=False) typer_app = typer.Typer(pretty_exceptions_show_locals=False, add_completion=False)
@ -25,16 +24,29 @@ def download(
model: str = Option( model: str = Option(
..., help="Model id on HuggingFace e.g: runwayml/stable-diffusion-inpainting" ..., 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") @typer_app.command(name="list", help="List downloaded models")
def list_model( 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() scanned_models = scan_models()
for it in scanned_models: for it in scanned_models:
print(it.name) print(it.name)
@ -59,13 +71,19 @@ def run(
concat: bool = Option( concat: bool = Option(
False, help="Concat original image, mask and output images into one image" 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() scanned_models = scan_models()
if model not in [it.name for it in scanned_models]: if model not in [it.name for it in scanned_models]:
logger.info(f"{model} not found in {model_dir}, try to downloading") 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 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", f"You can use download command to download other SD/SDXL normal/inpainting models on huggingface",
), ),
model_dir: Path = Option( 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), no_half: bool = Option(False, help=NO_HALF_HELP),
cpu_offload: bool = Option(False, help=CPU_OFFLOAD_HELP), cpu_offload: bool = Option(False, help=CPU_OFFLOAD_HELP),
@ -125,16 +147,17 @@ def start(
output_dir.mkdir(parents=True) output_dir.mkdir(parents=True)
model_dir = model_dir.expanduser().absolute() model_dir = model_dir.expanduser().absolute()
setup_model_dir(model_dir)
if local_files_only: if local_files_only:
os.environ["TRANSFORMERS_OFFLINE"] = "1" os.environ["TRANSFORMERS_OFFLINE"] = "1"
os.environ["HF_HUB_OFFLINE"] = "1" os.environ["HF_HUB_OFFLINE"] = "1"
from iopaint.download import cli_download_model, scan_models
scanned_models = scan_models() scanned_models = scan_models()
if model not in [it.name for it in scanned_models]: if model not in [it.name for it in scanned_models]:
logger.info(f"{model} not found in {model_dir}, try to downloading") 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.api import Api
from iopaint.schema import ApiConfig from iopaint.schema import ApiConfig

View File

@ -15,11 +15,9 @@ from iopaint.const import (
) )
from iopaint.model.utils import handle_from_pretrained_exceptions from iopaint.model.utils import handle_from_pretrained_exceptions
from iopaint.model_info import ModelInfo, ModelType from iopaint.model_info import ModelInfo, ModelType
from iopaint.runtime import setup_model_dir
def cli_download_model(model: str, model_dir: Path): def cli_download_model(model: str):
setup_model_dir(model_dir)
from iopaint.model import models from iopaint.model import models
if model in models and models[model].is_erase_model: if model in models and models[model].is_erase_model:

View File

@ -84,3 +84,4 @@ def setup_model_dir(model_dir: Path):
if not model_dir.exists(): if not model_dir.exists():
logger.info(f"Create model directory: {model_dir}") logger.info(f"Create model directory: {model_dir}")
model_dir.mkdir(exist_ok=True, parents=True) model_dir.mkdir(exist_ok=True, parents=True)
return model_dir

View File

@ -1,7 +1,7 @@
torch>=2.0.0 torch>=2.0.0
opencv-python opencv-python
diffusers==0.25.0 diffusers==0.25.0
transformers==4.34.1 transformers>=4.35.1
safetensors safetensors
controlnet-aux==0.0.3 controlnet-aux==0.0.3
fastapi==0.108.0 fastapi==0.108.0
@ -11,6 +11,5 @@ pydantic
rich rich
loguru loguru
yacs yacs
gradio
piexif==1.1.3 piexif==1.1.3
omegaconf omegaconf

View File

@ -1,8 +1,8 @@
import setuptools import setuptools
from pathlib import Path from pathlib import Path
web_files = Path("iopaint/app/build/").glob("**/*") web_files = Path("iopaint/web_app").glob("**/*")
web_files = [str(it).replace("lama_cleaner/", "") for it in web_files] web_files = [str(it).replace("iopaint/", "") for it in web_files]
with open("README.md", "r", encoding="utf-8") as fh: with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read() long_description = fh.read()
@ -21,7 +21,7 @@ def load_requirements():
# https://setuptools.readthedocs.io/en/latest/setuptools.html#including-data-files # https://setuptools.readthedocs.io/en/latest/setuptools.html#including-data-files
setuptools.setup( setuptools.setup(
name="IOPaint", name="IOPaint",
version="1.0.0", version="1.0.0-beta.1",
author="PanicByte", author="PanicByte",
author_email="cwq1913@gmail.com", author_email="cwq1913@gmail.com",
description="Image inpainting, outpainting tool powered by SOTA AI Model", description="Image inpainting, outpainting tool powered by SOTA AI Model",