Upload SW_run.py
Browse files
SW_run.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import logging
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
# 配置日志
|
| 6 |
+
logging.basicConfig(filename='logs_run.txt', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 7 |
+
|
| 8 |
+
# 执行第二个命令,并捕获输出
|
| 9 |
+
proc = subprocess.Popen(['python', '/content/ui/launch.py', '--listen', '--xformers', '--enable-insecure-extension-access',
|
| 10 |
+
'--theme', 'dark', '--gradio-queue', '--no-download-sd-model', '--share'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
| 11 |
+
|
| 12 |
+
# 读取输出并捕获地址
|
| 13 |
+
while True:
|
| 14 |
+
output = proc.stdout.readline().strip()
|
| 15 |
+
if not output:
|
| 16 |
+
break
|
| 17 |
+
|
| 18 |
+
# 记录输出到日志
|
| 19 |
+
logging.info(output)
|
| 20 |
+
|
| 21 |
+
# 查找 "Public WebUI Colab URL" 字符串
|
| 22 |
+
match = re.search(r'Public WebUI Colab URL: (.+)', output)
|
| 23 |
+
if match:
|
| 24 |
+
url = match.group(1)
|
| 25 |
+
print(url) # 打印地址到控制台
|
| 26 |
+
|
| 27 |
+
# 等待程序执行完成
|
| 28 |
+
proc.wait()
|
| 29 |
+
|
| 30 |
+
# 关闭日志处理程序
|
| 31 |
+
logging.shutdown()
|