Sign In

Extract_PositivePrompts_Metadata

3

Extract_PositivePrompts_Metadata

While creating images with ComfyUI for a new experimental LoRA dataset, I needed prompts that resemble mathematical representations on Cartesian coordinates. GPT helped generate batch prompts for simple image generation, resulting in around 300 images. Now comes the task of captioning each image for training.

To avoid manually importing images into ComfyUI to retrieve their positive prompts—or pre-generating caption files—this Python script automates the process.

What the Script Does:

This script extracts positive prompts from PNG metadata, specifically designed for images generated with ComfyUI. It processes all PNG files in the current directory and creates a separate .txt file for each image containing its positive prompt.

Features:

  • Scans all PNG files in the script's directory.

  • Extracts positive prompts from ComfyUI metadata.

  • Creates a .txt file for each image, named after the original image.

  • Outputs status messages:

    • Successfully processed files.

    • Files without valid prompts.

    • Errors during processing.

Notes:

  • Supports only PNG files.

  • Requires ComfyUI metadata in the correct format.

  • If no valid metadata is found, the script will notify you.

Troubleshooting:

Ensure:

  • The images are PNG format.

  • ComfyUI metadata is embedded in the files.

  • Python and required libraries (e.g., Pillow) are correctly installed.

  • The script is in the same directory as the images to process.

Check it out here for detailed instructions:
Github Repository: https://github.com/Tranchillo/Extract_PositivePrompts_Metadata

3