Skip to content

Commit

Permalink
fix(api): filter out temporary files from model lists (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Mar 20, 2023
1 parent b99c8c8 commit 1971226
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions api/onnx_web/server/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ def get_config_value(key: str, subkey: str = "default", default=None):
return config_params.get(key, {}).get(subkey, default)


def get_model_name(model: str) -> str:
base = path.basename(model)
(file, _ext) = path.splitext(base)
return file


def load_extras(context: ServerContext):
"""
Expand Down Expand Up @@ -202,15 +197,21 @@ def load_extras(context: ServerContext):
extra_strings = strings


IGNORE_EXTENSIONS = ["crdownload", "lock", "tmp"]


def list_model_globs(
context: ServerContext, globs: List[str], base_path: Optional[str] = None
) -> List[str]:
models = []
for pattern in globs:
pattern_path = path.join(base_path or context.model_path, pattern)
logger.debug("loading models from %s", pattern_path)

models.extend([get_model_name(f) for f in glob(pattern_path)])
for name in glob(pattern_path):
base = path.basename(name)
(file, ext) = path.splitext(base)
if ext not in IGNORE_EXTENSIONS:
models.append(file)

unique_models = list(set(models))
unique_models.sort()
Expand Down

0 comments on commit 1971226

Please sign in to comment.