BBrother commited on
Commit
afd65b5
1 Parent(s): aa9f08a

Update launch.py

Browse files
Files changed (1) hide show
  1. launch.py +20 -104
launch.py CHANGED
@@ -5,14 +5,21 @@ import threading
5
  import logging
6
  import sys
7
 
 
 
 
 
 
 
 
 
 
8
 
9
- # 检查是否存在 logs_run.txt 文件,如果存在则删除它
10
- log_file = '/bushu/logs_run.txt'
11
- if os.path.exists(log_file):
12
- os.remove(log_file)
13
 
14
  # 配置日志
15
- logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
16
 
17
  # 创建一个将输出同时发送到控制台和日志文件的处理程序
18
  console_handler = logging.StreamHandler(sys.stdout)
@@ -25,111 +32,20 @@ logging.getLogger().addHandler(console_handler)
25
  sys.stdout = logging.getLogger().handlers[0].stream
26
  sys.stderr = logging.getLogger().handlers[0].stream
27
 
28
- # 切换到/bushu/ui目录
29
- subprocess.run(["cd", "/bushu/ui"], shell=True)
30
-
31
  try:
32
- # 在try块中运行v2_3.py,并将输出重定向到日志文件
33
- with open(log_file, 'a') as log_file_handle:
34
- subprocess.run(['python', '/bushu/ui/launch.py'], check=True, stdout=log_file_handle, stderr=subprocess.STDOUT)
35
- except subprocess.CalledProcessError as e:
36
- # 捕获异常并记录到日志文件
37
- logging.exception(f"程序发生异常: {e}")
38
- except Exception as e:
39
- # 捕获其他异常并记录到日志文件
40
- logging.exception(f"程序发生异常: {e}")
41
- finally:
42
- # 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
43
- logging.getLogger().removeHandler(console_handler)
44
- console_handler.close()
45
-
46
- # 设置启动参数
47
- args = launch_utils.args
48
- args.listen = True
49
- args.xformers = True
50
- args.enable_insecure_extension_access = True
51
- args.theme = "dark"
52
- args.gradio_queue = True
53
- args.multiple = True
54
- args.no_download_sd_model = True
55
- args.share = True
56
-
57
- python = launch_utils.python
58
- git = launch_utils.git
59
- index_url = launch_utils.index_url
60
- dir_repos = launch_utils.dir_repos
61
-
62
- commit_hash = launch_utils.commit_hash
63
- git_tag = launch_utils.git_tag
64
-
65
- run = launch_utils.run
66
- is_installed = launch_utils.is_installed
67
- repo_dir = launch_utils.repo_dir
68
-
69
- run_pip = launch_utils.run_pip
70
- check_run_python = launch_utils.check_run_python
71
- git_clone = launch_utils.git_clone
72
- git_pull_recursive = launch_utils.git_pull_recursive
73
- list_extensions = launch_utils.list_extensions
74
- run_extension_installer = launch_utils.run_extension_installer
75
- prepare_environment = launch_utils.prepare_environment
76
- configure_for_tests = launch_utils.configure_for_tests
77
- start = launch_utils.start
78
-
79
- util_py_path = '/bushu/ui/repositories/diffusion-stability-stable/ldm/util.py'
80
-
81
- # 打开日志文件以写入程序的所有输出
82
- log_file_path = '/bushu/logs_run_launch.txt'
83
- log_file = open(log_file_path, 'w')
84
-
85
- # 创建一个线程,用于实时查找并打印链接
86
- def find_and_print_links():
87
- while True:
88
- line = log_process.stdout.readline()
89
- if "Public WebUI Colab URL" in line:
90
- url = line.split("Public WebUI Colab URL: ")[1].strip()
91
- print(url) # 在控制台中显示链接
92
- else:
93
- # 将其他消息记录到日志文件
94
- log_file.write(line)
95
- log_file.flush()
96
-
97
- # 使用tee命令将程序的输出同时写入日志文件和进程管道
98
- tee_command = f"{python} -u -m tee -a {log_file_path}"
99
- log_process = subprocess.Popen(tee_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True)
100
-
101
- def main():
102
  if not args.skip_prepare_environment:
103
  prepare_environment()
104
  os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
105
- os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
106
- os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
107
- os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
108
- os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
109
- os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
110
 
111
  if args.test_server:
112
  configure_for_tests()
113
 
114
  start()
115
-
116
- # 创建一个线程,用于实时查找并打印链接
117
- def find_and_print_links():
118
- while True:
119
- line = log_process.stdout.readline()
120
- if "Public WebUI Colab URL" in line:
121
- url = line.split("Public WebUI Colab URL: ")[1].strip()
122
- print(url) # 在控制台中显示链接
123
- else:
124
- # 将其他消息记录��日志文件
125
- log_file.write(line)
126
- log_file.flush()
127
-
128
- # 调用 main() 函数,不再需要条件判断
129
- main()
130
-
131
- # 等待程序执行完毕
132
- log_process.wait()
133
-
134
- # 关闭日志文件
135
- log_file.close()
 
5
  import logging
6
  import sys
7
 
8
+ # 设置启动参数
9
+ args = launch_utils.args
10
+ args.listen = True
11
+ args.xformers = True
12
+ args.enable_insecure_extension_access = True
13
+ args.theme = "dark"
14
+ args.gradio_queue = True
15
+ args.multiple = True
16
+ args.no_download_sd_model = True
17
 
18
+ # 设置日志文件路径
19
+ log_file_path = '/bushu/logs_run.txt'
 
 
20
 
21
  # 配置日志
22
+ logging.basicConfig(filename=log_file_path, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
23
 
24
  # 创建一个将输出同时发送到控制台和日志文件的处理程序
25
  console_handler = logging.StreamHandler(sys.stdout)
 
32
  sys.stdout = logging.getLogger().handlers[0].stream
33
  sys.stderr = logging.getLogger().handlers[0].stream
34
 
 
 
 
35
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  if not args.skip_prepare_environment:
37
  prepare_environment()
38
  os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
39
+ os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /bushu/ui/repositories/diffusion-stability-stable/ldm/util.py")
 
 
 
 
40
 
41
  if args.test_server:
42
  configure_for_tests()
43
 
44
  start()
45
+ except Exception as e:
46
+ # 捕获其他异常并记录到日志文件
47
+ logging.exception(f"程序发生异常: {e}")
48
+ finally:
49
+ # 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
50
+ logging.getLogger().removeHandler(console_handler)
51
+ console_handler.close()