afromero commited on
Commit
22ce2ab
1 Parent(s): 6d34081

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +55 -1
README.md CHANGED
@@ -6,4 +6,58 @@ base_model:
6
  - black-forest-labs/FLUX.1-dev
7
  - black-forest-labs/FLUX.1-Depth-dev
8
  pipeline_tag: image-to-image
9
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  - black-forest-labs/FLUX.1-dev
7
  - black-forest-labs/FLUX.1-Depth-dev
8
  pipeline_tag: image-to-image
9
+ ---
10
+
11
+ # The Flux pipeline for image inpainting using Flux-dev-Depth/Canny
12
+
13
+ ```py
14
+ import torch
15
+ from diffusers import DiffusionPipeline, FluxTransformer2DModel
16
+ from transformers import T5EncoderModel
17
+ from diffusers.utils import load_image, make_image_grid
18
+ from image_gen_aux import DepthPreprocessor # https://github.com/huggingface/image_gen_aux
19
+ from PIL import Image
20
+ import numpy as np
21
+
22
+ pipe = DiffusionPipeline.from_pretrained(
23
+ "black-forest-labs/FLUX.1-Depth-dev",
24
+ torch_dtype=torch.bfloat16,
25
+ custom_pipeline="afromero/pipeline_flux_control_inpaint",
26
+ )
27
+
28
+ transformer = FluxTransformer2DModel.from_pretrained(
29
+ "sayakpaul/FLUX.1-Depth-dev-nf4", subfolder="transformer", torch_dtype=torch.bfloat16
30
+ )
31
+ text_encoder_2 = T5EncoderModel.from_pretrained(
32
+ "sayakpaul/FLUX.1-Depth-dev-nf4", subfolder="text_encoder_2", torch_dtype=torch.bfloat16
33
+ )
34
+ pipe.transformer = transformer
35
+ pipe.text_encoder_2 = text_encoder_2
36
+ pipe.to("cuda")
37
+
38
+ prompt = "The head of a human in a robot body giving a heated speech"
39
+ image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png")
40
+
41
+ head_mask = np.ones_like(image)*255
42
+ head_mask[65:380,300:642] = 0
43
+ mask_image = Image.fromarray(head_mask)
44
+
45
+ processor = DepthPreprocessor.from_pretrained("LiheYoung/depth-anything-large-hf")
46
+ control_image = processor(image)[0].convert("RGB")
47
+
48
+ output = pipe(
49
+ prompt=prompt,
50
+ image=image,
51
+ control_image=control_image,
52
+ mask_image=mask_image,
53
+ height=1024,
54
+ width=1024,
55
+ num_inference_steps=30,
56
+ strength=0.9,
57
+ guidance_scale=10.0,
58
+ generator=torch.Generator().manual_seed(42),
59
+ ).images[0]
60
+ make_image_grid([image, control_image, mask_image, output], rows=1, cols=4).save("output.png")
61
+
62
+ ```
63
+