-
Notifications
You must be signed in to change notification settings - Fork 0
/
flux-schnell-16.py
executable file
·64 lines (50 loc) · 2.08 KB
/
flux-schnell-16.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
#!/usr/bin/env python3
from argparse import ArgumentParser, BooleanOptionalAction
from subprocess import call
from time import time
from diffusers import FluxPipeline
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
datatype = bfloat16
pipeline = FluxPipeline.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,
guidance_scale=0.0,
num_inference_steps=inference_steps,
max_sequence_length=256,
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="black-forest-labs/FLUX.1-schnell", 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)