add inbrowser
This commit is contained in:
parent
f52dbc1091
commit
45d29a4249
@ -1,3 +1,5 @@
|
|||||||
|
import webbrowser
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
|
|
||||||
@ -97,6 +99,7 @@ def run(
|
|||||||
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),
|
||||||
|
inbrowser: bool = Option(False, help=INBROWSER_HELP),
|
||||||
model: str = Option(
|
model: str = Option(
|
||||||
DEFAULT_MODEL,
|
DEFAULT_MODEL,
|
||||||
help=f"Erase models: [{', '.join(AVAILABLE_MODELS)}].\n"
|
help=f"Erase models: [{', '.join(AVAILABLE_MODELS)}].\n"
|
||||||
@ -165,10 +168,18 @@ def start(
|
|||||||
from iopaint.api import Api
|
from iopaint.api import Api
|
||||||
from iopaint.schema import ApiConfig
|
from iopaint.schema import ApiConfig
|
||||||
|
|
||||||
app = FastAPI()
|
@asynccontextmanager
|
||||||
|
async def lifespan(app: FastAPI):
|
||||||
|
if inbrowser:
|
||||||
|
webbrowser.open(f"http://localhost:{port}", new=0, autoraise=True)
|
||||||
|
yield
|
||||||
|
|
||||||
|
app = FastAPI(lifespan=lifespan)
|
||||||
|
|
||||||
api_config = ApiConfig(
|
api_config = ApiConfig(
|
||||||
host=host,
|
host=host,
|
||||||
port=port,
|
port=port,
|
||||||
|
inbrowser=inbrowser,
|
||||||
model=model,
|
model=model,
|
||||||
no_half=no_half,
|
no_half=no_half,
|
||||||
low_mem=low_mem,
|
low_mem=low_mem,
|
||||||
|
@ -116,3 +116,5 @@ REALESRGAN_HELP = "Enable realesrgan super resolution"
|
|||||||
GFPGAN_HELP = "Enable GFPGAN face restore. To also enhance background, use with --enable-realesrgan"
|
GFPGAN_HELP = "Enable GFPGAN face restore. To also enhance background, use with --enable-realesrgan"
|
||||||
RESTOREFORMER_HELP = "Enable RestoreFormer face restore. To also enhance background, use with --enable-realesrgan"
|
RESTOREFORMER_HELP = "Enable RestoreFormer face restore. To also enhance background, use with --enable-realesrgan"
|
||||||
GIF_HELP = "Enable GIF plugin. Make GIF to compare original and cleaned image"
|
GIF_HELP = "Enable GIF plugin. Make GIF to compare original and cleaned image"
|
||||||
|
|
||||||
|
INBROWSER_HELP = "Automatically launch IOPaint in a new tab on the default browser"
|
||||||
|
@ -216,6 +216,7 @@ class PowerPaintTask(str, Enum):
|
|||||||
class ApiConfig(BaseModel):
|
class ApiConfig(BaseModel):
|
||||||
host: str
|
host: str
|
||||||
port: int
|
port: int
|
||||||
|
inbrowser: bool
|
||||||
model: str
|
model: str
|
||||||
no_half: bool
|
no_half: bool
|
||||||
low_mem: bool
|
low_mem: bool
|
||||||
|
@ -28,6 +28,7 @@ _config_file: Path = None
|
|||||||
default_configs = dict(
|
default_configs = dict(
|
||||||
host="127.0.0.1",
|
host="127.0.0.1",
|
||||||
port=8080,
|
port=8080,
|
||||||
|
inbrowser=True,
|
||||||
model=DEFAULT_MODEL,
|
model=DEFAULT_MODEL,
|
||||||
model_dir=DEFAULT_MODEL_DIR,
|
model_dir=DEFAULT_MODEL_DIR,
|
||||||
no_half=False,
|
no_half=False,
|
||||||
@ -100,6 +101,7 @@ def save_config(
|
|||||||
gfpgan_device,
|
gfpgan_device,
|
||||||
enable_restoreformer,
|
enable_restoreformer,
|
||||||
restoreformer_device,
|
restoreformer_device,
|
||||||
|
inbrowser,
|
||||||
):
|
):
|
||||||
config = WebConfig(**locals())
|
config = WebConfig(**locals())
|
||||||
if str(config.input) == ".":
|
if str(config.input) == ".":
|
||||||
@ -146,6 +148,7 @@ def main(config_file: Path):
|
|||||||
with gr.Row():
|
with gr.Row():
|
||||||
host = gr.Textbox(init_config.host, label="Host")
|
host = gr.Textbox(init_config.host, label="Host")
|
||||||
port = gr.Number(init_config.port, label="Port", precision=0)
|
port = gr.Number(init_config.port, label="Port", precision=0)
|
||||||
|
inbrowser = gr.Checkbox(init_config.inbrowser, label=INBROWSER_HELP)
|
||||||
|
|
||||||
with gr.Column():
|
with gr.Column():
|
||||||
model = gr.Textbox(
|
model = gr.Textbox(
|
||||||
@ -297,6 +300,7 @@ def main(config_file: Path):
|
|||||||
gfpgan_device,
|
gfpgan_device,
|
||||||
enable_restoreformer,
|
enable_restoreformer,
|
||||||
restoreformer_device,
|
restoreformer_device,
|
||||||
|
inbrowser,
|
||||||
],
|
],
|
||||||
message,
|
message,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user