Upload launch.py
Browse files
launch.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from modules import launch_utils
|
2 |
+
import os
|
3 |
+
import subprocess
|
4 |
+
import threading
|
5 |
+
|
6 |
+
args = launch_utils.args
|
7 |
+
python = launch_utils.python
|
8 |
+
git = launch_utils.git
|
9 |
+
index_url = launch_utils.index_url
|
10 |
+
dir_repos = launch_utils.dir_repos
|
11 |
+
|
12 |
+
commit_hash = launch_utils.commit_hash
|
13 |
+
git_tag = launch_utils.git_tag
|
14 |
+
|
15 |
+
run = launch_utils.run
|
16 |
+
is_installed = launch_utils.is_installed
|
17 |
+
repo_dir = launch_utils.repo_dir
|
18 |
+
|
19 |
+
run_pip = launch_utils.run_pip
|
20 |
+
check_run_python = launch_utils.check_run_python
|
21 |
+
git_clone = launch_utils.git_clone
|
22 |
+
git_pull_recursive = launch_utils.git_pull_recursive
|
23 |
+
list_extensions = launch_utils.list_extensions
|
24 |
+
run_extension_installer = launch_utils.run_extension_installer
|
25 |
+
prepare_environment = launch_utils.prepare_environment
|
26 |
+
configure_for_tests = launch_utils.configure_for_tests
|
27 |
+
start = launch_utils.start
|
28 |
+
|
29 |
+
util_py_path = '/content/ui/repositories/diffusion-stability-stable/ldm/util.py'
|
30 |
+
|
31 |
+
# 创建一个线程,用于实时查找并打印链接
|
32 |
+
def find_and_print_links():
|
33 |
+
while True:
|
34 |
+
line = log_process.stdout.readline().decode("utf-8")
|
35 |
+
if "Public WebUI Colab URL" in line:
|
36 |
+
url = line.split("Public WebUI Colab URL: ")[1].strip()
|
37 |
+
print(url)
|
38 |
+
|
39 |
+
# 打开日志文件以写入程序的所有输出
|
40 |
+
log_file_path = '/content/logs_run.txt'
|
41 |
+
log_file = open(log_file_path, 'w')
|
42 |
+
|
43 |
+
# 使用tee命令将程序的输出同时写入日志文件和进程管道
|
44 |
+
tee_command = f"{python} -u -m tee {log_file_path}"
|
45 |
+
log_process = subprocess.Popen(tee_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True)
|
46 |
+
|
47 |
+
def main():
|
48 |
+
if not args.skip_prepare_environment:
|
49 |
+
prepare_environment()
|
50 |
+
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
|
51 |
+
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
|
52 |
+
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
|
53 |
+
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
|
54 |
+
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
|
55 |
+
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
|
56 |
+
|
57 |
+
if args.test_server:
|
58 |
+
configure_for_tests()
|
59 |
+
|
60 |
+
start()
|
61 |
+
|
62 |
+
if __name__ == "__main__":
|
63 |
+
# 创建线程用于实时查找并打印链接
|
64 |
+
link_thread = threading.Thread(target=find_and_print_links)
|
65 |
+
link_thread.daemon = True # 设置为守护线程,程序退出时自动结束
|
66 |
+
link_thread.start()
|
67 |
+
|
68 |
+
main()
|
69 |
+
|
70 |
+
# 等待程序执行完毕
|
71 |
+
log_process.wait()
|
72 |
+
|
73 |
+
# 关闭日志文件
|
74 |
+
log_file.close()
|