mirror of
https://github.com/ostris/ai-toolkit.git
synced 2026-01-26 16:39:47 +00:00
Reworked so everything is in classes for easy expansion. Single entry point for all config files now.
This commit is contained in:
@@ -1,31 +1,18 @@
|
||||
import json
|
||||
|
||||
software_meta = {
|
||||
"name": "ai-toolkit",
|
||||
"url": "https://github.com/ostris/ai-toolkit"
|
||||
}
|
||||
from collections import OrderedDict
|
||||
from info import software_meta
|
||||
|
||||
|
||||
def create_meta(dict_list, name=None):
|
||||
meta = {}
|
||||
for d in dict_list:
|
||||
for key, value in d.items():
|
||||
meta[key] = value
|
||||
|
||||
if "name" not in meta:
|
||||
meta["name"] = "[name]"
|
||||
|
||||
meta["software"] = software_meta
|
||||
|
||||
# convert to string to handle replacements
|
||||
def get_meta_for_safetensors(meta: OrderedDict, name=None) -> OrderedDict:
|
||||
# stringify the meta and reparse OrderedDict to replace [name] with name
|
||||
meta_string = json.dumps(meta)
|
||||
if name is not None:
|
||||
meta_string = meta_string.replace("[name]", name)
|
||||
return json.loads(meta_string)
|
||||
|
||||
|
||||
def prep_meta_for_safetensors(meta):
|
||||
save_meta = json.loads(meta_string, object_pairs_hook=OrderedDict)
|
||||
save_meta["software"] = software_meta
|
||||
# safetensors can only be one level deep
|
||||
for key, value in meta.items():
|
||||
meta[key] = json.dumps(value)
|
||||
return meta
|
||||
for key, value in save_meta.items():
|
||||
# if not float, int, bool, or str, convert to json string
|
||||
if not isinstance(value, (float, int, bool, str)):
|
||||
save_meta[key] = json.dumps(value)
|
||||
return save_meta
|
||||
|
||||
Reference in New Issue
Block a user