CoolFace
Apppublic

carloscar/stable-diffusion-webui-controlnet-docker

sourceHugging Faceupdated 4y agoView on Hugging Face
31likes
run.py56 linesDownload Raw Back to root
1import os2import subprocess3import sys4 5 6def on_start():7    print("---------------")8    print("Running script './on_start.sh' to download models ...")9    print("---------------")10    result = subprocess.run("./on_start.sh", shell=True, env=os.environ)11    if result.returncode != 0:12        raise RuntimeError(f"Error executing ./on_start.sh [exit code: {result.returncode}]")13 14 15def start():16    print("---------------")17    print(f"Launching {'API server' if '--nowebui' in sys.argv else 'Web UI'} with arguments: {' '.join(sys.argv[1:])}")18    print("---------------")19    import webui  # type: ignore  # noqa20 21    if "--nowebui" in sys.argv:22        webui.api_only()23    else:24        webui.webui()25 26 27def set_options():28    import torch  # type: ignore  # noqa29 30    if not torch.cuda.is_available():31        # If no GPU is available, uninstall xformers and apply "--precision full --no-half --use-cpu all" to sys.argv.32        os.system(f"{sys.executable} -m pip uninstall -y xformers")33        sys.argv.extend(34            [35                "--precision",36                "full",37                "--no-half",38                "--use-cpu",39                "all",40            ]41        )42    else:43        # Applies "--force-enable-xformers --xformers" to sys.argv when there's a GPU present.44        sys.argv.extend(["--force-enable-xformers", "--xformers"])45 46    is_shared_ui = str(os.environ.get("IS_SHARED_UI", "") or "").strip().lower() not in ("", "0", "false", "none", "no")47    if not is_shared_ui:48        # Provide access to extensions only if IS_SHARED_UI isn't set.49        sys.argv.extend(["--enable-insecure-extension-access"])50 51 52if __name__ == "__main__":53    set_options()54    on_start()55    start()56