File size: 1,107 Bytes
ad44ad4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch
from diffusers import FluxPipeline
import argparse


def image_generation(prompt: str, save_path: str):
    pipe = FluxPipeline.from_pretrained(
        "black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16
    )
    pipe.enable_model_cpu_offload()

    out = pipe(
        prompt=prompt,
        guidance_scale=3.5,
        height=480,
        width=720,
        num_inference_steps=50,
    ).images[0]
    out.save(save_path)

    print(f"Generated image saved to {save_path}")


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Generate an image using FLUX.")
    parser.add_argument(
        "--prompt", type=str, required=True, help="The prompt for image generation."
    )
    parser.add_argument(
        "--save_path",
        type=str,
        required=True,
        help="The path to save the generated image.",
    )
    args = parser.parse_args()

    pipe = FluxPipeline.from_pretrained(
        "black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16
    )
    pipe.enable_model_cpu_offload()

    image_generation(args.prompt, args.save_path)