Spaces:
Running
Running
Delete launcher.py
Browse files- launcher.py +0 -204
launcher.py
DELETED
@@ -1,204 +0,0 @@
|
|
1 |
-
# this scripts installs necessary requirements and launches main program in webui.py
|
2 |
-
# borrow from : https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/launch.py
|
3 |
-
import subprocess
|
4 |
-
import os
|
5 |
-
import sys
|
6 |
-
import importlib.util
|
7 |
-
import shlex
|
8 |
-
import platform
|
9 |
-
import json
|
10 |
-
|
11 |
-
python = sys.executable
|
12 |
-
git = os.environ.get('GIT', "git")
|
13 |
-
index_url = os.environ.get('INDEX_URL', "")
|
14 |
-
stored_commit_hash = None
|
15 |
-
skip_install = False
|
16 |
-
dir_repos = "repositories"
|
17 |
-
script_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
18 |
-
|
19 |
-
if 'GRADIO_ANALYTICS_ENABLED' not in os.environ:
|
20 |
-
os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False'
|
21 |
-
|
22 |
-
|
23 |
-
def check_python_version():
|
24 |
-
is_windows = platform.system() == "Windows"
|
25 |
-
major = sys.version_info.major
|
26 |
-
minor = sys.version_info.minor
|
27 |
-
micro = sys.version_info.micro
|
28 |
-
|
29 |
-
if is_windows:
|
30 |
-
supported_minors = [10]
|
31 |
-
else:
|
32 |
-
supported_minors = [7, 8, 9, 10, 11]
|
33 |
-
|
34 |
-
if not (major == 3 and minor in supported_minors):
|
35 |
-
|
36 |
-
raise (f"""
|
37 |
-
INCOMPATIBLE PYTHON VERSION
|
38 |
-
This program is tested with 3.10.6 Python, but you have {major}.{minor}.{micro}.
|
39 |
-
If you encounter an error with "RuntimeError: Couldn't install torch." message,
|
40 |
-
or any other error regarding unsuccessful package (library) installation,
|
41 |
-
please downgrade (or upgrade) to the latest version of 3.10 Python
|
42 |
-
and delete current Python and "venv" folder in WebUI's directory.
|
43 |
-
You can download 3.10 Python from here: https://www.python.org/downloads/release/python-3109/
|
44 |
-
{"Alternatively, use a binary release of WebUI: https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases" if is_windows else ""}
|
45 |
-
Use --skip-python-version-check to suppress this warning.
|
46 |
-
""")
|
47 |
-
|
48 |
-
|
49 |
-
def commit_hash():
|
50 |
-
global stored_commit_hash
|
51 |
-
|
52 |
-
if stored_commit_hash is not None:
|
53 |
-
return stored_commit_hash
|
54 |
-
|
55 |
-
try:
|
56 |
-
stored_commit_hash = run(f"{git} rev-parse HEAD").strip()
|
57 |
-
except Exception:
|
58 |
-
stored_commit_hash = "<none>"
|
59 |
-
|
60 |
-
return stored_commit_hash
|
61 |
-
|
62 |
-
|
63 |
-
def run(command, desc=None, errdesc=None, custom_env=None, live=False):
|
64 |
-
if desc is not None:
|
65 |
-
print(desc)
|
66 |
-
|
67 |
-
if live:
|
68 |
-
result = subprocess.run(command, shell=True, env=os.environ if custom_env is None else custom_env)
|
69 |
-
if result.returncode != 0:
|
70 |
-
raise RuntimeError(f"""{errdesc or 'Error running command'}.
|
71 |
-
Command: {command}
|
72 |
-
Error code: {result.returncode}""")
|
73 |
-
|
74 |
-
return ""
|
75 |
-
|
76 |
-
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env)
|
77 |
-
|
78 |
-
if result.returncode != 0:
|
79 |
-
|
80 |
-
message = f"""{errdesc or 'Error running command'}.
|
81 |
-
Command: {command}
|
82 |
-
Error code: {result.returncode}
|
83 |
-
stdout: {result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stdout)>0 else '<empty>'}
|
84 |
-
stderr: {result.stderr.decode(encoding="utf8", errors="ignore") if len(result.stderr)>0 else '<empty>'}
|
85 |
-
"""
|
86 |
-
raise RuntimeError(message)
|
87 |
-
|
88 |
-
return result.stdout.decode(encoding="utf8", errors="ignore")
|
89 |
-
|
90 |
-
|
91 |
-
def check_run(command):
|
92 |
-
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
93 |
-
return result.returncode == 0
|
94 |
-
|
95 |
-
|
96 |
-
def is_installed(package):
|
97 |
-
try:
|
98 |
-
spec = importlib.util.find_spec(package)
|
99 |
-
except ModuleNotFoundError:
|
100 |
-
return False
|
101 |
-
|
102 |
-
return spec is not None
|
103 |
-
|
104 |
-
|
105 |
-
def repo_dir(name):
|
106 |
-
return os.path.join(script_path, dir_repos, name)
|
107 |
-
|
108 |
-
|
109 |
-
def run_python(code, desc=None, errdesc=None):
|
110 |
-
return run(f'"{python}" -c "{code}"', desc, errdesc)
|
111 |
-
|
112 |
-
|
113 |
-
def run_pip(args, desc=None):
|
114 |
-
if skip_install:
|
115 |
-
return
|
116 |
-
|
117 |
-
index_url_line = f' --index-url {index_url}' if index_url != '' else ''
|
118 |
-
return run(f'"{python}" -m pip {args} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}")
|
119 |
-
|
120 |
-
|
121 |
-
def check_run_python(code):
|
122 |
-
return check_run(f'"{python}" -c "{code}"')
|
123 |
-
|
124 |
-
|
125 |
-
def git_clone(url, dir, name, commithash=None):
|
126 |
-
# TODO clone into temporary dir and move if successful
|
127 |
-
|
128 |
-
if os.path.exists(dir):
|
129 |
-
if commithash is None:
|
130 |
-
return
|
131 |
-
|
132 |
-
current_hash = run(f'"{git}" -C "{dir}" rev-parse HEAD', None, f"Couldn't determine {name}'s hash: {commithash}").strip()
|
133 |
-
if current_hash == commithash:
|
134 |
-
return
|
135 |
-
|
136 |
-
run(f'"{git}" -C "{dir}" fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}")
|
137 |
-
run(f'"{git}" -C "{dir}" checkout {commithash}', f"Checking out commit for {name} with hash: {commithash}...", f"Couldn't checkout commit {commithash} for {name}")
|
138 |
-
return
|
139 |
-
|
140 |
-
run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}")
|
141 |
-
|
142 |
-
if commithash is not None:
|
143 |
-
run(f'"{git}" -C "{dir}" checkout {commithash}', None, "Couldn't checkout {name}'s hash: {commithash}")
|
144 |
-
|
145 |
-
|
146 |
-
def git_pull_recursive(dir):
|
147 |
-
for subdir, _, _ in os.walk(dir):
|
148 |
-
if os.path.exists(os.path.join(subdir, '.git')):
|
149 |
-
try:
|
150 |
-
output = subprocess.check_output([git, '-C', subdir, 'pull', '--autostash'])
|
151 |
-
print(f"Pulled changes for repository in '{subdir}':\n{output.decode('utf-8').strip()}\n")
|
152 |
-
except subprocess.CalledProcessError as e:
|
153 |
-
print(f"Couldn't perform 'git pull' on repository in '{subdir}':\n{e.output.decode('utf-8').strip()}\n")
|
154 |
-
|
155 |
-
|
156 |
-
def run_extension_installer(extension_dir):
|
157 |
-
path_installer = os.path.join(extension_dir, "install.py")
|
158 |
-
if not os.path.isfile(path_installer):
|
159 |
-
return
|
160 |
-
|
161 |
-
try:
|
162 |
-
env = os.environ.copy()
|
163 |
-
env['PYTHONPATH'] = os.path.abspath(".")
|
164 |
-
|
165 |
-
print(run(f'"{python}" "{path_installer}"', errdesc=f"Error running install.py for extension {extension_dir}", custom_env=env))
|
166 |
-
except Exception as e:
|
167 |
-
print(e, file=sys.stderr)
|
168 |
-
|
169 |
-
|
170 |
-
def prepare_environment():
|
171 |
-
global skip_install
|
172 |
-
|
173 |
-
torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113")
|
174 |
-
|
175 |
-
## check windows
|
176 |
-
if sys.platform != 'win32':
|
177 |
-
requirements_file = os.environ.get('REQS_FILE', "req.txt")
|
178 |
-
else:
|
179 |
-
requirements_file = os.environ.get('REQS_FILE', "requirements.txt")
|
180 |
-
|
181 |
-
commit = commit_hash()
|
182 |
-
|
183 |
-
print(f"Python {sys.version}")
|
184 |
-
print(f"Commit hash: {commit}")
|
185 |
-
|
186 |
-
if not is_installed("torch") or not is_installed("torchvision"):
|
187 |
-
run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True)
|
188 |
-
|
189 |
-
run_pip(f"install -r \"{requirements_file}\"", "requirements for SadTalker WebUI (may take longer time in first time)")
|
190 |
-
|
191 |
-
if sys.platform != 'win32' and not is_installed('tts'):
|
192 |
-
run_pip(f"install TTS", "install TTS individually in SadTalker, which might not work on windows.")
|
193 |
-
|
194 |
-
|
195 |
-
def start():
|
196 |
-
print(f"Launching SadTalker Web UI")
|
197 |
-
from app_sadtalker import sadtalker_demo
|
198 |
-
demo = sadtalker_demo()
|
199 |
-
demo.queue()
|
200 |
-
demo.launch()
|
201 |
-
|
202 |
-
if __name__ == "__main__":
|
203 |
-
prepare_environment()
|
204 |
-
start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|