|
from modules import launch_utils |
|
import os |
|
import subprocess |
|
import threading |
|
import logging |
|
import sys |
|
|
|
|
|
|
|
log_file = '/bushu/logs_run.txt' |
|
if os.path.exists(log_file): |
|
os.remove(log_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 |
|
|
|
|
|
subprocess.run(["cd", "/bushu/ui"], shell=True) |
|
|
|
try: |
|
|
|
with open(log_file, 'a') as log_file_handle: |
|
subprocess.run(['python', '/bushu/ui/launch.py'], check=True, stdout=log_file_handle, stderr=subprocess.STDOUT) |
|
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() |
|
|
|
|
|
args = launch_utils.args |
|
args.listen = True |
|
args.xformers = True |
|
args.enable_insecure_extension_access = True |
|
args.theme = "dark" |
|
args.gradio_queue = True |
|
args.multiple = True |
|
args.no_download_sd_model = True |
|
args.share = True |
|
|
|
python = launch_utils.python |
|
git = launch_utils.git |
|
index_url = launch_utils.index_url |
|
dir_repos = launch_utils.dir_repos |
|
|
|
commit_hash = launch_utils.commit_hash |
|
git_tag = launch_utils.git_tag |
|
|
|
run = launch_utils.run |
|
is_installed = launch_utils.is_installed |
|
repo_dir = launch_utils.repo_dir |
|
|
|
run_pip = launch_utils.run_pip |
|
check_run_python = launch_utils.check_run_python |
|
git_clone = launch_utils.git_clone |
|
git_pull_recursive = launch_utils.git_pull_recursive |
|
list_extensions = launch_utils.list_extensions |
|
run_extension_installer = launch_utils.run_extension_installer |
|
prepare_environment = launch_utils.prepare_environment |
|
configure_for_tests = launch_utils.configure_for_tests |
|
start = launch_utils.start |
|
|
|
util_py_path = '/bushu/ui/repositories/diffusion-stability-stable/ldm/util.py' |
|
|
|
|
|
log_file_path = '/bushu/logs_run_launch.txt' |
|
log_file = open(log_file_path, 'w') |
|
|
|
|
|
def find_and_print_links(): |
|
while True: |
|
line = log_process.stdout.readline() |
|
if "Public WebUI Colab URL" in line: |
|
url = line.split("Public WebUI Colab URL: ")[1].strip() |
|
print(url) |
|
else: |
|
|
|
log_file.write(line) |
|
log_file.flush() |
|
|
|
|
|
tee_command = f"{python} -u -m tee -a {log_file_path}" |
|
log_process = subprocess.Popen(tee_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True) |
|
|
|
def main(): |
|
if not args.skip_prepare_environment: |
|
prepare_environment() |
|
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}") |
|
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py") |
|
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}") |
|
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py") |
|
os.system(f"sed -i -e 's/dict()))/dict())).cuda()/g' {util_py_path}") |
|
os.system(f"sed -i -e 's/stable/dict()))/dict())).cuda()/g' /content/ui/repositories/diffusion-stability-stable/ldm/util.py") |
|
|
|
if args.test_server: |
|
configure_for_tests() |
|
|
|
start() |
|
|
|
|
|
def find_and_print_links(): |
|
while True: |
|
line = log_process.stdout.readline() |
|
if "Public WebUI Colab URL" in line: |
|
url = line.split("Public WebUI Colab URL: ")[1].strip() |
|
print(url) |
|
else: |
|
|
|
log_file.write(line) |
|
log_file.flush() |
|
|
|
|
|
main() |
|
|
|
|
|
log_process.wait() |
|
|
|
|
|
log_file.close() |