diff --git a/build.bat b/build.bat index dc9e622f..2c7890ee 100644 --- a/build.bat +++ b/build.bat @@ -15,6 +15,7 @@ mkdir dist\win\stable-diffusion-ui\scripts copy scripts\on_env_start.bat dist\win\stable-diffusion-ui\scripts\ copy scripts\bootstrap.bat dist\win\stable-diffusion-ui\scripts\ +copy scripts\config.yaml.sample dist\win\stable-diffusion-ui\scripts\config.yaml copy "scripts\Start Stable Diffusion UI.cmd" dist\win\stable-diffusion-ui\ copy LICENSE dist\win\stable-diffusion-ui\ copy "CreativeML Open RAIL-M License" dist\win\stable-diffusion-ui\ diff --git a/build.sh b/build.sh index bddf3c49..dfb8f420 100755 --- a/build.sh +++ b/build.sh @@ -29,6 +29,7 @@ mkdir -p dist/linux-mac/stable-diffusion-ui/scripts cp scripts/on_env_start.sh dist/linux-mac/stable-diffusion-ui/scripts/ cp scripts/bootstrap.sh dist/linux-mac/stable-diffusion-ui/scripts/ cp scripts/functions.sh dist/linux-mac/stable-diffusion-ui/scripts/ +cp scripts/config.yaml.sample dist/linux-mac/stable-diffusion-ui/scripts/config.yaml cp scripts/start.sh dist/linux-mac/stable-diffusion-ui/ cp LICENSE dist/linux-mac/stable-diffusion-ui/ cp "CreativeML Open RAIL-M License" dist/linux-mac/stable-diffusion-ui/ diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 4634adb3..d6a26424 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -24,6 +24,7 @@ modules_to_check = { "uvicorn": "0.19.0", "fastapi": "0.85.1", "pycloudflared": "0.2.0", + "ruamel.yaml": "0.17.21", # "xformers": "0.0.16", } modules_to_log = ["torch", "torchvision", "sdkit", "stable-diffusion-sdkit"] diff --git a/scripts/config.yaml.sample b/scripts/config.yaml.sample new file mode 100644 index 00000000..9c2cc4a6 --- /dev/null +++ b/scripts/config.yaml.sample @@ -0,0 +1,24 @@ +# Change listen_port if port 9000 is already in use on your system +# Set listen_to_network to true to make Easy Diffusion accessibble on your local network +net: + listen_port: 9000 + listen_to_network: false + +# Multi GPU setup +render_devices: auto + +# Set open_browser_on_start to false to disable opening a new browser tab on each restart +ui: + open_browser_on_start: true + +# set update_branch to main to use the stable version, or to beta to use the experimental +# beta version. +update_branch: main + +# Set force_save_path to enforce an auto save path. Clients will not be able to change or +# disable auto save when this option is set. Please adapt the path in the examples to your +# needs. +# Windows: +# force_save_path: C:\\Easy Diffusion Images\\ +# Linux: +# force_save_path: /data/easy-diffusion-images/ diff --git a/ui/easydiffusion/app.py b/ui/easydiffusion/app.py index 99810e75..d50ee5d1 100644 --- a/ui/easydiffusion/app.py +++ b/ui/easydiffusion/app.py @@ -4,6 +4,9 @@ import os import socket import sys import traceback +import shlex +from ruamel.yaml import YAML + import urllib import warnings @@ -14,6 +17,8 @@ from rich.console import Console from rich.panel import Panel from sdkit.utils import log as sdkit_log # hack, so we can overwrite the log config +yaml = YAML() + # Remove all handlers associated with the root logger object. for handler in logging.root.handlers[:]: logging.root.removeHandler(handler) @@ -98,30 +103,51 @@ def init(): def getConfig(default_val=APP_CONFIG_DEFAULTS): - try: - config_json_path = os.path.join(CONFIG_DIR, "config.json") - if not os.path.exists(config_json_path): - config = default_val - else: - with open(config_json_path, "r", encoding="utf-8") as f: - config = json.load(f) - if "net" not in config: - config["net"] = {} - if os.getenv("SD_UI_BIND_PORT") is not None: - config["net"]["listen_port"] = int(os.getenv("SD_UI_BIND_PORT")) - if os.getenv("SD_UI_BIND_IP") is not None: - config["net"]["listen_to_network"] = os.getenv("SD_UI_BIND_IP") == "0.0.0.0" - return config - except Exception: - log.warn(traceback.format_exc()) - return default_val + config_yaml_path = os.path.join(CONFIG_DIR, "config.yaml") + if os.path.isfile(config_yaml_path): + try: + log.info("Loading config.yaml") + with open(config_yaml_path, "r", encoding="utf-8") as f: + config = yaml.load(f) + if "net" not in config: + config["net"] = {} + if os.getenv("SD_UI_BIND_PORT") is not None: + config["net"]["listen_port"] = int(os.getenv("SD_UI_BIND_PORT")) + else: + config['net']['listen_port'] = 9000 + if os.getenv("SD_UI_BIND_IP") is not None: + config["net"]["listen_to_network"] = os.getenv("SD_UI_BIND_IP") == "0.0.0.0" + else: + config["net"]["listen_to_network"] = True + return config + except Exception as e: + log.warn(traceback.format_exc()) + return default_val + else: + try: + config_json_path = os.path.join(CONFIG_DIR, "config.json") + if not os.path.exists(config_json_path): + return default_val + else: + log.info("Converting old json config file to yaml") + with open(config_json_path, "r", encoding="utf-8") as f: + config = json.load(f) + # Save config in new format + setConfig(config) + os.rename(config_json_path, config_json_path + ".bak") + log.info("Saved old config.json as config.json.bak") + return getConfig(default_val) + except Exception as e: + log.warn(traceback.format_exc()) + return default_val def setConfig(config): - try: # config.json - config_json_path = os.path.join(CONFIG_DIR, "config.json") - with open(config_json_path, "w", encoding="utf-8") as f: - json.dump(config, f) + try: # config.yaml + config_yaml_path = os.path.join(CONFIG_DIR, 'config.yaml') + yaml.indent(mapping=2, sequence=4, offset=2) + with open(config_yaml_path, 'w', encoding='utf-8') as f: + yaml.dump(config, f) except: log.error(traceback.format_exc())