-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt-forge-standalone.py
36 lines (27 loc) · 1.56 KB
/
prompt-forge-standalone.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
from argparse import ArgumentParser
from pathlib import Path
from typing import TextIO
from scripts.prompt_forge import Generator
if __name__ == "__main__":
parser = ArgumentParser(
"Prompt-forge: create Stable Diffusion prompts from a configuration file"
)
parser.add_argument("content_file", type=Path, help="File containing the prompt generation configuration.")
parser.add_argument("-m", "--mode", choices=("random", "exhaustive"), default="random", help="Mode of generation. Warning: exhaustive generates ALL possibilities, thus the number of prompts scales exponentially.") # TODO
parser.add_argument("-n", "--number", type=int, required=False, help="Number of prompts to generate. Ignored if `mode=exhaustive`.")
parser.add_argument("-o", "--output", type=Path, default=sys.stdout, help="File to save the prompts to. By default, outputs to stdout.")
args = parser.parse_args()
if args.mode == "random" and not args.number:
raise ValueError("Expected a number of prompts to be generated with `mode=random`")
generator = Generator.from_file(args.content_file)
def write(prompts: list[str], destination: Path | TextIO):
prompts_txt = "\n".join(prompts)
if isinstance(destination, Path):
destination.write_text(prompts_txt)
else:
destination.write(prompts_txt)
if args.mode == "random":
write(generator.generate_random_prompts(n=args.number), args.output)
elif args.mode == "exhaustive":
write(generator.generate_exhaustive_prompts(), args.output)