| ''' |
| Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git |
| Date: 2023-09-30 13:25:39 |
| LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git |
| LastEditTime: 2023-09-30 21:20:54 |
| FilePath: \AI绘图配置\SDW\SW_run.py |
| Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE |
| ''' |
| import subprocess |
| import sys |
| import logging |
| import os |
| import binascii |
| import re |
|
|
| from pathlib import Path |
|
|
| |
| log_file = '/root/main/logs_run.txt' |
| if os.path.exists(log_file): |
| os.remove(log_file) |
|
|
| |
| url_file = '/root/main/url.txt' |
| if os.path.exists(url_file): |
| os.remove(url_file) |
|
|
| |
| logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') |
|
|
| |
| console_handler = logging.StreamHandler(sys.stdout) |
| console_handler.setLevel(logging.INFO) |
| formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') |
| console_handler.setFormatter(formatter) |
| logging.getLogger().addHandler(console_handler) |
|
|
| |
| sys.stdout = logging.getLogger().handlers[0].stream |
| sys.stderr = logging.getLogger().handlers[0].stream |
|
|
| |
| os.chdir('/root/main/') |
|
|
| try: |
| |
| with open(log_file, 'a') as log_file_handle, open(url_file, 'a') as url_file_handle: |
| |
| process = subprocess.Popen(['python', '/root/main/webui.py', '--api', '--disable-safe-unpickle', '--enable-insecure-extension-access', '--no-download-sd-model', '--no-half-vae', '--xformers', '--disable-console-progressbars', '--theme', 'dark', '--upcast-sampling', '--device-id=0,1'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) |
|
|
| url_pattern = re.compile(r'https?://\S+') |
|
|
| for line in process.stdout: |
| if "Public" in line or "Application" in line: |
| |
| hex_line = binascii.hexlify(line.encode()).decode() |
| url_file_handle.write(hex_line + '\n') |
| else: |
| |
| urls = url_pattern.findall(line) |
| if urls: |
| for url in urls: |
| hex_url = binascii.hexlify(url.encode()).decode() |
| url_file_handle.write(hex_url + '\n') |
|
|
| |
| log_file_handle.write(line) |
| log_file_handle.flush() |
|
|
| process.wait() |
|
|
| except subprocess.CalledProcessError as e: |
| |
| logging.exception(f"程序发生异常: {e}") |
| except Exception as e: |
| |
| logging.exception(f"程序发生异常: {e}") |
| finally: |
| |
| logging.getLogger().removeHandler(console_handler) |
| console_handler.close() |
|
|