-
Notifications
You must be signed in to change notification settings - Fork 0
/
sd-35-turbo.py
executable file
·76 lines (61 loc) · 2.4 KB
/
sd-35-turbo.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
from argparse import ArgumentParser, BooleanOptionalAction
from subprocess import call
from time import time
from diffusers import StableDiffusion3Pipeline
from slugify import slugify
from torch import bfloat16
def main(arguments):
model = arguments.model
prompt = arguments.prompt
width = arguments.width
height = arguments.height
inference_steps = arguments.inference_steps
images_per_batch = arguments.images_per_batch
open_outputs = arguments.open_outputs
prompt = [prompt] * images_per_batch
negative_attributes = (
"low quality",
"bad quality",
"ugly",
"deformed",
"disfigured",
"poor details",
"bad anatomy",
"unaesthetic",
)
negative_prompt = [", ".join(negative_attributes)] * images_per_batch
datatype = bfloat16
pipeline = StableDiffusion3Pipeline.from_pretrained(model, torch_dtype=datatype)
pipeline.enable_sequential_cpu_offload()
pipeline.vae.enable_slicing()
pipeline.vae.enable_tiling()
pipeline.to(datatype)
images = pipeline(
prompt=prompt,
negative_prompt=negative_prompt,
guidance_scale=0.0,
num_inference_steps=inference_steps,
width=width,
height=height,
).images
slugified_prompt = slugify(prompt[0])
slugified_model_name = slugify(model)
for image in images:
try:
image.save(f"outputs/{time()}-{slugified_model_name}-{width}-{height}-{slugified_prompt}.png")
except OSError:
image.save(f"outputs/{time()}-{slugified_model_name}-{width}-{height}.png")
if open_outputs:
call(("open", "outputs"))
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("--model", default="stabilityai/stable-diffusion-3.5-large-turbo", required=False)
parser.add_argument("--prompt", default="sunset in a remote valley in berner oberland", required=False)
parser.add_argument("--width", default=1024, type=int, required=False)
parser.add_argument("--height", default=1024, type=int, required=False)
parser.add_argument("--inference-steps", default=4, type=int, required=False)
parser.add_argument("--images-per-batch", default=1, type=int, required=False)
parser.add_argument("--open-outputs", default=True, action=BooleanOptionalAction, required=False)
arguments = parser.parse_args()
main(arguments)