ProDem commited on
Commit
b353306
·
1 Parent(s): f7ce7aa

Delete launch.py

Browse files
Files changed (1) hide show
  1. launch.py +0 -206
launch.py DELETED
@@ -1,206 +0,0 @@
1
- # this scripts installs necessary requirements and launches main program in webui.py
2
- import subprocess
3
- import os
4
- import sys
5
- import importlib.util
6
- import shlex
7
- import platform
8
-
9
- dir_repos = "repositories"
10
- python = sys.executable
11
- git = os.environ.get('GIT', "git")
12
- index_url = os.environ.get('INDEX_URL', "")
13
-
14
-
15
- def extract_arg(args, name):
16
- return [x for x in args if x != name], name in args
17
-
18
-
19
- def run(command, desc=None, errdesc=None):
20
- if desc is not None:
21
- print(desc)
22
-
23
- result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
24
-
25
- if result.returncode != 0:
26
-
27
- message = f"""{errdesc or 'Error running command'}.
28
- Command: {command}
29
- Error code: {result.returncode}
30
- stdout: {result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stdout)>0 else '<empty>'}
31
- stderr: {result.stderr.decode(encoding="utf8", errors="ignore") if len(result.stderr)>0 else '<empty>'}
32
- """
33
- raise RuntimeError(message)
34
-
35
- return result.stdout.decode(encoding="utf8", errors="ignore")
36
-
37
-
38
- def check_run(command):
39
- result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
40
- return result.returncode == 0
41
-
42
-
43
- def is_installed(package):
44
- try:
45
- spec = importlib.util.find_spec(package)
46
- except ModuleNotFoundError:
47
- return False
48
-
49
- return spec is not None
50
-
51
-
52
- def repo_dir(name):
53
- return os.path.join(dir_repos, name)
54
-
55
-
56
- def run_python(code, desc=None, errdesc=None):
57
- return run(f'"{python}" -c "{code}"', desc, errdesc)
58
-
59
-
60
- def run_pip(args, desc=None):
61
- index_url_line = f' --index-url {index_url}' if index_url != '' else ''
62
- return run(f'"{python}" -m pip {args} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}")
63
-
64
-
65
- def check_run_python(code):
66
- return check_run(f'"{python}" -c "{code}"')
67
-
68
-
69
- def git_clone(url, dir, name, commithash=None):
70
- # TODO clone into temporary dir and move if successful
71
-
72
- if os.path.exists(dir):
73
- if commithash is None:
74
- return
75
-
76
- current_hash = run(f'"{git}" -C {dir} rev-parse HEAD', None, f"Couldn't determine {name}'s hash: {commithash}").strip()
77
- if current_hash == commithash:
78
- return
79
-
80
- run(f'"{git}" -C {dir} fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}")
81
- run(f'"{git}" -C {dir} checkout {commithash}', f"Checking out commit for {name} with hash: {commithash}...", f"Couldn't checkout commit {commithash} for {name}")
82
- return
83
-
84
- run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}")
85
-
86
- if commithash is not None:
87
- run(f'"{git}" -C {dir} checkout {commithash}', None, "Couldn't checkout {name}'s hash: {commithash}")
88
-
89
-
90
- def version_check(commit):
91
- try:
92
- import requests
93
- commits = requests.get('https://api.github.com/repos/AUTOMATIC1111/stable-diffusion-webui/branches/master').json()
94
- if commit != "<none>" and commits['commit']['sha'] != commit:
95
- print("--------------------------------------------------------")
96
- print("| You are not up to date with the most recent release. |")
97
- print("| Consider running `git pull` to update. |")
98
- print("--------------------------------------------------------")
99
- elif commits['commit']['sha'] == commit:
100
- print("You are up to date with the most recent release.")
101
- else:
102
- print("Not a git clone, can't perform version check.")
103
- except Exception as e:
104
- print("versipm check failed",e)
105
-
106
-
107
- def prepare_enviroment():
108
- 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")
109
- requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
110
- commandline_args = os.environ.get('COMMANDLINE_ARGS', "")
111
-
112
- gfpgan_package = os.environ.get('GFPGAN_PACKAGE', "git+https://github.com/TencentARC/GFPGAN.git@8d2447a2d918f8eba5a4a01463fd48e45126a379")
113
- clip_package = os.environ.get('CLIP_PACKAGE', "git+https://github.com/openai/CLIP.git@d50d76daa670286dd6cacf3bcd80b5e4823fc8e1")
114
- deepdanbooru_package = os.environ.get('DEEPDANBOORU_PACKAGE', "git+https://github.com/KichangKim/DeepDanbooru.git@edf73df4cdaeea2cf00e9ac08bd8a9026b7a7b26")
115
-
116
- xformers_windows_package = os.environ.get('XFORMERS_WINDOWS_PACKAGE', 'https://github.com/C43H66N12O12S2/stable-diffusion-webui/releases/download/f/xformers-0.0.14.dev0-cp310-cp310-win_amd64.whl')
117
-
118
- stable_diffusion_repo = os.environ.get('STABLE_DIFFUSION_REPO', "https://github.com/CompVis/stable-diffusion.git")
119
- taming_transformers_repo = os.environ.get('TAMING_REANSFORMERS_REPO', "https://github.com/CompVis/taming-transformers.git")
120
- k_diffusion_repo = os.environ.get('K_DIFFUSION_REPO', 'https://github.com/crowsonkb/k-diffusion.git')
121
- codeformer_repo = os.environ.get('CODEFORMET_REPO', 'https://github.com/sczhou/CodeFormer.git')
122
- blip_repo = os.environ.get('BLIP_REPO', 'https://github.com/salesforce/BLIP.git')
123
-
124
- stable_diffusion_commit_hash = os.environ.get('STABLE_DIFFUSION_COMMIT_HASH', "69ae4b35e0a0f6ee1af8bb9a5d0016ccb27e36dc")
125
- taming_transformers_commit_hash = os.environ.get('TAMING_TRANSFORMERS_COMMIT_HASH', "24268930bf1dce879235a7fddd0b2355b84d7ea6")
126
- k_diffusion_commit_hash = os.environ.get('K_DIFFUSION_COMMIT_HASH', "f4e99857772fc3a126ba886aadf795a332774878")
127
- codeformer_commit_hash = os.environ.get('CODEFORMER_COMMIT_HASH', "c5b4593074ba6214284d6acd5f1719b6c5d739af")
128
- blip_commit_hash = os.environ.get('BLIP_COMMIT_HASH', "48211a1594f1321b00f14c9f7a5b4813144b2fb9")
129
-
130
- sys.argv += shlex.split(commandline_args)
131
-
132
- sys.argv, skip_torch_cuda_test = extract_arg(sys.argv, '--skip-torch-cuda-test')
133
- sys.argv, reinstall_xformers = extract_arg(sys.argv, '--reinstall-xformers')
134
- sys.argv, update_check = extract_arg(sys.argv, '--update-check')
135
- xformers = '--xformers' in sys.argv
136
- deepdanbooru = '--deepdanbooru' in sys.argv
137
- ngrok = '--ngrok' in sys.argv
138
-
139
- try:
140
- commit = run(f"{git} rev-parse HEAD").strip()
141
- except Exception:
142
- commit = "<none>"
143
-
144
- print(f"Python {sys.version}")
145
- print(f"Commit hash: {commit}")
146
-
147
- if not is_installed("torch") or not is_installed("torchvision"):
148
- run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch")
149
-
150
- if not skip_torch_cuda_test:
151
- 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'")
152
-
153
- if not is_installed("gfpgan"):
154
- run_pip(f"install {gfpgan_package}", "gfpgan")
155
-
156
- if not is_installed("clip"):
157
- run_pip(f"install {clip_package}", "clip")
158
-
159
- if (not is_installed("xformers") or reinstall_xformers) and xformers:
160
- if platform.system() == "Windows":
161
- if platform.python_version().startswith("3.10"):
162
- run_pip(f"install -U -I --no-deps {xformers_windows_package}", "xformers")
163
- else:
164
- print("Installation of xformers is not supported in this version of Python.")
165
- print("You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness")
166
- if not is_installed("xformers"):
167
- exit(0)
168
- elif platform.system() == "Linux":
169
- run_pip("install xformers", "xformers")
170
-
171
- if not is_installed("deepdanbooru") and deepdanbooru:
172
- run_pip(f"install {deepdanbooru_package}#egg=deepdanbooru[tensorflow] tensorflow==2.10.0 tensorflow-io==0.27.0", "deepdanbooru")
173
-
174
- if not is_installed("pyngrok") and ngrok:
175
- run_pip("install pyngrok", "ngrok")
176
-
177
- os.makedirs(dir_repos, exist_ok=True)
178
-
179
- git_clone(stable_diffusion_repo, repo_dir('stable-diffusion'), "Stable Diffusion", stable_diffusion_commit_hash)
180
- git_clone(taming_transformers_repo, repo_dir('taming-transformers'), "Taming Transformers", taming_transformers_commit_hash)
181
- git_clone(k_diffusion_repo, repo_dir('k-diffusion'), "K-diffusion", k_diffusion_commit_hash)
182
- git_clone(codeformer_repo, repo_dir('CodeFormer'), "CodeFormer", codeformer_commit_hash)
183
- git_clone(blip_repo, repo_dir('BLIP'), "BLIP", blip_commit_hash)
184
-
185
- if not is_installed("lpips"):
186
- run_pip(f"install -r {os.path.join(repo_dir('CodeFormer'), 'requirements.txt')}", "requirements for CodeFormer")
187
-
188
- run_pip(f"install -r {requirements_file}", "requirements for Web UI")
189
-
190
- if update_check:
191
- version_check(commit)
192
-
193
- if "--exit" in sys.argv:
194
- print("Exiting because of --exit argument")
195
- exit(0)
196
-
197
-
198
- def start_webui():
199
- print(f"Launching Web UI with arguments: {' '.join(sys.argv[1:])}")
200
- import webui
201
- webui.webui()
202
-
203
-
204
- if __name__ == "__main__":
205
- prepare_enviroment()
206
- start_webui()