From 49db24ce273ebccb598fc13de946d1ac3cad38f8 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 10:30:29 +0300 Subject: launch.py: Add debugging envvar to see install output --- launch.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index cfc0cffa..136e8855 100644 --- a/launch.py +++ b/launch.py @@ -22,6 +22,9 @@ stored_commit_hash = None stored_git_tag = None dir_repos = "repositories" +# Whether to default to printing command output +default_command_live = (os.environ.get('WEBUI_LAUNCH_LIVE_OUTPUT') == "1") + if 'GRADIO_ANALYTICS_ENABLED' not in os.environ: os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False' @@ -85,7 +88,7 @@ def git_tag(): return stored_git_tag -def run(command, desc=None, errdesc=None, custom_env=None, live=False): +def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_command_live): if desc is not None: print(desc) @@ -135,7 +138,7 @@ def run_python(code, desc=None, errdesc=None): return run(f'"{python}" -c "{code}"', desc, errdesc) -def run_pip(command, desc=None, live=False): +def run_pip(command, desc=None, live=default_command_live): if args.skip_install: return -- cgit v1.2.3 From 875bc270093b4f89b9d0d20a93a5e8ea514b3f6c Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 10:34:19 +0300 Subject: launch.py: Simplify run() --- launch.py | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 136e8855..ae75f6fd 100644 --- a/launch.py +++ b/launch.py @@ -88,32 +88,36 @@ def git_tag(): return stored_git_tag -def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_command_live): +def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_command_live) -> str: if desc is not None: print(desc) - if live: - result = subprocess.run(command, shell=True, env=os.environ if custom_env is None else custom_env) - if result.returncode != 0: - raise RuntimeError(f"""{errdesc or 'Error running command'}. -Command: {command} -Error code: {result.returncode}""") + run_kwargs = { + "args": command, + "shell": True, + "env": os.environ if custom_env is None else custom_env, + "encoding": 'utf8', + "errors": 'ignore', + } - return "" + if not live: + run_kwargs["stdout"] = run_kwargs["stderr"] = subprocess.PIPE - result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env) + result = subprocess.run(**run_kwargs) if result.returncode != 0: - - message = f"""{errdesc or 'Error running command'}. -Command: {command} -Error code: {result.returncode} -stdout: {result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stdout)>0 else ''} -stderr: {result.stderr.decode(encoding="utf8", errors="ignore") if len(result.stderr)>0 else ''} -""" - raise RuntimeError(message) - - return result.stdout.decode(encoding="utf8", errors="ignore") + error_bits = [ + f"{errdesc or 'Error running command'}.", + f"Command: {command}", + f"Error code: {result.returncode}", + ] + if result.stdout: + error_bits.append(f"stdout: {result.stdout}") + if result.stderr: + error_bits.append(f"stderr: {result.stderr}") + raise RuntimeError("\n".join(error_bits)) + + return (result.stdout or "") def check_run(command): -- cgit v1.2.3 From a09e1e6e18e800191817493253dfc481a07b1868 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 10:48:48 +0300 Subject: launch.py: Use GitHub archive URLs for gfpgan, clip, openclip instead of git clones --- launch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index ae75f6fd..fed14d93 100644 --- a/launch.py +++ b/launch.py @@ -248,9 +248,9 @@ def prepare_environment(): requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.17') - gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379") - clip_package = os.environ.get('CLIP_PACKAGE', "git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1") - openclip_package = os.environ.get('OPENCLIP_PACKAGE', "git+https://github.com/mlfoundations/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b") + gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "https://github.com/TencentARC/GFPGAN/archive/8d2447a2d918f8eba5a4a01463fd48e45126a379.zip") + clip_package = os.environ.get('CLIP_PACKAGE', "https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip") + openclip_package = os.environ.get('OPENCLIP_PACKAGE', "https://github.com/mlfoundations/open_clip/archive/bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b.zip") stable_diffusion_repo = os.environ.get('STABLE_DIFFUSION_REPO', "https://github.com/Stability-AI/stablediffusion.git") taming_transformers_repo = os.environ.get('TAMING_TRANSFORMERS_REPO', "https://github.com/CompVis/taming-transformers.git") -- cgit v1.2.3 From dd3ca9adf7077cb7209b31fd16a40deffc4948ca Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 10:35:22 +0300 Subject: launch.py: make torch_index_url an envvar --- launch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index fed14d93..670af87c 100644 --- a/launch.py +++ b/launch.py @@ -244,7 +244,8 @@ def run_extensions_installers(settings_file): def prepare_environment(): - torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url https://download.pytorch.org/whl/cu118") + torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu118") + torch_command = os.environ.get('TORCH_COMMAND', f"pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url {torch_index_url}") requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.17') -- cgit v1.2.3 From 49a55b410b66b7dd9be9335d8a2e3a71e4f8b15c Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 18:28:15 +0300 Subject: Autofix Ruff W (not W605) (mostly whitespace) --- launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 670af87c..62b33f14 100644 --- a/launch.py +++ b/launch.py @@ -327,7 +327,7 @@ def prepare_environment(): if args.update_all_extensions: git_pull_recursive(extensions_dir) - + if "--exit" in sys.argv: print("Exiting because of --exit argument") exit(0) -- cgit v1.2.3 From 681c16dd1e911bdf831b031b0f31aaba41c280f8 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Fri, 12 May 2023 22:33:21 +0900 Subject: fix --data-dir for COMMANDLINE_ARGS move reading of COMMANDLINE_ARGS into paths_internal.py so --data-dir can be properly read --- launch.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 62b33f14..516746ac 100644 --- a/launch.py +++ b/launch.py @@ -3,16 +3,12 @@ import subprocess import os import sys import importlib.util -import shlex import platform import json from modules import cmd_args from modules.paths_internal import script_path, extensions_dir -commandline_args = os.environ.get('COMMANDLINE_ARGS', "") -sys.argv += shlex.split(commandline_args) - args, _ = cmd_args.parser.parse_known_args() python = sys.executable -- cgit v1.2.3 From 55d222a9f4fb51eeb4c0b0fe4e703d45a39ae7a0 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 23:00:53 +0300 Subject: launch.py: make git_tag() and commit_hash() work even when WEBUI_LAUNCH_LIVE_OUTPUT --- launch.py | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 516746ac..ae67fe5c 100644 --- a/launch.py +++ b/launch.py @@ -5,6 +5,7 @@ import sys import importlib.util import platform import json +from functools import lru_cache from modules import cmd_args from modules.paths_internal import script_path, extensions_dir @@ -14,8 +15,6 @@ args, _ = cmd_args.parser.parse_known_args() python = sys.executable git = os.environ.get('GIT', "git") index_url = os.environ.get('INDEX_URL', "") -stored_commit_hash = None -stored_git_tag = None dir_repos = "repositories" # Whether to default to printing command output @@ -56,32 +55,20 @@ Use --skip-python-version-check to suppress this warning. """) +@lru_cache() def commit_hash(): - global stored_commit_hash - - if stored_commit_hash is not None: - return stored_commit_hash - try: - stored_commit_hash = run(f"{git} rev-parse HEAD").strip() + return subprocess.check_output(f"{git} rev-parse HEAD", encoding='utf8').strip() except Exception: - stored_commit_hash = "" - - return stored_commit_hash + return "" +@lru_cache() def git_tag(): - global stored_git_tag - - if stored_git_tag is not None: - return stored_git_tag - try: - stored_git_tag = run(f"{git} describe --tags").strip() + return subprocess.check_output(f"{git} describe --tags", encoding='utf8').strip() except Exception: - stored_git_tag = "" - - return stored_git_tag + return "" def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_command_live) -> str: -- cgit v1.2.3 From 451d255b5859580c4adf99d67760330d58d76446 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 23:29:34 +0300 Subject: Get rid of check_run + run_python --- launch.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index ae67fe5c..578af229 100644 --- a/launch.py +++ b/launch.py @@ -103,11 +103,6 @@ def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_ return (result.stdout or "") -def check_run(command): - result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) - return result.returncode == 0 - - def is_installed(package): try: spec = importlib.util.find_spec(package) @@ -121,10 +116,6 @@ def repo_dir(name): return os.path.join(script_path, dir_repos, name) -def run_python(code, desc=None, errdesc=None): - return run(f'"{python}" -c "{code}"', desc, errdesc) - - def run_pip(command, desc=None, live=default_command_live): if args.skip_install: return @@ -133,8 +124,9 @@ def run_pip(command, desc=None, live=default_command_live): return run(f'"{python}" -m pip {command} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}", live=live) -def check_run_python(code): - return check_run(f'"{python}" -c "{code}"') +def check_run_python(code: str) -> bool: + result = subprocess.run([python, "-c", code], capture_output=True, shell=True) + return result.returncode == 0 def git_clone(url, dir, name, commithash=None): @@ -261,8 +253,11 @@ def prepare_environment(): if args.reinstall_torch or not is_installed("torch") or not is_installed("torchvision"): run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True) - if not args.skip_torch_cuda_test: - run_python("import torch; assert torch.cuda.is_available(), 'Torch is not able to use GPU; add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check'") + if not args.skip_torch_cuda_test and not check_run_python("import torch; assert torch.cuda.is_available()"): + raise RuntimeError( + 'Torch is not able to use GPU; ' + 'add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check' + ) if not is_installed("gfpgan"): run_pip(f"install {gfpgan_package}", "gfpgan") -- cgit v1.2.3 From f29c41bf6dd04a721e1dc0a162b042cad269f247 Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Sun, 14 May 2023 22:29:28 +0800 Subject: Modify pytorch command --- launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index cfc0cffa..b00420d0 100644 --- a/launch.py +++ b/launch.py @@ -237,7 +237,7 @@ def run_extensions_installers(settings_file): def prepare_environment(): - torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url https://download.pytorch.org/whl/cu118") + torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --index-url https://download.pytorch.org/whl/cu118") requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.17') -- cgit v1.2.3 From d9968e61082fb5ed16eedfe8fa43bf6f2e7b76e7 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Sun, 14 May 2023 20:30:02 +0300 Subject: launch.py: Don't involve shell for running Python or Git for output Fixes Linux regression in 451d255b5859580c4adf99d67760330d58d76446 --- launch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 578af229..f8380911 100644 --- a/launch.py +++ b/launch.py @@ -58,7 +58,7 @@ Use --skip-python-version-check to suppress this warning. @lru_cache() def commit_hash(): try: - return subprocess.check_output(f"{git} rev-parse HEAD", encoding='utf8').strip() + return subprocess.check_output([git, "rev-parse", "HEAD"], shell=False, encoding='utf8').strip() except Exception: return "" @@ -66,7 +66,7 @@ def commit_hash(): @lru_cache() def git_tag(): try: - return subprocess.check_output(f"{git} describe --tags", encoding='utf8').strip() + return subprocess.check_output([git, "describe", "--tags"], shell=False, encoding='utf8').strip() except Exception: return "" @@ -125,7 +125,7 @@ def run_pip(command, desc=None, live=default_command_live): def check_run_python(code: str) -> bool: - result = subprocess.run([python, "-c", code], capture_output=True, shell=True) + result = subprocess.run([python, "-c", code], capture_output=True, shell=False) return result.returncode == 0 -- cgit v1.2.3 From 9a9557ecfc824c4a005dc79466dba8f5884dbfb1 Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Mon, 15 May 2023 03:00:23 +0800 Subject: Change to extra-index-url --- launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index b00420d0..034de0a9 100644 --- a/launch.py +++ b/launch.py @@ -237,7 +237,7 @@ def run_extensions_installers(settings_file): def prepare_environment(): - torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --index-url https://download.pytorch.org/whl/cu118") + torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118") requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.17') -- cgit v1.2.3 From 0d31f20cbd556ea4ba3d8ad9254bcce71c32088c Mon Sep 17 00:00:00 2001 From: bobzilladev Date: Tue, 16 May 2023 13:15:30 -0400 Subject: Use ngrok-py library --- launch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index cfc0cffa..871d3ea8 100644 --- a/launch.py +++ b/launch.py @@ -294,8 +294,8 @@ def prepare_environment(): elif platform.system() == "Linux": run_pip(f"install {xformers_package}", "xformers") - if not is_installed("pyngrok") and args.ngrok: - run_pip("install pyngrok", "ngrok") + if not is_installed("ngrok") and args.ngrok: + run_pip("install ngrok", "ngrok") os.makedirs(os.path.join(script_path, dir_repos), exist_ok=True) -- cgit v1.2.3 From 96cba45d71cf25ab2f3bb7d7085347c8b6ef6d7d Mon Sep 17 00:00:00 2001 From: Sakura-Luna <53183413+Sakura-Luna@users.noreply.github.com> Date: Thu, 18 May 2023 17:29:47 +0800 Subject: Modify xformers instead of pytorch --- launch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 034de0a9..de8bde24 100644 --- a/launch.py +++ b/launch.py @@ -237,7 +237,8 @@ def run_extensions_installers(settings_file): def prepare_environment(): - torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118") + torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu118") + torch_command = os.environ.get('TORCH_COMMAND', f"pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url {torch_index_url}") requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.17') @@ -292,7 +293,7 @@ def prepare_environment(): if not is_installed("xformers"): exit(0) elif platform.system() == "Linux": - run_pip(f"install {xformers_package}", "xformers") + run_pip(f"install -U -I --no-deps {xformers_package}", "xformers") if not is_installed("pyngrok") and args.ngrok: run_pip("install pyngrok", "ngrok") -- cgit v1.2.3 From 793a491923ba11adbe1024e0eb0402923165dafa Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 11 May 2023 21:57:43 +0300 Subject: Overhaul tests to use py.test --- launch.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index 6e9ca8de..b9b5b709 100644 --- a/launch.py +++ b/launch.py @@ -310,12 +310,8 @@ def prepare_environment(): print("Exiting because of --exit argument") exit(0) - if args.tests and not args.no_tests: - exitcode = tests(args.tests) - exit(exitcode) - -def tests(test_dir): +def configure_for_tests(): if "--api" not in sys.argv: sys.argv.append("--api") if "--ckpt" not in sys.argv: @@ -325,21 +321,8 @@ def tests(test_dir): sys.argv.append("--skip-torch-cuda-test") if "--disable-nan-check" not in sys.argv: sys.argv.append("--disable-nan-check") - if "--no-tests" not in sys.argv: - sys.argv.append("--no-tests") - - print(f"Launching Web UI in another process for testing with arguments: {' '.join(sys.argv[1:])}") os.environ['COMMANDLINE_ARGS'] = "" - with open(os.path.join(script_path, 'test/stdout.txt'), "w", encoding="utf8") as stdout, open(os.path.join(script_path, 'test/stderr.txt'), "w", encoding="utf8") as stderr: - proc = subprocess.Popen([sys.executable, *sys.argv], stdout=stdout, stderr=stderr) - - import test.server_poll - exitcode = test.server_poll.run_tests(proc, test_dir) - - print(f"Stopping Web UI process with id {proc.pid}") - proc.kill() - return exitcode def start(): @@ -351,6 +334,15 @@ def start(): webui.webui() -if __name__ == "__main__": - prepare_environment() +def main(): + if not args.skip_prepare_environment: + prepare_environment() + + if args.test_server: + configure_for_tests() + start() + + +if __name__ == "__main__": + main() -- cgit v1.2.3 From 31545abe145ac8833c9c15aa41300fb609dcb128 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sun, 21 May 2023 07:31:39 +0300 Subject: add DPM-Solver++(2M) SDE from new k-diffusion --- launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'launch.py') diff --git a/launch.py b/launch.py index b9b5b709..1d504c38 100644 --- a/launch.py +++ b/launch.py @@ -236,7 +236,7 @@ def prepare_environment(): stable_diffusion_commit_hash = os.environ.get('STABLE_DIFFUSION_COMMIT_HASH', "cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf") taming_transformers_commit_hash = os.environ.get('TAMING_TRANSFORMERS_COMMIT_HASH', "24268930bf1dce879235a7fddd0b2355b84d7ea6") - k_diffusion_commit_hash = os.environ.get('K_DIFFUSION_COMMIT_HASH', "5b3af030dd83e0297272d861c19477735d0317ec") + k_diffusion_commit_hash = os.environ.get('K_DIFFUSION_COMMIT_HASH', "c9fe758757e022f05ca5a53fa8fac28889e4f1cf") codeformer_commit_hash = os.environ.get('CODEFORMER_COMMIT_HASH', "c5b4593074ba6214284d6acd5f1719b6c5d739af") blip_commit_hash = os.environ.get('BLIP_COMMIT_HASH', "48211a1594f1321b00f14c9f7a5b4813144b2fb9") -- cgit v1.2.3 From 4b07984d1b92949311a703cfbb7dad5e96a7fb01 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sun, 21 May 2023 16:15:16 +0300 Subject: reworking launch.py: rename --- launch.py | 348 -------------------------------------------------------------- 1 file changed, 348 deletions(-) delete mode 100644 launch.py (limited to 'launch.py') diff --git a/launch.py b/launch.py deleted file mode 100644 index 1d504c38..00000000 --- a/launch.py +++ /dev/null @@ -1,348 +0,0 @@ -# this scripts installs necessary requirements and launches main program in webui.py -import subprocess -import os -import sys -import importlib.util -import platform -import json -from functools import lru_cache - -from modules import cmd_args -from modules.paths_internal import script_path, extensions_dir - -args, _ = cmd_args.parser.parse_known_args() - -python = sys.executable -git = os.environ.get('GIT', "git") -index_url = os.environ.get('INDEX_URL', "") -dir_repos = "repositories" - -# Whether to default to printing command output -default_command_live = (os.environ.get('WEBUI_LAUNCH_LIVE_OUTPUT') == "1") - -if 'GRADIO_ANALYTICS_ENABLED' not in os.environ: - os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False' - - -def check_python_version(): - is_windows = platform.system() == "Windows" - major = sys.version_info.major - minor = sys.version_info.minor - micro = sys.version_info.micro - - if is_windows: - supported_minors = [10] - else: - supported_minors = [7, 8, 9, 10, 11] - - if not (major == 3 and minor in supported_minors): - import modules.errors - - modules.errors.print_error_explanation(f""" -INCOMPATIBLE PYTHON VERSION - -This program is tested with 3.10.6 Python, but you have {major}.{minor}.{micro}. -If you encounter an error with "RuntimeError: Couldn't install torch." message, -or any other error regarding unsuccessful package (library) installation, -please downgrade (or upgrade) to the latest version of 3.10 Python -and delete current Python and "venv" folder in WebUI's directory. - -You can download 3.10 Python from here: https://www.python.org/downloads/release/python-3106/ - -{"Alternatively, use a binary release of WebUI: https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases" if is_windows else ""} - -Use --skip-python-version-check to suppress this warning. -""") - - -@lru_cache() -def commit_hash(): - try: - return subprocess.check_output([git, "rev-parse", "HEAD"], shell=False, encoding='utf8').strip() - except Exception: - return "" - - -@lru_cache() -def git_tag(): - try: - return subprocess.check_output([git, "describe", "--tags"], shell=False, encoding='utf8').strip() - except Exception: - return "" - - -def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_command_live) -> str: - if desc is not None: - print(desc) - - run_kwargs = { - "args": command, - "shell": True, - "env": os.environ if custom_env is None else custom_env, - "encoding": 'utf8', - "errors": 'ignore', - } - - if not live: - run_kwargs["stdout"] = run_kwargs["stderr"] = subprocess.PIPE - - result = subprocess.run(**run_kwargs) - - if result.returncode != 0: - error_bits = [ - f"{errdesc or 'Error running command'}.", - f"Command: {command}", - f"Error code: {result.returncode}", - ] - if result.stdout: - error_bits.append(f"stdout: {result.stdout}") - if result.stderr: - error_bits.append(f"stderr: {result.stderr}") - raise RuntimeError("\n".join(error_bits)) - - return (result.stdout or "") - - -def is_installed(package): - try: - spec = importlib.util.find_spec(package) - except ModuleNotFoundError: - return False - - return spec is not None - - -def repo_dir(name): - return os.path.join(script_path, dir_repos, name) - - -def run_pip(command, desc=None, live=default_command_live): - if args.skip_install: - return - - index_url_line = f' --index-url {index_url}' if index_url != '' else '' - return run(f'"{python}" -m pip {command} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}", live=live) - - -def check_run_python(code: str) -> bool: - result = subprocess.run([python, "-c", code], capture_output=True, shell=False) - return result.returncode == 0 - - -def git_clone(url, dir, name, commithash=None): - # TODO clone into temporary dir and move if successful - - if os.path.exists(dir): - if commithash is None: - return - - current_hash = run(f'"{git}" -C "{dir}" rev-parse HEAD', None, f"Couldn't determine {name}'s hash: {commithash}").strip() - if current_hash == commithash: - return - - run(f'"{git}" -C "{dir}" fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}") - run(f'"{git}" -C "{dir}" checkout {commithash}', f"Checking out commit for {name} with hash: {commithash}...", f"Couldn't checkout commit {commithash} for {name}") - return - - run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}") - - if commithash is not None: - run(f'"{git}" -C "{dir}" checkout {commithash}', None, "Couldn't checkout {name}'s hash: {commithash}") - - -def git_pull_recursive(dir): - for subdir, _, _ in os.walk(dir): - if os.path.exists(os.path.join(subdir, '.git')): - try: - output = subprocess.check_output([git, '-C', subdir, 'pull', '--autostash']) - print(f"Pulled changes for repository in '{subdir}':\n{output.decode('utf-8').strip()}\n") - except subprocess.CalledProcessError as e: - print(f"Couldn't perform 'git pull' on repository in '{subdir}':\n{e.output.decode('utf-8').strip()}\n") - - -def version_check(commit): - try: - import requests - commits = requests.get('https://api.github.com/repos/AUTOMATIC1111/stable-diffusion-webui/branches/master').json() - if commit != "" and commits['commit']['sha'] != commit: - print("--------------------------------------------------------") - print("| You are not up to date with the most recent release. |") - print("| Consider running `git pull` to update. |") - print("--------------------------------------------------------") - elif commits['commit']['sha'] == commit: - print("You are up to date with the most recent release.") - else: - print("Not a git clone, can't perform version check.") - except Exception as e: - print("version check failed", e) - - -def run_extension_installer(extension_dir): - path_installer = os.path.join(extension_dir, "install.py") - if not os.path.isfile(path_installer): - return - - try: - env = os.environ.copy() - env['PYTHONPATH'] = os.path.abspath(".") - - print(run(f'"{python}" "{path_installer}"', errdesc=f"Error running install.py for extension {extension_dir}", custom_env=env)) - except Exception as e: - print(e, file=sys.stderr) - - -def list_extensions(settings_file): - settings = {} - - try: - if os.path.isfile(settings_file): - with open(settings_file, "r", encoding="utf8") as file: - settings = json.load(file) - except Exception as e: - print(e, file=sys.stderr) - - disabled_extensions = set(settings.get('disabled_extensions', [])) - disable_all_extensions = settings.get('disable_all_extensions', 'none') - - if disable_all_extensions != 'none': - return [] - - return [x for x in os.listdir(extensions_dir) if x not in disabled_extensions] - - -def run_extensions_installers(settings_file): - if not os.path.isdir(extensions_dir): - return - - for dirname_extension in list_extensions(settings_file): - run_extension_installer(os.path.join(extensions_dir, dirname_extension)) - - -def prepare_environment(): - torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu118") - torch_command = os.environ.get('TORCH_COMMAND', f"pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url {torch_index_url}") - requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") - - xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.17') - gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "https://github.com/TencentARC/GFPGAN/archive/8d2447a2d918f8eba5a4a01463fd48e45126a379.zip") - clip_package = os.environ.get('CLIP_PACKAGE', "https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip") - openclip_package = os.environ.get('OPENCLIP_PACKAGE', "https://github.com/mlfoundations/open_clip/archive/bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b.zip") - - stable_diffusion_repo = os.environ.get('STABLE_DIFFUSION_REPO', "https://github.com/Stability-AI/stablediffusion.git") - taming_transformers_repo = os.environ.get('TAMING_TRANSFORMERS_REPO', "https://github.com/CompVis/taming-transformers.git") - k_diffusion_repo = os.environ.get('K_DIFFUSION_REPO', 'https://github.com/crowsonkb/k-diffusion.git') - codeformer_repo = os.environ.get('CODEFORMER_REPO', 'https://github.com/sczhou/CodeFormer.git') - blip_repo = os.environ.get('BLIP_REPO', 'https://github.com/salesforce/BLIP.git') - - stable_diffusion_commit_hash = os.environ.get('STABLE_DIFFUSION_COMMIT_HASH', "cf1d67a6fd5ea1aa600c4df58e5b47da45f6bdbf") - taming_transformers_commit_hash = os.environ.get('TAMING_TRANSFORMERS_COMMIT_HASH', "24268930bf1dce879235a7fddd0b2355b84d7ea6") - k_diffusion_commit_hash = os.environ.get('K_DIFFUSION_COMMIT_HASH', "c9fe758757e022f05ca5a53fa8fac28889e4f1cf") - codeformer_commit_hash = os.environ.get('CODEFORMER_COMMIT_HASH', "c5b4593074ba6214284d6acd5f1719b6c5d739af") - blip_commit_hash = os.environ.get('BLIP_COMMIT_HASH', "48211a1594f1321b00f14c9f7a5b4813144b2fb9") - - if not args.skip_python_version_check: - check_python_version() - - commit = commit_hash() - tag = git_tag() - - print(f"Python {sys.version}") - print(f"Version: {tag}") - print(f"Commit hash: {commit}") - - if args.reinstall_torch or not is_installed("torch") or not is_installed("torchvision"): - run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True) - - if not args.skip_torch_cuda_test and not check_run_python("import torch; assert torch.cuda.is_available()"): - raise RuntimeError( - 'Torch is not able to use GPU; ' - 'add --skip-torch-cuda-test to COMMANDLINE_ARGS variable to disable this check' - ) - - if not is_installed("gfpgan"): - run_pip(f"install {gfpgan_package}", "gfpgan") - - if not is_installed("clip"): - run_pip(f"install {clip_package}", "clip") - - if not is_installed("open_clip"): - run_pip(f"install {openclip_package}", "open_clip") - - if (not is_installed("xformers") or args.reinstall_xformers) and args.xformers: - if platform.system() == "Windows": - if platform.python_version().startswith("3.10"): - run_pip(f"install -U -I --no-deps {xformers_package}", "xformers", live=True) - else: - print("Installation of xformers is not supported in this version of Python.") - print("You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness") - if not is_installed("xformers"): - exit(0) - elif platform.system() == "Linux": - run_pip(f"install -U -I --no-deps {xformers_package}", "xformers") - - if not is_installed("ngrok") and args.ngrok: - run_pip("install ngrok", "ngrok") - - os.makedirs(os.path.join(script_path, dir_repos), exist_ok=True) - - git_clone(stable_diffusion_repo, repo_dir('stable-diffusion-stability-ai'), "Stable Diffusion", stable_diffusion_commit_hash) - git_clone(taming_transformers_repo, repo_dir('taming-transformers'), "Taming Transformers", taming_transformers_commit_hash) - git_clone(k_diffusion_repo, repo_dir('k-diffusion'), "K-diffusion", k_diffusion_commit_hash) - git_clone(codeformer_repo, repo_dir('CodeFormer'), "CodeFormer", codeformer_commit_hash) - git_clone(blip_repo, repo_dir('BLIP'), "BLIP", blip_commit_hash) - - if not is_installed("lpips"): - run_pip(f"install -r \"{os.path.join(repo_dir('CodeFormer'), 'requirements.txt')}\"", "requirements for CodeFormer") - - if not os.path.isfile(requirements_file): - requirements_file = os.path.join(script_path, requirements_file) - run_pip(f"install -r \"{requirements_file}\"", "requirements") - - run_extensions_installers(settings_file=args.ui_settings_file) - - if args.update_check: - version_check(commit) - - if args.update_all_extensions: - git_pull_recursive(extensions_dir) - - if "--exit" in sys.argv: - print("Exiting because of --exit argument") - exit(0) - - -def configure_for_tests(): - if "--api" not in sys.argv: - sys.argv.append("--api") - if "--ckpt" not in sys.argv: - sys.argv.append("--ckpt") - sys.argv.append(os.path.join(script_path, "test/test_files/empty.pt")) - if "--skip-torch-cuda-test" not in sys.argv: - sys.argv.append("--skip-torch-cuda-test") - if "--disable-nan-check" not in sys.argv: - sys.argv.append("--disable-nan-check") - - os.environ['COMMANDLINE_ARGS'] = "" - - -def start(): - print(f"Launching {'API server' if '--nowebui' in sys.argv else 'Web UI'} with arguments: {' '.join(sys.argv[1:])}") - import webui - if '--nowebui' in sys.argv: - webui.api_only() - else: - webui.webui() - - -def main(): - if not args.skip_prepare_environment: - prepare_environment() - - if args.test_server: - configure_for_tests() - - start() - - -if __name__ == "__main__": - main() -- cgit v1.2.3 From f9fe5e5f9d7b7465da75bf8ba470785d2240caf7 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Sun, 21 May 2023 16:27:23 +0300 Subject: reworking launch.py: add references to renamed file --- launch.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 launch.py (limited to 'launch.py') diff --git a/launch.py b/launch.py new file mode 100644 index 00000000..b103c8f3 --- /dev/null +++ b/launch.py @@ -0,0 +1,38 @@ +from modules import launch_utils + + +args = launch_utils.args +python = launch_utils.python +git = launch_utils.git +index_url = launch_utils.index_url +dir_repos = launch_utils.dir_repos + +commit_hash = launch_utils.commit_hash +git_tag = launch_utils.git_tag + +run = launch_utils.run +is_installed = launch_utils.is_installed +repo_dir = launch_utils.repo_dir + +run_pip = launch_utils.run_pip +check_run_python = launch_utils.check_run_python +git_clone = launch_utils.git_clone +git_pull_recursive = launch_utils.git_pull_recursive +run_extension_installer = launch_utils.run_extension_installer +prepare_environment = launch_utils.prepare_environment +configure_for_tests = launch_utils.configure_for_tests +start = launch_utils.start + + +def main(): + if not args.skip_prepare_environment: + prepare_environment() + + if args.test_server: + configure_for_tests() + + start() + + +if __name__ == "__main__": + main() -- cgit v1.2.3