2023-06-11 16:51:50 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2023-07-27 14:54:01 +00:00
|
|
|
"""
|
2023-06-09 03:11:53 +00:00
|
|
|
Scan the models directory and print out a new models.yaml
|
2023-07-27 14:54:01 +00:00
|
|
|
"""
|
2023-06-09 03:11:53 +00:00
|
|
|
|
2023-08-18 15:13:28 +00:00
|
|
|
import argparse
|
2023-06-09 03:11:53 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
2023-08-18 15:13:28 +00:00
|
|
|
|
2023-06-09 03:11:53 +00:00
|
|
|
from omegaconf import OmegaConf
|
|
|
|
|
2023-07-27 14:54:01 +00:00
|
|
|
|
2023-06-09 03:11:53 +00:00
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser(description="Model directory scanner")
|
2023-07-27 14:54:01 +00:00
|
|
|
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",
|
|
|
|
)
|
|
|
|
|
2023-06-09 03:11:53 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
directory = args.models_directory
|
|
|
|
|
|
|
|
conf = OmegaConf.create()
|
2023-07-27 14:54:01 +00:00
|
|
|
conf["_version"] = "3.0.0"
|
|
|
|
|
2023-06-09 03:11:53 +00:00
|
|
|
for root, dirs, files in os.walk(directory):
|
2023-07-27 14:54:01 +00:00
|
|
|
parents = root.split("/")
|
|
|
|
subpaths = parents[parents.index("models") + 1 :]
|
2023-06-11 16:51:50 +00:00
|
|
|
if len(subpaths) < 2:
|
|
|
|
continue
|
|
|
|
base, model_type, *_ = subpaths
|
2023-07-27 14:54:01 +00:00
|
|
|
|
|
|
|
if args.all_models or model_type == "diffusers":
|
2023-06-11 16:51:50 +00:00
|
|
|
for d in dirs:
|
2023-11-10 23:44:43 +00:00
|
|
|
conf[f"{base}/{model_type}/{d}"] = {
|
|
|
|
"path": os.path.join(root, d),
|
|
|
|
"description": f"{model_type} model {d}",
|
|
|
|
"format": "folder",
|
|
|
|
"base": base,
|
|
|
|
}
|
2023-06-11 16:51:50 +00:00
|
|
|
|
|
|
|
for f in files:
|
|
|
|
basename = Path(f).stem
|
|
|
|
format = Path(f).suffix[1:]
|
2023-11-10 23:44:43 +00:00
|
|
|
conf[f"{base}/{model_type}/{basename}"] = {
|
|
|
|
"path": os.path.join(root, f),
|
|
|
|
"description": f"{model_type} model {basename}",
|
|
|
|
"format": format,
|
|
|
|
"base": base,
|
|
|
|
}
|
2023-07-27 14:54:01 +00:00
|
|
|
|
2023-06-09 03:11:53 +00:00
|
|
|
OmegaConf.save(config=dict(sorted(conf.items())), f=sys.stdout)
|
|
|
|
|
2023-07-27 14:54:01 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-06-09 03:11:53 +00:00
|
|
|
main()
|