afromero commited on
Commit
182c9c5
1 Parent(s): 22ce2ab

Update pipeline.py

Browse files
Files changed (1) hide show
  1. pipeline.py +9 -7
pipeline.py CHANGED
@@ -60,8 +60,9 @@ EXAMPLE_DOC_STRING = """
60
  import torch
61
  from diffusers import DiffusionPipeline, FluxTransformer2DModel
62
  from transformers import T5EncoderModel
63
- from diffusers.utils import load_image
64
  from image_gen_aux import DepthPreprocessor # https://github.com/huggingface/image_gen_aux
 
65
  import numpy as np
66
 
67
  pipe = DiffusionPipeline.from_pretrained(
@@ -81,27 +82,28 @@ EXAMPLE_DOC_STRING = """
81
  pipe.to("cuda")
82
 
83
  prompt = "The head of a human in a robot body giving a heated speech"
84
- control_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png")
85
 
86
- head_mask = np.ones_like(control_image)*255
87
  head_mask[65:380,300:642] = 0
88
  mask_image = Image.fromarray(head_mask)
89
 
90
  processor = DepthPreprocessor.from_pretrained("LiheYoung/depth-anything-large-hf")
91
- control_image = processor(control_image)[0].convert("RGB")
92
 
93
- image = pipe(
94
  prompt=prompt,
 
95
  control_image=control_image,
96
  mask_image=mask_image,
97
- strength=0.9,
98
  height=1024,
99
  width=1024,
100
  num_inference_steps=30,
 
101
  guidance_scale=10.0,
102
  generator=torch.Generator().manual_seed(42),
103
  ).images[0]
104
- image.save("output.png")
105
 
106
  ```
107
  """
 
60
  import torch
61
  from diffusers import DiffusionPipeline, FluxTransformer2DModel
62
  from transformers import T5EncoderModel
63
+ from diffusers.utils import load_image, make_image_grid
64
  from image_gen_aux import DepthPreprocessor # https://github.com/huggingface/image_gen_aux
65
+ from PIL import Image
66
  import numpy as np
67
 
68
  pipe = DiffusionPipeline.from_pretrained(
 
82
  pipe.to("cuda")
83
 
84
  prompt = "The head of a human in a robot body giving a heated speech"
85
+ image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png")
86
 
87
+ head_mask = np.ones_like(image)*255
88
  head_mask[65:380,300:642] = 0
89
  mask_image = Image.fromarray(head_mask)
90
 
91
  processor = DepthPreprocessor.from_pretrained("LiheYoung/depth-anything-large-hf")
92
+ control_image = processor(image)[0].convert("RGB")
93
 
94
+ output = pipe(
95
  prompt=prompt,
96
+ image=image,
97
  control_image=control_image,
98
  mask_image=mask_image,
 
99
  height=1024,
100
  width=1024,
101
  num_inference_steps=30,
102
+ strength=0.9,
103
  guidance_scale=10.0,
104
  generator=torch.Generator().manual_seed(42),
105
  ).images[0]
106
+ make_image_grid([image, control_image, mask_image, output], rows=1, cols=4).save("output.png")
107
 
108
  ```
109
  """