Script to convert civitai.info -> .json #12009
Replies: 3 comments
-
import re
import json
import glob
for file in glob.glob("**/*.civitai.info", recursive=True):
out = {}
with open(file) as f:
info = json.load(f)
out["description"] = info.get("description", "")
out["activation text"] = ", ".join(info["trainedWords"])
out["notes"] = f"https://civitai.com/models/{info['modelId']}?modelVersionId={info['id']}"
with open(re.sub(r"\.civitai\.info$", ".json", file), "w") as f:
json.dump(out, f, indent=4) Looks for |
Beta Was this translation helpful? Give feedback.
-
First of all, Thank you so much. I was able to run it on about 3000 civitai files in about 2 seconds. I ran into some small snags.
|
Beta Was this translation helpful? Give feedback.
-
Beware, there was a bug in import json
import glob
for file in glob.glob("**/*.civitai.info", recursive=True):
out = {}
with open(file) as f:
info = json.load(f)
if not info:
continue
out["description"] = info.get("description", "")
out["activation text"] = ", ".join(info.get("trainedWords", []))
out["notes"] = f"https://civitai.com/models/{info['modelId']}?modelVersionId={info['id']}"
with open(f"{file[:-12]}json", "w") as f:
json.dump(out, f, indent=4) |
Beta Was this translation helpful? Give feedback.
-
We now have a native LoRA editor built into the WebUI. It generates .json files to store the activation text and preferred weight etc.
Someone should build a script to migrate the data the civitai helper generates to create the jason files.
An example json file that the webUI creates
Most of that data can be pulled from fields in the civitai.info files.
MAPPING:
description: FROM description
activation text: FROM trainedWords (Change list format to comma separated)
notes: can create a URL FROM ModelID and ID like "https://civitai.com/models/[modelId]?modelVersionId=[id]"
sd version: can be left off as the web UI detects this on its own.
weight can be left off because users and set this as preferred.
The end result will look like this.
I have thousands of models and would love some help creating something like this.
Beta Was this translation helpful? Give feedback.
All reactions