File size: 1,333 Bytes
2b6a9b4 3256f40 21e468b 3256f40 21e468b 3256f40 21e468b 3256f40 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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
|