Better way to sort the models/loras

This commit is contained in:
oobabooga 2023-04-12 22:56:32 -03:00
parent 7dfbe54f42
commit ddbd237ec9

View File

@ -40,11 +40,18 @@ if settings_file is not None:
shared.settings[item] = new_settings[item] shared.settings[item] = new_settings[item]
def special_sort(model_name):
if '_' in model_name:
return ('_'.join(model_name.split('_')[1:])).lower()
else:
return model_name.lower()
def get_available_models(): def get_available_models():
if shared.args.flexgen: if shared.args.flexgen:
return sorted([re.sub('-np$', '', item.name) for item in list(Path(f'{shared.args.model_dir}/').glob('*')) if item.name.endswith('-np')], key=str.lower) return sorted([re.sub('-np$', '', item.name) for item in list(Path(f'{shared.args.model_dir}/').glob('*')) if item.name.endswith('-np')], key=special_sort)
else: else:
return sorted([re.sub('.pth$', '', item.name) for item in list(Path(f'{shared.args.model_dir}/').glob('*')) if not item.name.endswith(('.txt', '-np', '.pt', '.json'))], key=str.lower) return sorted([re.sub('.pth$', '', item.name) for item in list(Path(f'{shared.args.model_dir}/').glob('*')) if not item.name.endswith(('.txt', '-np', '.pt', '.json'))], key=special_sort)
def get_available_presets(): def get_available_presets():
@ -81,7 +88,7 @@ def get_available_softprompts():
def get_available_loras(): def get_available_loras():
return ['None'] + sorted([item.name for item in list(Path(shared.args.lora_dir).glob('*')) if not item.name.endswith(('.txt', '-np', '.pt', '.json'))], key=str.lower) return ['None'] + sorted([item.name for item in list(Path(shared.args.lora_dir).glob('*')) if not item.name.endswith(('.txt', '-np', '.pt', '.json'))], key=special_sort)
def load_model_wrapper(selected_model): def load_model_wrapper(selected_model):