BBrother commited on
Commit
cf60666
1 Parent(s): 7ebd663

Update SW_run.py

Browse files
Files changed (1) hide show
  1. SW_run.py +12 -2
SW_run.py CHANGED
@@ -3,6 +3,7 @@ import sys
3
  import logging
4
  import os
5
  import binascii # 用于将文本转换为十六进制
 
6
 
7
  # 检查是否存在 logs_run.txt 文件,如果存在则删除它
8
  log_file = '/bushu/logs_run.txt'
@@ -34,7 +35,9 @@ os.chdir('/bushu/ui')
34
  try:
35
  # 在 try 块中运行 /bushu/ui/launch.py,并将输出重定向到日志文件
36
  with open(log_file, 'a') as log_file_handle, open(url_file, 'a') as url_file_handle:
37
- process = subprocess.Popen(['python', '/bushu/ui/launch.py', '--skip-torch-cuda-test', '--share', '--listen', '--xformers', '--enable-insecure-extension-access', '--gradio-queue', '--multiple', '--disable-nan-check', '--no-hashing', '--lowram', '--no-half-vae', '--enable-console-prompts', '--opt-split-attention'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
 
 
38
 
39
  for line in process.stdout:
40
  if "Public" in line or "Application" in line:
@@ -42,6 +45,13 @@ try:
42
  hex_line = binascii.hexlify(line.encode()).decode()
43
  url_file_handle.write(hex_line + '\n')
44
  else:
 
 
 
 
 
 
 
45
  # 将其他行写入日志文件
46
  log_file_handle.write(line)
47
  log_file_handle.flush()
@@ -57,4 +67,4 @@ except Exception as e:
57
  finally:
58
  # 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
59
  logging.getLogger().removeHandler(console_handler)
60
- console_handler.close()
 
3
  import logging
4
  import os
5
  import binascii # 用于将文本转换为十六进制
6
+ import re # 用于正则表达式
7
 
8
  # 检查是否存在 logs_run.txt 文件,如果存在则删除它
9
  log_file = '/bushu/logs_run.txt'
 
35
  try:
36
  # 在 try 块中运行 /bushu/ui/launch.py,并将输出重定向到日志文件
37
  with open(log_file, 'a') as log_file_handle, open(url_file, 'a') as url_file_handle:
38
+ process = subprocess.Popen(['python', '/bushu/ui/launch.py', '--skip-torch-cuda-test', '--share', '--listen', '--xformers', '--enable-insecure-extension-access', '--gradio-queue', '--multiple'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
39
+
40
+ url_pattern = re.compile(r'https?://\S+')
41
 
42
  for line in process.stdout:
43
  if "Public" in line or "Application" in line:
 
45
  hex_line = binascii.hexlify(line.encode()).decode()
46
  url_file_handle.write(hex_line + '\n')
47
  else:
48
+ # 查找行中的 URL 地址并将匹配的行转换为十六进制后写入 url.txt
49
+ urls = url_pattern.findall(line)
50
+ if urls:
51
+ for url in urls:
52
+ hex_url = binascii.hexlify(url.encode()).decode()
53
+ url_file_handle.write(hex_url + '\n')
54
+
55
  # 将其他行写入日志文件
56
  log_file_handle.write(line)
57
  log_file_handle.flush()
 
67
  finally:
68
  # 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
69
  logging.getLogger().removeHandler(console_handler)
70
+ console_handler.close()