fix --input file.jpg

This commit is contained in:
Qing 2024-01-31 22:10:13 +08:00
parent 1d2d39dfa0
commit 44ee0769dd
4 changed files with 35 additions and 31 deletions

View File

@ -5,6 +5,7 @@ import typer
from fastapi import FastAPI from fastapi import FastAPI
from loguru import logger from loguru import logger
from typer import Option from typer import Option
from typer_config import use_json_config
from iopaint.const import * from iopaint.const import *
from iopaint.runtime import setup_model_dir, dump_environment_info, check_device from iopaint.runtime import setup_model_dir, dump_environment_info, check_device
@ -92,6 +93,7 @@ def run(
@typer_app.command(help="Start IOPaint server") @typer_app.command(help="Start IOPaint server")
@use_json_config()
def start( def start(
host: str = Option("127.0.0.1"), host: str = Option("127.0.0.1"),
port: int = Option(8080), port: int = Option(8080),
@ -163,36 +165,35 @@ def start(
from iopaint.schema import ApiConfig from iopaint.schema import ApiConfig
app = FastAPI() app = FastAPI()
api = Api( api_config = ApiConfig(
app, host=host,
ApiConfig( port=port,
host=host, model=model,
port=port, no_half=no_half,
model=model, low_mem=low_mem,
no_half=no_half, cpu_offload=cpu_offload,
low_mem=low_mem, disable_nsfw_checker=disable_nsfw_checker,
cpu_offload=cpu_offload, local_files_only=local_files_only,
disable_nsfw_checker=disable_nsfw_checker, cpu_textencoder=cpu_textencoder if device == Device.cuda else False,
local_files_only=local_files_only, device=device,
cpu_textencoder=cpu_textencoder if device == Device.cuda else False, input=input,
device=device, output_dir=output_dir,
input=input, quality=quality,
output_dir=output_dir, enable_interactive_seg=enable_interactive_seg,
quality=quality, interactive_seg_model=interactive_seg_model,
enable_interactive_seg=enable_interactive_seg, interactive_seg_device=interactive_seg_device,
interactive_seg_model=interactive_seg_model, enable_remove_bg=enable_remove_bg,
interactive_seg_device=interactive_seg_device, enable_anime_seg=enable_anime_seg,
enable_remove_bg=enable_remove_bg, enable_realesrgan=enable_realesrgan,
enable_anime_seg=enable_anime_seg, realesrgan_device=realesrgan_device,
enable_realesrgan=enable_realesrgan, realesrgan_model=realesrgan_model,
realesrgan_device=realesrgan_device, enable_gfpgan=enable_gfpgan,
realesrgan_model=realesrgan_model, gfpgan_device=gfpgan_device,
enable_gfpgan=enable_gfpgan, enable_restoreformer=enable_restoreformer,
gfpgan_device=gfpgan_device, restoreformer_device=restoreformer_device,
enable_restoreformer=enable_restoreformer,
restoreformer_device=restoreformer_device,
),
) )
print(api_config.model_dump_json(indent=4))
api = Api(app, api_config)
api.launch() api.launch()

View File

@ -304,7 +304,9 @@ def get_image_ext(img_bytes):
def decode_base64_to_image( def decode_base64_to_image(
encoding: str, gray=False encoding: str, gray=False
) -> Tuple[np.array, Optional[np.array], Dict]: ) -> Tuple[np.array, Optional[np.array], Dict]:
if encoding.startswith("data:image/"): if encoding.startswith("data:image/") or encoding.startswith(
"data:application/octet-stream;base64,"
):
encoding = encoding.split(";")[1].split(",")[1] encoding = encoding.split(";")[1].split(",")[1]
image = Image.open(io.BytesIO(base64.b64decode(encoding))) image = Image.open(io.BytesIO(base64.b64decode(encoding)))

View File

@ -60,7 +60,7 @@ def save_config(
if str(config.output_dir) == ".": if str(config.output_dir) == ".":
config.output_dir = None config.output_dir = None
print(config) print(config.model_dump_json(indent=4))
if config.input and not os.path.exists(config.input): if config.input and not os.path.exists(config.input):
return "[Error] Input file or directory does not exist" return "[Error] Input file or directory does not exist"

View File

@ -19,5 +19,6 @@ piexif==1.1.3
omegaconf omegaconf
easydict easydict
gradio gradio
typer-config==1.4.0
Pillow==9.5.0 # for AnyText Pillow==9.5.0 # for AnyText