InvokeAI/scripts/images2prompt.py
Scott Lahteine 7d8d4bcafb
Global replace [ \t]+$, add "GB" (#1751)
* "GB"

* Replace [ \t]+$ global

Co-authored-by: Lincoln Stein <lincoln.stein@gmail.com>
2022-12-19 16:36:39 +00:00

31 lines
853 B
Python
Executable File

#!/usr/bin/env python3
'''This script reads the "Invoke" Stable Diffusion prompt embedded in files generated by invoke.py'''
import sys
from PIL import Image,PngImagePlugin
if len(sys.argv) < 2:
print("Usage: file2prompt.py <file1.png> <file2.png> <file3.png>...")
print("This script opens up the indicated invoke.py-generated PNG file(s) and prints out the prompt used to generate them.")
exit(-1)
filenames = sys.argv[1:]
for f in filenames:
try:
im = Image.open(f)
try:
prompt = im.text['Dream']
except KeyError:
prompt = ''
print(f'{f}: {prompt}')
except FileNotFoundError:
sys.stderr.write(f'{f} not found\n')
continue
except PermissionError:
sys.stderr.write(f'{f} could not be opened due to inadequate permissions\n')
continue