Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store prompts/parameters in EXIF #111

Open
sowbug opened this issue Sep 2, 2022 · 6 comments · May be fixed by #123
Open

Store prompts/parameters in EXIF #111

sowbug opened this issue Sep 2, 2022 · 6 comments · May be fixed by #123

Comments

@sowbug
Copy link

sowbug commented Sep 2, 2022

It would be cool to (optionally) embed the information in each file's EXIF metadata needed to reproduce it. Having the seed and the prompt in the filename/folder is nice, but it's not always enough information, and if your --n_samples is larger than 1, then the prompt is no longer part of the filename, so individual files have even less metadata.

@sowbug
Copy link
Author

sowbug commented Sep 2, 2022

Screenshot from 2022-09-02 15-18-35

Here's what it might look like. Other advantages:

  • No more worrying about whether the filename is valid if there are special characters in the prompt
  • Photo services can more easily index keywords that appear in EXIF, rather than hoping that they correctly extract keywords from the filename
  • If a photo-management app needs to rename or move the file, no valuable data is lost.

@sowbug
Copy link
Author

sowbug commented Sep 5, 2022

Here is a Python snippet that works for PNG:

from libxmp import XMPFiles, consts, XMPMeta
import time

xmpfile = XMPFiles(file_path="PNG-metadata-test.png", open_forupdate=True)
xmp = xmpfile.get_xmp()
if xmp is None:
  xmp = XMPMeta()
xmp.append_array_item(consts.XMP_NS_DC, 'description', 'the time is %s' % time.asctime(), {'prop_array_is_ordered':True, 'prop_value_is_array':True})
xmpfile.put_xmp(xmp)
xmpfile.close_file()

On my Ubuntu Cinnamon system, this works as expected. Note that I needed to install libxml (pip install python-xmp-toolkit)

sowbug added a commit to sowbug/stable-diffusion that referenced this issue Sep 5, 2022
Problems:

1. The pip package python-xmp-toolkit isn't supported on Windows,
   and doesn't automatically install the required C++-based
   dependency libexempi3. See
   https://python-xmp-toolkit.readthedocs.io/en/latest/installation.html
   for manual installation steps.

2. The metadata is just a dump of argparse's parsed options, which
   could leak private information in arguments such as outdir. A
   todo is to build a dictionary from the argparse namespace, but
   exclude fields that could contain sensitive information.

this might work
@sowbug
Copy link
Author

sowbug commented Sep 5, 2022

Please take a look at 50d0f0e. It mostly does what I had in mind. Outstanding issues are listed in the commit message. Another issue I just thought of is that JSON might be a better format than str(argparse), because it's just as human-readable, but it's more machine-readable.

Anyway, this definitely scratches my own itch for now. If anyone else finds it useful, I'll be happy to turn it into a PR.

Screenshot from 2022-09-05 16-49-44

@basujindal
Copy link
Owner

Hi, sorry for the late reply, and thanks for adding this amazing feature; I will merge the commits as soon as possible. Thanks again!

@sowbug
Copy link
Author

sowbug commented Sep 6, 2022

Please wait until I submit a PR, as I don't think the current implementation's quality is high enough. The problem is that installation of a certain required library is difficult, and I don't want you to incur a support load for anyone who runs into trouble.

@sowbug sowbug linked a pull request Sep 6, 2022 that will close this issue
@sowbug
Copy link
Author

sowbug commented Sep 6, 2022

This is good to review. It works for both txt2img and img2txt, and JPEG and PNG file formats. It introduces no platform-specific dependencies. I've manually tested on Debian.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants