File size: 1,516 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
44
45
46
47
48
49
50
51
import torch
from diffusers import FluxControlPipeline, FluxTransformer2DModel
from diffusers.utils import load_image
from image_gen_aux import DepthPreprocessor
import argparse


def edit_image(prompt: str, ori_image_path: str, save_path: str):
    pipe = FluxControlPipeline.from_pretrained(
        "black-forest-labs/FLUX.1-Depth-dev", torch_dtype=torch.bfloat16
    ).to("cuda")

    control_image = load_image(ori_image_path)

    processor = DepthPreprocessor.from_pretrained("LiheYoung/depth-anything-large-hf")
    control_image = processor(control_image)[0].convert("RGB")

    image = pipe(
        prompt=prompt,
        control_image=control_image,
        height=480,
        width=854,
        num_inference_steps=30,
        guidance_scale=10.0,
        generator=torch.Generator().manual_seed(42),
    ).images[0]
    image.save(save_path)
    print(f"Edited image saved to {save_path}")


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

    edit_image(args.prompt, args.ori_image_path, args.save_path)