Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from PIL import Image
- import time
- import codecs
- input_folder = 'E:\\SD'
- prompts = []
- for path, subdirs, files in os.walk(input_folder):
- for name in files:
- filename = os.path.join(path, name)
- print (filename)
- if filename.endswith('.png'):
- # Open the image file with PIL.Image.File
- try:
- im = Image.open(filename)
- except:
- continue
- if 'parameters' in im.info:
- metadata_str = str(im.info['parameters'].split('Negative prompt')[0])
- # print (metadata_str)
- # time.sleep(1)
- if len(metadata_str.split(',')) > 1 and metadata_str not in prompts:
- prompts.append(metadata_str)
- with codecs.open("prompts.txt", "a", encoding='utf-8') as myfile:
- myfile.write(metadata_str.replace('_',' '))
- myfile.write("\n")
- im.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement