SW / SW_run.py
BBrother's picture
Update SW_run.py
74ba676
raw
history blame
No virus
997 Bytes
import subprocess
import logging
import re
# 配置日志
logging.basicConfig(filename='logs_run.txt', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# 执行第二个命令,并捕获输出
proc = subprocess.Popen(['python', '/content/ui/launch.py', '--listen', '--xformers', '--enable-insecure-extension-access',
'--theme', 'dark', '--gradio-queue', '--no-download-sd-model', '--share'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# 读取输出并捕获地址
while True:
output = proc.stdout.readline().strip()
if not output:
break
# 记录输出到日志
logging.info(output)
# 查找 "Public WebUI Colab URL" 字符串
match = re.search(r'Public WebUI Colab URL: (.+)', output)
if match:
url = match.group(1)
print(url) # 打印地址到控制台
# 等待程序执行完成
proc.wait()
# 关闭日志处理程序
logging.shutdown()