From 3662a274e2b6482c4ad831cc2d7976d919b40212 Mon Sep 17 00:00:00 2001 From: rucadi Date: Fri, 16 Dec 2022 17:10:13 +0100 Subject: Add polling callback --- webui.py | 1 + 1 file changed, 1 insertion(+) (limited to 'webui.py') diff --git a/webui.py b/webui.py index 5b5c2139..6c2b511c 100644 --- a/webui.py +++ b/webui.py @@ -171,6 +171,7 @@ def create_api(app): def wait_on_server(demo=None): while 1: time.sleep(0.5) + modules.script_callbacks.app_polling_callback(None, demo) if shared.state.need_restart: shared.state.need_restart = False time.sleep(0.5) -- cgit v1.2.1 From eb5eb8aa117c3d9ff9c55c59bc589ad8e983919e Mon Sep 17 00:00:00 2001 From: rucadi Date: Fri, 16 Dec 2022 18:31:20 +0100 Subject: Add a callback called before reloading the server --- webui.py | 1 + 1 file changed, 1 insertion(+) (limited to 'webui.py') diff --git a/webui.py b/webui.py index 6c2b511c..ddccf870 100644 --- a/webui.py +++ b/webui.py @@ -173,6 +173,7 @@ def wait_on_server(demo=None): time.sleep(0.5) modules.script_callbacks.app_polling_callback(None, demo) if shared.state.need_restart: + modules.script_callbacks.app_reload_callback(None, demo) shared.state.need_restart = False time.sleep(0.5) demo.close() -- cgit v1.2.1 From c9647c8d23efa8c939c6af39878784e246082122 Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Sat, 25 Mar 2023 16:11:41 -0400 Subject: Support Gradio's theme API --- webui.py | 1 + 1 file changed, 1 insertion(+) (limited to 'webui.py') diff --git a/webui.py b/webui.py index 30f3e4a1..6986e576 100644 --- a/webui.py +++ b/webui.py @@ -150,6 +150,7 @@ def initialize(): shared.opts.onchange("sd_vae", wrap_queued_call(lambda: modules.sd_vae.reload_vae_weights()), call=False) shared.opts.onchange("sd_vae_as_default", wrap_queued_call(lambda: modules.sd_vae.reload_vae_weights()), call=False) shared.opts.onchange("temp_dir", ui_tempdir.on_tmpdir_changed) + shared.opts.onchange("gradio_theme", shared.reload_gradio_theme) startup_timer.record("opts onchange") shared.reload_hypernetworks() -- cgit v1.2.1 From ad5afcaae0b47e9e68b49aacf04cc3ad59d41a8e Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Wed, 29 Mar 2023 16:46:03 -0500 Subject: Save/restore working webui/extension configs --- webui.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'webui.py') diff --git a/webui.py b/webui.py index b570895f..b8f9a2c1 100644 --- a/webui.py +++ b/webui.py @@ -5,6 +5,7 @@ import importlib import signal import re import warnings +import json from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.gzip import GZipMiddleware @@ -37,7 +38,7 @@ if ".dev" in torch.__version__ or "+git" in torch.__version__: torch.__long_version__ = torch.__version__ torch.__version__ = re.search(r'[\d.]+[\d]', torch.__version__).group(0) -from modules import shared, devices, sd_samplers, upscaler, extensions, localization, ui_tempdir, ui_extra_networks +from modules import shared, devices, sd_samplers, upscaler, extensions, localization, ui_tempdir, ui_extra_networks, config_states import modules.codeformer_model as codeformer import modules.face_restoration import modules.gfpgan_model as gfpgan @@ -105,6 +106,17 @@ def initialize(): localization.list_localizations(cmd_opts.localizations_dir) startup_timer.record("list extensions") + config_state_file = shared.opts.restore_config_state_file + shared.opts.restore_config_state_file = "" + shared.opts.save(shared.config_filename) + + if os.path.isfile(config_state_file): + print(f"*** About to restore extension state from file: {config_state_file}") + with open(config_state_file, "r", encoding="utf-8") as f: + config_state = json.load(f) + config_states.restore_extension_state(config_state) + startup_timer.record("restore extension config") + if cmd_opts.ui_debug_mode: shared.sd_upscalers = upscaler.UpscalerLanczos().scalers modules.scripts.load_scripts() @@ -301,6 +313,17 @@ def webui(): extensions.list_extensions() startup_timer.record("list extensions") + config_state_file = shared.opts.restore_config_state_file + shared.opts.restore_config_state_file = "" + shared.opts.save(shared.config_filename) + + if os.path.isfile(config_state_file): + print(f"*** About to restore extension state from file: {config_state_file}") + with open(config_state_file, "r", encoding="utf-8") as f: + config_state = json.load(f) + config_states.restore_extension_state(config_state) + startup_timer.record("restore extension config") + localization.list_localizations(cmd_opts.localizations_dir) modelloader.forbid_loaded_nonbuiltin_upscalers() -- cgit v1.2.1 From f3320b802c12f29e5a3201fcc0abfe72be294293 Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Wed, 29 Mar 2023 18:32:54 -0500 Subject: Various UI fixes in config state tab --- webui.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'webui.py') diff --git a/webui.py b/webui.py index b8f9a2c1..5ce45056 100644 --- a/webui.py +++ b/webui.py @@ -114,8 +114,10 @@ def initialize(): print(f"*** About to restore extension state from file: {config_state_file}") with open(config_state_file, "r", encoding="utf-8") as f: config_state = json.load(f) - config_states.restore_extension_state(config_state) + config_states.restore_extension_config(config_state) startup_timer.record("restore extension config") + else: + print(f"!!! Config state backup not found: {config_state_file}") if cmd_opts.ui_debug_mode: shared.sd_upscalers = upscaler.UpscalerLanczos().scalers @@ -321,8 +323,10 @@ def webui(): print(f"*** About to restore extension state from file: {config_state_file}") with open(config_state_file, "r", encoding="utf-8") as f: config_state = json.load(f) - config_states.restore_extension_state(config_state) + config_states.restore_extension_config(config_state) startup_timer.record("restore extension config") + else: + print(f"!!! Config state backup not found: {config_state_file}") localization.list_localizations(cmd_opts.localizations_dir) -- cgit v1.2.1 From 563d048780790fb9e7e9a5fc54a86bdf1ee65d58 Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Wed, 29 Mar 2023 19:22:45 -0500 Subject: Squelch warning if no config restore --- webui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webui.py') diff --git a/webui.py b/webui.py index 5ce45056..ee5e4f11 100644 --- a/webui.py +++ b/webui.py @@ -116,7 +116,7 @@ def initialize(): config_state = json.load(f) config_states.restore_extension_config(config_state) startup_timer.record("restore extension config") - else: + elif config_state_file: print(f"!!! Config state backup not found: {config_state_file}") if cmd_opts.ui_debug_mode: @@ -325,7 +325,7 @@ def webui(): config_state = json.load(f) config_states.restore_extension_config(config_state) startup_timer.record("restore extension config") - else: + elif config_state_file: print(f"!!! Config state backup not found: {config_state_file}") localization.list_localizations(cmd_opts.localizations_dir) -- cgit v1.2.1 From d5063e07e8b4737621978feffd37b18077b9ea64 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Thu, 30 Mar 2023 10:57:54 -0400 Subject: update torch --- webui.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'webui.py') diff --git a/webui.py b/webui.py index b570895f..54552cdd 100644 --- a/webui.py +++ b/webui.py @@ -20,6 +20,8 @@ startup_timer = timer.Timer() import torch import pytorch_lightning # pytorch_lightning should be imported after torch, but it re-enables warnings on import so import once to disable them warnings.filterwarnings(action="ignore", category=DeprecationWarning, module="pytorch_lightning") +warnings.filterwarnings(action="ignore", category=UserWarning, module="torchvision") + startup_timer.record("import torch") import gradio -- cgit v1.2.1 From aef42bfec09a9ca93d1222b7b47256f37e192a32 Mon Sep 17 00:00:00 2001 From: keith <1868690+wk5ovc@users.noreply.github.com> Date: Mon, 3 Apr 2023 17:05:49 +0800 Subject: Fix #9046 /sdapi/v1/txt2img endpoint not working **Describe what this pull request is trying to achieve.** Fix https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/9046 **Environment this was tested in** * OS: Linux * Browser: chrome * Graphics card: RTX 3090 --- webui.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'webui.py') diff --git a/webui.py b/webui.py index b570895f..8927aa33 100644 --- a/webui.py +++ b/webui.py @@ -5,6 +5,7 @@ import importlib import signal import re import warnings +import asyncio from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.gzip import GZipMiddleware @@ -66,6 +67,46 @@ if cmd_opts.server_name: else: server_name = "0.0.0.0" if cmd_opts.listen else None +if sys.platform == "win32" and hasattr(asyncio, "WindowsSelectorEventLoopPolicy"): + # "Any thread" and "selector" should be orthogonal, but there's not a clean + # interface for composing policies so pick the right base. + _BasePolicy = asyncio.WindowsSelectorEventLoopPolicy # type: ignore +else: + _BasePolicy = asyncio.DefaultEventLoopPolicy + + +class AnyThreadEventLoopPolicy(_BasePolicy): # type: ignore + """Event loop policy that allows loop creation on any thread. + + The default `asyncio` event loop policy only automatically creates + event loops in the main threads. Other threads must create event + loops explicitly or `asyncio.get_event_loop` (and therefore + `.IOLoop.current`) will fail. Installing this policy allows event + loops to be created automatically on any thread, matching the + behavior of Tornado versions prior to 5.0 (or 5.0 on Python 2). + + Usage:: + + asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy()) + + .. versionadded:: 5.0 + + """ + + def get_event_loop(self) -> asyncio.AbstractEventLoop: + try: + return super().get_event_loop() + except (RuntimeError, AssertionError): + # This was an AssertionError in python 3.4.2 (which ships with debian jessie) + # and changed to a RuntimeError in 3.4.3. + # "There is no current event loop in thread %r" + loop = self.new_event_loop() + self.set_event_loop(loop) + return loop + + +asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy()) + def check_versions(): if shared.cmd_opts.skip_version_check: -- cgit v1.2.1 From 7ea5be3e29dd79e2a7669e0b02f8ce66354c5416 Mon Sep 17 00:00:00 2001 From: aniaan Date: Wed, 26 Apr 2023 20:59:55 +0800 Subject: perf(webui): Remove duplicate code --- webui.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'webui.py') diff --git a/webui.py b/webui.py index b570895f..bde4025b 100644 --- a/webui.py +++ b/webui.py @@ -126,9 +126,6 @@ def initialize(): modules.scripts.load_scripts() startup_timer.record("load scripts") - modelloader.load_upscalers() - startup_timer.record("load upscalers") - modules.sd_vae.refresh_vae_list() startup_timer.record("refresh VAE") -- cgit v1.2.1 From 86bafb625ae2671722abe1f95a4c0fc5e38381e3 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sat, 29 Apr 2023 10:21:01 +0300 Subject: put asyncio fix into a function to make it more obvious where it starts and ends --- webui.py | 67 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 33 deletions(-) (limited to 'webui.py') diff --git a/webui.py b/webui.py index fa8e21ae..0e2a3df0 100644 --- a/webui.py +++ b/webui.py @@ -5,7 +5,6 @@ import importlib import signal import re import warnings -import asyncio from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.gzip import GZipMiddleware @@ -67,45 +66,45 @@ if cmd_opts.server_name: else: server_name = "0.0.0.0" if cmd_opts.listen else None -if sys.platform == "win32" and hasattr(asyncio, "WindowsSelectorEventLoopPolicy"): - # "Any thread" and "selector" should be orthogonal, but there's not a clean - # interface for composing policies so pick the right base. - _BasePolicy = asyncio.WindowsSelectorEventLoopPolicy # type: ignore -else: - _BasePolicy = asyncio.DefaultEventLoopPolicy - - -class AnyThreadEventLoopPolicy(_BasePolicy): # type: ignore - """Event loop policy that allows loop creation on any thread. - The default `asyncio` event loop policy only automatically creates - event loops in the main threads. Other threads must create event - loops explicitly or `asyncio.get_event_loop` (and therefore - `.IOLoop.current`) will fail. Installing this policy allows event - loops to be created automatically on any thread, matching the - behavior of Tornado versions prior to 5.0 (or 5.0 on Python 2). - - Usage:: +def fix_asyncio_event_loop_policy(): + """ + The default `asyncio` event loop policy only automatically creates + event loops in the main threads. Other threads must create event + loops explicitly or `asyncio.get_event_loop` (and therefore + `.IOLoop.current`) will fail. Installing this policy allows event + loops to be created automatically on any thread, matching the + behavior of Tornado versions prior to 5.0 (or 5.0 on Python 2). + """ - asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy()) + import asyncio - .. versionadded:: 5.0 + if sys.platform == "win32" and hasattr(asyncio, "WindowsSelectorEventLoopPolicy"): + # "Any thread" and "selector" should be orthogonal, but there's not a clean + # interface for composing policies so pick the right base. + _BasePolicy = asyncio.WindowsSelectorEventLoopPolicy # type: ignore + else: + _BasePolicy = asyncio.DefaultEventLoopPolicy - """ + class AnyThreadEventLoopPolicy(_BasePolicy): # type: ignore + """Event loop policy that allows loop creation on any thread. + Usage:: - def get_event_loop(self) -> asyncio.AbstractEventLoop: - try: - return super().get_event_loop() - except (RuntimeError, AssertionError): - # This was an AssertionError in python 3.4.2 (which ships with debian jessie) - # and changed to a RuntimeError in 3.4.3. - # "There is no current event loop in thread %r" - loop = self.new_event_loop() - self.set_event_loop(loop) - return loop + asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy()) + """ + def get_event_loop(self) -> asyncio.AbstractEventLoop: + try: + return super().get_event_loop() + except (RuntimeError, AssertionError): + # This was an AssertionError in python 3.4.2 (which ships with debian jessie) + # and changed to a RuntimeError in 3.4.3. + # "There is no current event loop in thread %r" + loop = self.new_event_loop() + self.set_event_loop(loop) + return loop -asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy()) + asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy()) def check_versions(): @@ -140,6 +139,8 @@ Use --skip-version-check commandline argument to disable this check. def initialize(): + fix_asyncio_event_loop_policy() + check_versions() extensions.list_extensions() -- cgit v1.2.1 From ee71eee1818f6f6eba9895c93ba25e0cad27e069 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sat, 29 Apr 2023 12:36:50 +0300 Subject: stuff related to torch version change --- webui.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'webui.py') diff --git a/webui.py b/webui.py index 1f97b475..3fd6e1e9 100644 --- a/webui.py +++ b/webui.py @@ -21,6 +21,8 @@ import torch import pytorch_lightning # pytorch_lightning should be imported after torch, but it re-enables warnings on import so import once to disable them warnings.filterwarnings(action="ignore", category=DeprecationWarning, module="pytorch_lightning") warnings.filterwarnings(action="ignore", category=UserWarning, module="torchvision") +warnings.filterwarnings(action='ignore', category=UserWarning, message='TypedStorage is deprecated') + startup_timer.record("import torch") @@ -113,7 +115,7 @@ def check_versions(): if shared.cmd_opts.skip_version_check: return - expected_torch_version = "1.13.1" + expected_torch_version = "2.0.0" if version.parse(torch.__version__) < version.parse(expected_torch_version): errors.print_error_explanation(f""" @@ -126,7 +128,7 @@ there are reports of issues with training tab on the latest version. Use --skip-version-check commandline argument to disable this check. """.strip()) - expected_xformers_version = "0.0.16rc425" + expected_xformers_version = "0.0.17" if shared.xformers_available: import xformers -- cgit v1.2.1 From aee6d9bb74d9868d0782acc54b6cbefa32422a8f Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sat, 29 Apr 2023 12:39:05 +0300 Subject: remove unneeded warning filter --- webui.py | 1 - 1 file changed, 1 deletion(-) (limited to 'webui.py') diff --git a/webui.py b/webui.py index 3fd6e1e9..759125e0 100644 --- a/webui.py +++ b/webui.py @@ -21,7 +21,6 @@ import torch import pytorch_lightning # pytorch_lightning should be imported after torch, but it re-enables warnings on import so import once to disable them warnings.filterwarnings(action="ignore", category=DeprecationWarning, module="pytorch_lightning") warnings.filterwarnings(action="ignore", category=UserWarning, module="torchvision") -warnings.filterwarnings(action='ignore', category=UserWarning, message='TypedStorage is deprecated') startup_timer.record("import torch") -- cgit v1.2.1 From a95dc02535ce647efbb3bc66964ab61b6f1446f4 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sat, 29 Apr 2023 19:05:43 +0300 Subject: remove unwanted changes from #8789 --- webui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webui.py') diff --git a/webui.py b/webui.py index 98b6d394..a0d5e2cd 100644 --- a/webui.py +++ b/webui.py @@ -264,13 +264,13 @@ def create_api(app): def wait_on_server(demo=None): while 1: time.sleep(0.5) - modules.script_callbacks.app_polling_callback(None, demo) if shared.state.need_restart: - modules.script_callbacks.app_reload_callback(None, demo) shared.state.need_restart = False time.sleep(0.5) demo.close() time.sleep(0.5) + + modules.script_callbacks.app_reload_callback() break -- cgit v1.2.1