From 248068fe5d57b5639ea7a87ee6cbf023104d957d Mon Sep 17 00:00:00 2001 From: devops117 <55235206+devops117@users.noreply.github.com> Date: Wed, 23 Nov 2022 10:40:27 +0530 Subject: [PATCH] make the docstring more readable and improve the list_models logic Signed-off-by: devops117 <55235206+devops117@users.noreply.github.com> --- ldm/invoke/model_cache.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/ldm/invoke/model_cache.py b/ldm/invoke/model_cache.py index 645a6fd4da..3bb1b7e928 100644 --- a/ldm/invoke/model_cache.py +++ b/ldm/invoke/model_cache.py @@ -125,15 +125,18 @@ class ModelCache(object): def list_models(self) -> dict: ''' Return a dict of models in the format: - { model_name1: {'status': ('active'|'cached'|'not loaded'), - 'description': description, - }, - model_name2: { etc } + { + model_name1: { + 'status': ('active'|'cached'|'not loaded'), + 'description': description, + }, + model_name2: { etc }, + } ''' - result = dict() - for name in self.config: + models = {} + for name, config in self.config.items(): try: - description = self.config[name].description + description = config.description except ConfigAttributeError: description = '' @@ -144,11 +147,13 @@ class ModelCache(object): else: status = 'not loaded' - result[name]={ - 'status' : status, - 'description' : description - } - return result + models = models.update( + name = { + 'status': status, + 'description': description, + }) + + return models def print_models(self) -> None: '''