INNER CODE UNIT · Python

json_file_to_dict

AbdBarho/stable-diffusion-webui-docker · services/AUTOMATIC1111/config.py:35

def json_file_to_dict(config_file: str) -> dict|None:
   """Load json file into a dictionary. Return None if file does not exist."""

   if os.path.isfile(config_file):
    with open(config_file, 'r') as f:
      return json.load(f)
   else:
      return None

def replace_if_invalid(value: str, replacement: str, pattern: str|re.Pattern[str]) -> str:
  """Returns original value if valid, fallback value if invalid"""

  if re.match(pattern, value):
    return value
  else:
    return replacement

def check_and_replace_config(config_file: str, target_file: str = None):

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…