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