SW / launch.py
BBrother's picture
Update launch.py
da266e7
raw
history blame
No virus
2.72 kB
from modules import launch_utils
import os
import subprocess
import threading
args = launch_utils.args
python = launch_utils.python
git = launch_utils.git
index_url = launch_utils.index_url
dir_repos = launch_utils.dir_repos
commit_hash = launch_utils.commit_hash
git_tag = launch_utils.git_tag
run = launch_utils.run
is_installed = launch_utils.is_installed
repo_dir = launch_utils.repo_dir
run_pip = launch_utils.run_pip
check_run_python = launch_utils.check_run_python
git_clone = launch_utils.git_clone
git_pull_recursive = launch_utils.git_pull_recursive
list_extensions = launch_utils.list_extensions
run_extension_installer = launch_utils.run_extension_installer
prepare_environment = launch_utils.prepare_environment
configure_for_tests = launch_utils.configure_for_tests
start = launch_utils.start
util_py_path = '/content/ui/repositories/diffusion-stability-stable/ldm/util.py'
# 创建一个线程,用于实时查找并打印链接
def find_and_print_links():
while True:
line = log_process.stdout.readline()
if "Public WebUI Colab URL" in line:
url = line.split("Public WebUI Colab URL: ")[1].strip()
print(url)
# 打开日志文件以写入程序的所有输出
log_file_path = '/content/logs_run.txt'
log_file = open(log_file_path, 'w')
# 使用tee命令将程序的输出同时写入日志文件和进程管道
tee_command = f"{python} -u -m tee {log_file_path}"
log_process = subprocess.Popen(tee_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True)
def main():
if not args.skip_prepare_environment:
prepare_environment()
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py")
if args.test_server:
configure_for_tests()
start()
if __name__ == "__main__":
# 创建线程用于实时查找并打印链接
link_thread = threading.Thread(target=find_and_print_links)
link_thread.daemon = True # 设置为守护线程,程序退出时自动结束
link_thread.start()
main()
# 等待程序执行完毕
log_process.wait()
# 关闭日志文件
log_file.close()