-
Notifications
You must be signed in to change notification settings - Fork 2
/
txt2img.py
48 lines (40 loc) · 1.19 KB
/
txt2img.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
37
38
39
40
41
42
43
44
45
46
47
48
import argparse
from sdxl import pipeline
def arguments_parser():
parser = argparse.ArgumentParser(
description="Generate a 1024x1024 image for the given prompt to the specified output file."
)
parser.add_argument(
"prompt",
type=str,
help='prompt for the image (e.g., "sunshrine and a blue sky")',
)
parser.add_argument(
"filename",
type=str,
help="filename of the output image (e.g., images/sky.png)",
)
parser.add_argument(
"-l",
"--lowvram",
default=False,
action="store_true",
help="enable lowvram mode.",
)
return parser
def main():
args = arguments_parser().parse_args()
prompt = args.prompt
outfile = args.filename
low_vram = args.lowvram
base_pipe = pipeline(
model="stabilityai/stable-diffusion-xl-base-0.9", low_vram=low_vram
)
refiner_pipe = pipeline(
model="stabilityai/stable-diffusion-xl-refiner-0.9", low_vram=low_vram
)
images = base_pipe(prompt=prompt, output_type="latent").images
image = refiner_pipe(prompt=prompt, image=images).images[0]
image.save(outfile)
if __name__ == "__main__":
main()