import re | |
import json | |
import glob | |
import os | |
for file in glob.glob("**/*.civitai.info", recursive=True): | |
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() | |
print(jsonname) | |
with open(file) as f: | |
info = json.load(f) | |
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 | |
print(jsonname) | |
with open(jsonname, "w") as f: | |
json.dump(out, f, indent=4) |