import re import json import glob import os for file in glob.glob("**/*.civitai.info", recursive=True): try: out = {} jsonname = re.sub(r"\.civitai\.info$", ".json", file) textname = re.sub(r"\.civitai\.info$", ".txt", file) if os.path.isfile(jsonname): continue description = "" if os.path.isfile(textname): with open(textname) as f: description = f.read() f.close() with open(file) as f: info = json.load(f) print("Processing :",jsonname) sdversion = "Unknown" if 'SD 1' in info['baseModel']: sdversion = "SD1" if 'SD 2' in info['baseModel']: sdversion = "SD2" if 'SDXL' in info['baseModel']: sdversion = "SDXL" # out["description"] = info.get("description", "") # if not out["description"]: out["description"] = description out["activation text"] = ", ".join(info["trainedWords"]) out["notes"] = f"https://civitai.com/models/{info['modelId']}?modelVersionId={info['id']}" out["sd version"] = sdversion out["preferred weight"] = 1 with open(jsonname, "w") as f: json.dump(out, f, indent=4) except: print("ERROR :", file) continue