# -*- coding: utf-8 -*- # Copyright @ 2023 wdcqc/aieud project. # Open-source under license obtainable in project root (LICENSE.md). import subprocess # taken from automatic1111 UI def run(command, desc=None, errdesc=None, custom_env=None): if desc is not None: print(desc) result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env) if result.returncode != 0: message = f"""{errdesc or 'Error running command'}. Command: {command} Error code: {result.returncode} stdout: {result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stdout)>0 else ''} stderr: {result.stderr.decode(encoding="utf8", errors="ignore") if len(result.stderr)>0 else ''} """ raise RuntimeError(message) return result.stdout.decode(encoding="utf8", errors="ignore") # taken from automatic1111 UI def check_run(command): result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) return result.returncode == 0 # taken from automatic1111 UI, didn't even fix the TODO def git_clone(url, dir, name, commithash=None): # TODO clone into temporary dir and move if successful git = os.environ.get('GIT', "git") if os.path.exists(dir): if commithash is None: return current_hash = run(f'"{git}" -C {dir} rev-parse HEAD', None, f"Couldn't determine {name}'s hash: {commithash}").strip() if current_hash == commithash: return run(f'"{git}" -C {dir} fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}") run(f'"{git}" -C {dir} checkout {commithash}', f"Checking out commit for {name} with hash: {commithash}...", f"Couldn't checkout commit {commithash} for {name}") return run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}") if commithash is not None: run(f'"{git}" -C {dir} checkout {commithash}', None, "Couldn't checkout {name}'s hash: {commithash}") if __name__ == "__main__": import time import argparse git_clone("https://github.com/wdcqc/WaveFunctionDiffusion.git", ".", "WaveFunctionDiffusion") time.sleep(5.88) from wfd.webui import start_demo parser = argparse.ArgumentParser(description="Demo script for WaveFunctionDiffusion.") parser.add_argument( "--colab", action="store_true", help="Use it in Google Colab.", ) args = parser.parse_args() start_demo(args)