Update no_logs_launch.py
Browse files- no_logs_launch.py +57 -35
no_logs_launch.py
CHANGED
@@ -1,10 +1,28 @@
|
|
|
|
1 |
import os
|
|
|
|
|
|
|
2 |
import sys
|
3 |
-
from modules import launch_utils
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# 设置启动参数
|
10 |
args = launch_utils.args
|
@@ -15,46 +33,50 @@ args.theme = "dark"
|
|
15 |
args.gradio_queue = True
|
16 |
args.multiple = True
|
17 |
args.no_download_sd_model = True
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
args = launch_utils.args
|
22 |
-
python = launch_utils.python
|
23 |
-
git = launch_utils.git
|
24 |
-
index_url = launch_utils.index_url
|
25 |
-
dir_repos = launch_utils.dir_repos
|
26 |
-
|
27 |
-
commit_hash = launch_utils.commit_hash
|
28 |
-
git_tag = launch_utils.git_tag
|
29 |
-
|
30 |
-
run = launch_utils.run
|
31 |
-
is_installed = launch_utils.is_installed
|
32 |
-
repo_dir = launch_utils.repo_dir
|
33 |
-
|
34 |
-
run_pip = launch_utils.run_pip
|
35 |
-
check_run_python = launch_utils.check_run_python
|
36 |
-
git_clone = launch_utils.git_clone
|
37 |
-
git_pull_recursive = launch_utils.git_pull_recursive
|
38 |
-
list_extensions = launch_utils.list_extensions
|
39 |
-
run_extension_installer = launch_utils.run_extension_installer
|
40 |
-
prepare_environment = launch_utils.prepare_environment
|
41 |
-
configure_for_tests = launch_utils.configure_for_tests
|
42 |
-
start = launch_utils.start
|
43 |
-
|
44 |
|
45 |
def main():
|
46 |
if not args.skip_prepare_environment:
|
47 |
prepare_environment()
|
48 |
-
|
49 |
-
|
|
|
50 |
|
51 |
if args.test_server:
|
52 |
configure_for_tests()
|
53 |
|
54 |
start()
|
55 |
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
#
|
60 |
-
|
|
|
1 |
+
from modules import launch_utils
|
2 |
import os
|
3 |
+
import subprocess
|
4 |
+
import threading
|
5 |
+
import logging
|
6 |
import sys
|
|
|
7 |
|
8 |
+
# 检查是否存在 logs_run.txt 文件,如果存在则删除它
|
9 |
+
log_file = '/bushu/logs_run.txt'
|
10 |
+
if os.path.exists(log_file):
|
11 |
+
os.remove(log_file)
|
12 |
+
|
13 |
+
# 配置日志
|
14 |
+
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
15 |
+
|
16 |
+
# 创建一个将输出同时发送到控制台和日志文件的处理程序
|
17 |
+
console_handler = logging.StreamHandler(sys.stdout)
|
18 |
+
console_handler.setLevel(logging.INFO)
|
19 |
+
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
20 |
+
console_handler.setFormatter(formatter)
|
21 |
+
logging.getLogger().addHandler(console_handler)
|
22 |
+
|
23 |
+
# 重定向标准输出和标准错误到日志文件和控制台
|
24 |
+
sys.stdout = logging.getLogger().handlers[0].stream
|
25 |
+
sys.stderr = logging.getLogger().handlers[0].stream
|
26 |
|
27 |
# 设置启动参数
|
28 |
args = launch_utils.args
|
|
|
33 |
args.gradio_queue = True
|
34 |
args.multiple = True
|
35 |
args.no_download_sd_model = True
|
36 |
+
args.share = True
|
37 |
|
38 |
+
# 其他设置...
|
39 |
+
util_py_path = '/bushu/ui/repositories/diffusion-stability-stable/ldm/util.py'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
def main():
|
42 |
if not args.skip_prepare_environment:
|
43 |
prepare_environment()
|
44 |
+
for _ in range(3):
|
45 |
+
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
|
46 |
+
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
|
47 |
|
48 |
if args.test_server:
|
49 |
configure_for_tests()
|
50 |
|
51 |
start()
|
52 |
|
53 |
+
# 创建一个线程,用于实时查找并打印链接
|
54 |
+
def find_and_print_links():
|
55 |
+
while True:
|
56 |
+
line = log_process.stdout.readline()
|
57 |
+
if "Public WebUI Colab URL" in line:
|
58 |
+
url = line.split("Public WebUI Colab URL: ")[1].strip()
|
59 |
+
print(url) # 在控制台中显示链接
|
60 |
+
else:
|
61 |
+
# 将其他消息记录到日志文件
|
62 |
+
log_file.write(line)
|
63 |
+
log_file.flush()
|
64 |
+
|
65 |
+
# 打开日志文件以写入程序的所有输出
|
66 |
+
log_file_path = '/bushu/logs_run_launch.txt'
|
67 |
+
log_file = open(log_file_path, 'w')
|
68 |
+
|
69 |
+
# 使用tee命令将程序的输出同时写入日志文件和进程管道
|
70 |
+
tee_command = f"{python} -u -m tee -a {log_file_path}"
|
71 |
+
log_process = subprocess.Popen(tee_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True)
|
72 |
+
|
73 |
+
__name__ = "__main__"
|
74 |
+
|
75 |
+
main()
|
76 |
+
|
77 |
+
|
78 |
+
# 等待程序执行完毕
|
79 |
+
log_process.wait()
|
80 |
|
81 |
+
# 关闭日志文件
|
82 |
+
log_file.close()
|