Skip to content

Commit

Permalink
feat(api): load wildcards from markup files
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jul 12, 2023
1 parent 00fc584 commit 5df9aa2
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions api/onnx_web/server/load.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import defaultdict
from functools import cmp_to_key
from glob import glob
from logging import getLogger
Expand Down Expand Up @@ -90,7 +91,7 @@
diffusion_models: List[str] = []
network_models: List[NetworkModel] = []
upscaling_models: List[str] = []
wildcard_data: Dict[str, List[str]] = {}
wildcard_data: Dict[str, List[str]] = defaultdict(list)

# Loaded from extra_models
extra_hashes: Dict[str, str] = {}
Expand Down Expand Up @@ -461,11 +462,13 @@ def any_first_cpu_last(a: DeviceParams, b: DeviceParams):
def load_wildcards(server: ServerContext) -> None:
global wildcard_data

wildcard_path = path.join(server.model_path, "wildcard")

# simple wildcards
wildcard_files = list_model_globs(
server,
["**/*.txt"],
base_path=path.join(server.model_path, "wildcard"),
base_path=wildcard_path,
filename_only=False,
recursive=True,
)
Expand All @@ -476,6 +479,20 @@ def load_wildcards(server: ServerContext) -> None:
lines = [line.strip() for line in lines if not line.startswith("#")]
lines = [line for line in lines if len(line) > 0]
logger.debug("loading wildcards from %s: %s", file, lines)
wildcard_data[path.splitext(file)[0]] = lines
wildcard_data[path.splitext(file)[0]].extend(lines)

structured_files = list_model_globs(
server,
["**/*.json", "**/*.yaml"],
base_path=wildcard_path,
filename_only=False,
recursive=True,
)

for file in structured_files:
data = load_config(path.join(wildcard_path, file))
logger.debug("loading structured wildcards from %s: %s", file, data)

# TODO: structured wildcards
for key, values in data.items():
if isinstance(values, list):
wildcard_data[key].extend(values)

0 comments on commit 5df9aa2

Please sign in to comment.