~/Projects/stable-diffusion-webui
git clone https://code.lsong.org/stable-diffusion-webui
Commit
- Commit
- 902f8cf292582301856ff018a3af34ea546a5393
- Author
- AUTOMATIC1111 <[email protected]>
- Date
- 2023-08-08 06:44:49 +0300 +0300
- Diffstat
modules/shared.py | 1 + webui.py | 15 +++++++++++----
Merge pull request #12254 from AUTOMATIC1111/auro-autolaunch Automatically open webui in browser when running "locally"
diff --git a/modules/shared.py b/modules/shared.py index 4d8549280257674e0978596d58f3d1329d703899..97f1eab522a059bb6a53843da9f53ba7abc9720b 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -422,6 +422,7 @@ "face_restoration_unload": OptionInfo(False, "Move face restoration model from VRAM into RAM after processing"), })) 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.").needs_reload_ui(), "show_gradio_deprecation_warnings": OptionInfo(True, "Show gradio deprecation warnings in console.").needs_reload_ui(), "memmon_poll_rate": OptionInfo(8, "VRAM usage polls per second during generation.", gr.Slider, {"minimum": 0, "maximum": 40, "step": 1}).info("0 = disable"), diff --git a/webui.py b/webui.py index 86a62a920aeff944ad7a31c09637e5f754a7f2a5..6d36f8806af477b040aafc75da7906a691794e0f 100644 --- a/webui.py +++ b/webui.py @@ -372,6 +372,13 @@ shared.demo.queue(64) 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, @@ -381,7 +388,7 @@ ssl_certfile=cmd_opts.tls_certfile, 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={ @@ -390,9 +397,6 @@ "redoc_url": "/redoc", }, 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") @@ -437,6 +441,9 @@ print("Stopping server...") # If we catch a keyboard interrupt, we want to stop the server and exit. 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()