move all installation code out of model_manager

This commit is contained in:
Lincoln Stein
2023-06-11 12:51:50 -04:00
parent 74b43c9bdf
commit 000626ab2e
8 changed files with 663 additions and 152 deletions

55
scripts/scan_models_directory.py Normal file → Executable file
View File

@ -1,3 +1,5 @@
#!/usr/bin/env python
'''
Scan the models directory and print out a new models.yaml
'''
@ -12,6 +14,12 @@ from omegaconf import OmegaConf
def main():
parser = argparse.ArgumentParser(description="Model directory scanner")
parser.add_argument('models_directory')
parser.add_argument('--all-models',
default=False,
action='store_true',
help='If true, then generates stanzas for all models; otherwise just diffusers'
)
args = parser.parse_args()
directory = args.models_directory
@ -19,29 +27,30 @@ def main():
conf['_version'] = '3.0.0'
for root, dirs, files in os.walk(directory):
for d in dirs:
parents = root.split('/')
subpaths = parents[parents.index('models')+1:]
if len(subpaths) < 2:
continue
base, model_type, *_ = subpaths
conf[f'{model_type}/{d}'] = dict(
path = os.path.join(root,d),
description = f'{model_type} model {d}',
format = 'folder',
base = base,
)
for f in files:
basename = Path(f).stem
format = Path(f).suffix[1:]
conf[f'{model_type}/{basename}'] = dict(
path = os.path.join(root,f),
description = f'{model_type} model {basename}',
format = format,
base = base,
)
parents = root.split('/')
subpaths = parents[parents.index('models')+1:]
if len(subpaths) < 2:
continue
base, model_type, *_ = subpaths
if args.all_models or model_type=='diffusers':
for d in dirs:
conf[f'{base}/{model_type}/{d}'] = dict(
path = os.path.join(root,d),
description = f'{model_type} model {d}',
format = 'folder',
base = base,
)
for f in files:
basename = Path(f).stem
format = Path(f).suffix[1:]
conf[f'{base}/{model_type}/{basename}'] = dict(
path = os.path.join(root,f),
description = f'{model_type} model {basename}',
format = format,
base = base,
)
OmegaConf.save(config=dict(sorted(conf.items())), f=sys.stdout)