Closed olamedia closed 1 year ago
Thanks for the request! Hmm moving from the JSON file into the metadata? I would imagine it would be outside the scope of this tool (as to just inspect) but I could put together a script. But not sure a reason to do this. What were you thinking?
Thanks!
There can be few reasons - to fix wrong metadata, to strip training data, to cleanup etc, to add own private-use fields
I think modifying the file would be outside the scope of this project currently. Additionally, the various ways to handle the input could be a lot to process.
But here is some code that may work, I haven't tested, so use it on a copy of a file you may have. Can then add new items to the python dict and then save it to a new safetensors file.
from safetensors import load_file, save_file
file = "x.safetensors"
with load_file(file) as f:
metadata = f.metadata()
metadata['new-key'] = "my value"
save_file(dict((key, f.get_tensor(key)) for key in f.keys()), file, metadata)
I added a script to do this as I had many additional people, as well as myself, needing it. a1111 will infer ss_output_name in some settings it seems, so being able to set that can help.
Add the ability to save modified metadata back