aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw-e-w <40751091+w-e-w@users.noreply.github.com>2023-08-08 11:22:35 +0900
committerw-e-w <40751091+w-e-w@users.noreply.github.com>2023-08-08 11:29:33 +0900
commitc75bda867be5345bf959daf23bdc19eadc90841a (patch)
tree1b4498d21c6141493639ae14bb0f05aca65d808f
parent6a0d498c8ec5287a75e2a3bc8a4fa79e82e64c18 (diff)
setting: Automatically open webui in browser on startup
-rw-r--r--modules/shared.py1
-rw-r--r--webui.py15
2 files changed, 12 insertions, 4 deletions
diff --git a/modules/shared.py b/modules/shared.py
index aa72c9c8..5a7be85b 100644
--- a/modules/shared.py
+++ b/modules/shared.py
@@ -385,6 +385,7 @@ options_templates.update(options_section(('face-restoration', "Face restoration"
}))
options_templates.update(options_section(('system', "System"), {
+ "auto_launch_browser": OptionInfo("Local", "Automatically open webui in browser on startup", gr.Radio, lambda: {"choices": ["Disable", "Local", "Remote"]}),
"show_warnings": OptionInfo(False, "Show warnings in console."),
"memmon_poll_rate": OptionInfo(8, "VRAM usage polls per second during generation.", gr.Slider, {"minimum": 0, "maximum": 40, "step": 1}).info("0 = disable"),
"samples_log_stdout": OptionInfo(False, "Always print all generation info to standard output"),
diff --git a/webui.py b/webui.py
index 2dc4f1aa..844e2548 100644
--- a/webui.py
+++ b/webui.py
@@ -398,6 +398,13 @@ def webui():
gradio_auth_creds = list(get_gradio_auth_creds()) or None
+ auto_launch_browser = False
+ if os.getenv('SD_WEBUI_RESTARTING') != '1':
+ if shared.opts.auto_launch_browser == "Remote" or cmd_opts.autolaunch:
+ auto_launch_browser = True
+ elif shared.opts.auto_launch_browser == "Local":
+ auto_launch_browser = not any([cmd_opts.listen, cmd_opts.share, cmd_opts.ngrok])
+
app, local_url, share_url = shared.demo.launch(
share=cmd_opts.share,
server_name=server_name,
@@ -407,7 +414,7 @@ def webui():
ssl_verify=cmd_opts.disable_tls_verify,
debug=cmd_opts.gradio_debug,
auth=gradio_auth_creds,
- inbrowser=cmd_opts.autolaunch and os.getenv('SD_WEBUI_RESTARTING') != '1',
+ inbrowser=auto_launch_browser,
prevent_thread_lock=True,
allowed_paths=cmd_opts.gradio_allowed_path,
app_kwargs={
@@ -417,9 +424,6 @@ def webui():
root_path=f"/{cmd_opts.subpath}" if cmd_opts.subpath else "",
)
- # after initial launch, disable --autolaunch for subsequent restarts
- cmd_opts.autolaunch = False
-
startup_timer.record("gradio launch")
# gradio uses a very open CORS policy via app.user_middleware, which makes it possible for
@@ -464,6 +468,9 @@ def webui():
shared.demo.close()
break
+ # disable auto launch webui in browser for subsequent UI Reload
+ os.environ.setdefault('SD_WEBUI_RESTARTING', '1')
+
print('Restarting UI...')
shared.demo.close()
time.sleep(0.5)