File size: 997 Bytes
56beff2
 
 
 
 
 
 
 
 
74ba676
 
56beff2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()