Upload civitaiinfo_convert.py
Browse files- civitaiinfo_convert.py +30 -0
civitaiinfo_convert.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
import json
|
3 |
+
import glob
|
4 |
+
import os
|
5 |
+
|
6 |
+
for file in glob.glob("**/*.civitai.info", recursive=True):
|
7 |
+
out = {}
|
8 |
+
jsonname = re.sub(r"\.civitai\.info$", ".json", file)
|
9 |
+
textname = re.sub(r"\.civitai\.info$", ".txt", file)
|
10 |
+
if os.path.isfile(jsonname):
|
11 |
+
continue
|
12 |
+
description = ""
|
13 |
+
if os.path.isfile(textname):
|
14 |
+
with open(textname) as f:
|
15 |
+
description = f.read()
|
16 |
+
f.close()
|
17 |
+
|
18 |
+
print(jsonname)
|
19 |
+
with open(file) as f:
|
20 |
+
info = json.load(f)
|
21 |
+
|
22 |
+
# out["description"] = info.get("description", "")
|
23 |
+
# if not out["description"]:
|
24 |
+
out["description"] = description
|
25 |
+
out["activation text"] = ", ".join(info["trainedWords"])
|
26 |
+
out["notes"] = f"https://civitai.com/models/{info['modelId']}?modelVersionId={info['id']}"
|
27 |
+
|
28 |
+
print(jsonname)
|
29 |
+
with open(jsonname, "w") as f:
|
30 |
+
json.dump(out, f, indent=4)
|