mirror of
				https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
				synced 2025-10-30 17:38:51 +00:00 
			
		
		
		
	Shielded launch enviroment creation stuff from multiprocessing
This commit is contained in:
		
							parent
							
								
									9d1138e294
								
							
						
					
					
						commit
						f8197976ef
					
				
							
								
								
									
										82
									
								
								launch.py
									
									
									
									
									
								
							
							
						
						
									
										82
									
								
								launch.py
									
									
									
									
									
								
							| @ -6,40 +6,11 @@ import importlib.util | |||||||
| import shlex | import shlex | ||||||
| import platform | import platform | ||||||
| 
 | 
 | ||||||
| dir_repos = "repositories" |  | ||||||
| dir_tmp = "tmp" |  | ||||||
| 
 |  | ||||||
| python = sys.executable |  | ||||||
| git = os.environ.get('GIT', "git") |  | ||||||
| torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113") |  | ||||||
| requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") |  | ||||||
| commandline_args = os.environ.get('COMMANDLINE_ARGS', "") |  | ||||||
| 
 |  | ||||||
| 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") |  | ||||||
| 
 |  | ||||||
| stable_diffusion_commit_hash = os.environ.get('STABLE_DIFFUSION_COMMIT_HASH', "69ae4b35e0a0f6ee1af8bb9a5d0016ccb27e36dc") |  | ||||||
| taming_transformers_commit_hash = os.environ.get('TAMING_TRANSFORMERS_COMMIT_HASH', "24268930bf1dce879235a7fddd0b2355b84d7ea6") |  | ||||||
| k_diffusion_commit_hash = os.environ.get('K_DIFFUSION_COMMIT_HASH', "f4e99857772fc3a126ba886aadf795a332774878") |  | ||||||
| codeformer_commit_hash = os.environ.get('CODEFORMER_COMMIT_HASH', "c5b4593074ba6214284d6acd5f1719b6c5d739af") |  | ||||||
| blip_commit_hash = os.environ.get('BLIP_COMMIT_HASH', "48211a1594f1321b00f14c9f7a5b4813144b2fb9") |  | ||||||
| 
 |  | ||||||
| args = shlex.split(commandline_args) |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| def extract_arg(args, name): | def extract_arg(args, name): | ||||||
|     return [x for x in args if x != name], name in args |     return [x for x in args if x != name], name in args | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| args, skip_torch_cuda_test = extract_arg(args, '--skip-torch-cuda-test') |  | ||||||
| xformers = '--xformers' in args |  | ||||||
| deepdanbooru = '--deepdanbooru' in args |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def repo_dir(name): |  | ||||||
|     return os.path.join(dir_repos, name) |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def run(command, desc=None, errdesc=None): | def run(command, desc=None, errdesc=None): | ||||||
|     if desc is not None: |     if desc is not None: | ||||||
|         print(desc) |         print(desc) | ||||||
| @ -59,23 +30,11 @@ stderr: {result.stderr.decode(encoding="utf8", errors="ignore") if len(result.st | |||||||
|     return result.stdout.decode(encoding="utf8", errors="ignore") |     return result.stdout.decode(encoding="utf8", errors="ignore") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def run_python(code, desc=None, errdesc=None): |  | ||||||
|     return run(f'"{python}" -c "{code}"', desc, errdesc) |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def run_pip(args, desc=None): |  | ||||||
|     return run(f'"{python}" -m pip {args} --prefer-binary', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}") |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def check_run(command): | def check_run(command): | ||||||
|     result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) |     result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | ||||||
|     return result.returncode == 0 |     return result.returncode == 0 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def check_run_python(code): |  | ||||||
|     return check_run(f'"{python}" -c "{code}"') |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def is_installed(package): | def is_installed(package): | ||||||
|     try: |     try: | ||||||
|         spec = importlib.util.find_spec(package) |         spec = importlib.util.find_spec(package) | ||||||
| @ -85,6 +44,42 @@ def is_installed(package): | |||||||
|     return spec is not None |     return spec is not None | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | def prepare_enviroment(): | ||||||
|  |     dir_repos = "repositories" | ||||||
|  | 
 | ||||||
|  |     python = sys.executable | ||||||
|  |     git = os.environ.get('GIT', "git") | ||||||
|  |     torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113") | ||||||
|  |     requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") | ||||||
|  |     commandline_args = os.environ.get('COMMANDLINE_ARGS', "") | ||||||
|  | 
 | ||||||
|  |     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") | ||||||
|  | 
 | ||||||
|  |     stable_diffusion_commit_hash = os.environ.get('STABLE_DIFFUSION_COMMIT_HASH', "69ae4b35e0a0f6ee1af8bb9a5d0016ccb27e36dc") | ||||||
|  |     taming_transformers_commit_hash = os.environ.get('TAMING_TRANSFORMERS_COMMIT_HASH', "24268930bf1dce879235a7fddd0b2355b84d7ea6") | ||||||
|  |     k_diffusion_commit_hash = os.environ.get('K_DIFFUSION_COMMIT_HASH', "f4e99857772fc3a126ba886aadf795a332774878") | ||||||
|  |     codeformer_commit_hash = os.environ.get('CODEFORMER_COMMIT_HASH', "c5b4593074ba6214284d6acd5f1719b6c5d739af") | ||||||
|  |     blip_commit_hash = os.environ.get('BLIP_COMMIT_HASH', "48211a1594f1321b00f14c9f7a5b4813144b2fb9") | ||||||
|  | 
 | ||||||
|  |     args = shlex.split(commandline_args) | ||||||
|  | 
 | ||||||
|  |     args, skip_torch_cuda_test = extract_arg(args, '--skip-torch-cuda-test') | ||||||
|  |     xformers = '--xformers' in args | ||||||
|  |     deepdanbooru = '--deepdanbooru' in args | ||||||
|  | 
 | ||||||
|  |     def repo_dir(name): | ||||||
|  |         return os.path.join(dir_repos, name) | ||||||
|  | 
 | ||||||
|  |     def run_python(code, desc=None, errdesc=None): | ||||||
|  |         return run(f'"{python}" -c "{code}"', desc, errdesc) | ||||||
|  | 
 | ||||||
|  |     def run_pip(args, desc=None): | ||||||
|  |         return run(f'"{python}" -m pip {args} --prefer-binary', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}") | ||||||
|  | 
 | ||||||
|  |     def check_run_python(code): | ||||||
|  |         return check_run(f'"{python}" -c "{code}"') | ||||||
|  | 
 | ||||||
|     def git_clone(url, dir, name, commithash=None): |     def git_clone(url, dir, name, commithash=None): | ||||||
|         # TODO clone into temporary dir and move if successful |         # TODO clone into temporary dir and move if successful | ||||||
| 
 | 
 | ||||||
| @ -105,7 +100,6 @@ def git_clone(url, dir, name, commithash=None): | |||||||
|         if commithash is not None: |         if commithash is not None: | ||||||
|             run(f'"{git}" -C {dir} checkout {commithash}', None, "Couldn't checkout {name}'s hash: {commithash}") |             run(f'"{git}" -C {dir} checkout {commithash}', None, "Couldn't checkout {name}'s hash: {commithash}") | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     try: |     try: | ||||||
|         commit = run(f"{git} rev-parse HEAD").strip() |         commit = run(f"{git} rev-parse HEAD").strip() | ||||||
|     except Exception: |     except Exception: | ||||||
| @ -114,7 +108,6 @@ except Exception: | |||||||
|     print(f"Python {sys.version}") |     print(f"Python {sys.version}") | ||||||
|     print(f"Commit hash: {commit}") |     print(f"Commit hash: {commit}") | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     if not is_installed("torch") or not is_installed("torchvision"): |     if not is_installed("torch") or not is_installed("torchvision"): | ||||||
|         run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch") |         run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch") | ||||||
| 
 | 
 | ||||||
| @ -155,10 +148,13 @@ if "--exit" in args: | |||||||
|         print("Exiting because of --exit argument") |         print("Exiting because of --exit argument") | ||||||
|         exit(0) |         exit(0) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def start_webui(): | def start_webui(): | ||||||
|     print(f"Launching Web UI with arguments: {' '.join(sys.argv[1:])}") |     print(f"Launching Web UI with arguments: {' '.join(sys.argv[1:])}") | ||||||
|     import webui |     import webui | ||||||
|     webui.webui() |     webui.webui() | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|  |     prepare_enviroment() | ||||||
|     start_webui() |     start_webui() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Greendayle
						Greendayle