Skip to content

Commit 6773706

Browse files
committed
[Docs] Add documentation for KontextInpaintingPipeline
1 parent 7a2b78b commit 6773706

File tree

1 file changed

+68
-0
lines changed
  • docs/source/en/api/pipelines

1 file changed

+68
-0
lines changed

docs/source/en/api/pipelines/flux.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,62 @@ if integrity_checker.test_image(image_):
316316
raise ValueError("Your image has been flagged. Choose another prompt/image or try again.")
317317
```
318318

319+
### Kontext Inpainting
320+
The Kontext Inpainting Pipeline enables image modification within a fixed mask region. It currently supports both text-based conditioning and image-reference conditioning.
321+
#### Inpainting with text only
322+
323+
```python
324+
import torch
325+
from diffusers import FluxKontextInpaintPipeline
326+
from diffusers.utils import load_image
327+
328+
prompt = "Change the yellow dinosaur to green one"
329+
img_url = (
330+
"https://github.com/ZenAI-Vietnam/Flux-Kontext-pipelines/blob/main/assets/dinosaur_input.jpeg?raw=true"
331+
)
332+
mask_url = (
333+
"https://github.com/ZenAI-Vietnam/Flux-Kontext-pipelines/blob/main/assets/dinosaur_mask.png?raw=true"
334+
)
335+
336+
source = load_image(img_url)
337+
mask = load_image(mask_url)
338+
339+
pipe = FluxKontextInpaintPipeline.from_pretrained(
340+
"black-forest-labs/FLUX.1-Kontext-dev", torch_dtype=torch.bfloat16
341+
)
342+
pipe.to("cuda")
343+
344+
image = pipe(prompt=prompt, image=source, mask_image=mask, strength=1.0).images[0]
345+
image.save("kontext_inpainting_normal.png")
346+
```
347+
348+
#### Inpainting with image conditioning
349+
```python
350+
import torch
351+
from diffusers import FluxKontextInpaintPipeline
352+
from diffusers.utils import load_image
353+
354+
pipe = FluxKontextInpaintPipeline.from_pretrained(
355+
"black-forest-labs/FLUX.1-Kontext-dev", torch_dtype=torch.bfloat16
356+
)
357+
pipe.to("cuda")
358+
359+
prompt = "Replace this ball"
360+
img_url = "https://images.pexels.com/photos/39362/the-ball-stadion-football-the-pitch-39362.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"
361+
mask_url = "https://github.com/ZenAI-Vietnam/Flux-Kontext-pipelines/blob/main/assets/ball_mask.png?raw=true"
362+
image_reference_url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTah3x6OL_ECMBaZ5ZlJJhNsyC-OSMLWAI-xw&s"
363+
364+
source = load_image(img_url)
365+
mask = load_image(mask_url)
366+
image_reference = load_image(image_reference_url)
367+
368+
mask = pipe.mask_processor.blur(mask, blur_factor=12)
369+
image = pipe(
370+
prompt=prompt, image=source, mask_image=mask, image_reference=image_reference, strength=1.0
371+
).images[0]
372+
image.save("kontext_inpainting_ref.png")
373+
```
374+
319375
## Combining Flux Turbo LoRAs with Flux Control, Fill, and Redux
320376

321377
We can combine Flux Turbo LoRAs with Flux Control and other pipelines like Fill and Redux to enable few-steps' inference. The example below shows how to do that for Flux Control LoRA for depth and turbo LoRA from [`ByteDance/Hyper-SD`](https://hf.co/ByteDance/Hyper-SD).
@@ -646,3 +702,15 @@ image.save("flux-fp8-dev.png")
646702
[[autodoc]] FluxFillPipeline
647703
- all
648704
- __call__
705+
706+
## FluxKontextPipeline
707+
708+
[[autodoc]] FluxKontextPipeline
709+
- all
710+
- __call__
711+
712+
## FluxKontextInpaintPipeline
713+
714+
[[autodoc]] FluxKontextInpaintPipeline
715+
- all
716+
- __call__

0 commit comments

Comments
 (0)