Update SW_run.py
Browse files
SW_run.py
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
|
|
|
|
|
| 1 |
import subprocess
|
| 2 |
-
import
|
| 3 |
import logging
|
| 4 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
log_file = '/bushu/logs_run.txt'
|
| 8 |
-
if os.path.exists(log_file):
|
| 9 |
-
os.remove(log_file)
|
| 10 |
-
|
| 11 |
-
# 检查是否存在 url.txt 文件,如果存在则删除它
|
| 12 |
-
url_file = '/bushu/url.txt'
|
| 13 |
-
if os.path.exists(url_file):
|
| 14 |
-
os.remove(url_file)
|
| 15 |
-
|
| 16 |
-
# 配置日志
|
| 17 |
-
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 18 |
-
|
| 19 |
-
# 创建一个将输出同时发送到控制台和日志文件的处理程序
|
| 20 |
-
console_handler = logging.StreamHandler(sys.stdout)
|
| 21 |
-
console_handler.setLevel(logging.INFO)
|
| 22 |
-
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
|
| 23 |
-
console_handler.setFormatter(formatter)
|
| 24 |
-
logging.getLogger().addHandler(console_handler)
|
| 25 |
-
|
| 26 |
-
# 重定向标准输出和标准错误到日志文件和控制台
|
| 27 |
-
sys.stdout = logging.getLogger().handlers[0].stream
|
| 28 |
-
sys.stderr = logging.getLogger().handlers[0].stream
|
| 29 |
-
|
| 30 |
-
# 切换到/bushu/ui目录
|
| 31 |
-
subprocess.run(["cd", "/bushu/ui"], shell=True)
|
| 32 |
-
|
| 33 |
-
try:
|
| 34 |
-
# 在try块中运行v2_3.py,并将输出重定向到日志文件
|
| 35 |
-
with open(log_file, 'a') as log_file_handle, open(url_file, 'a') as url_file_handle:
|
| 36 |
-
process = subprocess.Popen(['python', 'launch.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
| 37 |
-
for line in process.stdout:
|
| 38 |
-
if "Running on" in line:
|
| 39 |
-
# 如果日志行包含 "Running on",将它写入 url.txt 文件
|
| 40 |
-
url_file_handle.write(line)
|
| 41 |
-
else:
|
| 42 |
-
# 否则,将日志行写入 logs_run.txt 文件
|
| 43 |
-
log_file_handle.write(line)
|
| 44 |
-
log_file_handle.flush()
|
| 45 |
-
url_file_handle.flush()
|
| 46 |
-
process.wait()
|
| 47 |
-
except subprocess.CalledProcessError as e:
|
| 48 |
-
# 捕获异常并记录到日志文件
|
| 49 |
-
logging.exception(f"程序发生异常: {e}")
|
| 50 |
-
except Exception as e:
|
| 51 |
-
# 捕获其他异常并记录到日志文件
|
| 52 |
-
logging.exception(f"程序发生异常: {e}")
|
| 53 |
-
finally:
|
| 54 |
-
# 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
|
| 55 |
-
logging.getLogger().removeHandler(console_handler)
|
| 56 |
-
console_handler.close()
|
|
|
|
| 1 |
+
from modules import launch_utils
|
| 2 |
+
import os
|
| 3 |
import subprocess
|
| 4 |
+
import threading
|
| 5 |
import logging
|
| 6 |
+
import sys
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
# 设置启动参数
|
| 10 |
+
args = launch_utils.args
|
| 11 |
+
args.listen = True
|
| 12 |
+
args.xformers = True
|
| 13 |
+
args.enable_insecure_extension_access = True
|
| 14 |
+
args.theme = "dark"
|
| 15 |
+
args.gradio_queue = True
|
| 16 |
+
args.multiple = True
|
| 17 |
+
args.no_download_sd_model = True
|
| 18 |
+
args.share = True -o /bushu/out_url.txt
|
| 19 |
+
|
| 20 |
+
args = launch_utils.args
|
| 21 |
+
python = launch_utils.python
|
| 22 |
+
git = launch_utils.git
|
| 23 |
+
index_url = launch_utils.index_url
|
| 24 |
+
dir_repos = launch_utils.dir_repos
|
| 25 |
+
|
| 26 |
+
commit_hash = launch_utils.commit_hash
|
| 27 |
+
git_tag = launch_utils.git_tag
|
| 28 |
+
|
| 29 |
+
run = launch_utils.run
|
| 30 |
+
is_installed = launch_utils.is_installed
|
| 31 |
+
repo_dir = launch_utils.repo_dir
|
| 32 |
+
|
| 33 |
+
run_pip = launch_utils.run_pip
|
| 34 |
+
check_run_python = launch_utils.check_run_python
|
| 35 |
+
git_clone = launch_utils.git_clone
|
| 36 |
+
git_pull_recursive = launch_utils.git_pull_recursive
|
| 37 |
+
list_extensions = launch_utils.list_extensions
|
| 38 |
+
run_extension_installer = launch_utils.run_extension_installer
|
| 39 |
+
prepare_environment = launch_utils.prepare_environment
|
| 40 |
+
configure_for_tests = launch_utils.configure_for_tests
|
| 41 |
+
start = launch_utils.start
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def main():
|
| 45 |
+
if not args.skip_prepare_environment:
|
| 46 |
+
prepare_environment()
|
| 47 |
+
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}")
|
| 48 |
+
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /bushu/ui/repositories/diffusion-stability-stable/ldm/util.py")
|
| 49 |
+
|
| 50 |
+
if args.test_server:
|
| 51 |
+
configure_for_tests()
|
| 52 |
+
|
| 53 |
+
start()
|
| 54 |
+
|
| 55 |
|
| 56 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|