From 6773706b2c691831920c917f53a9b794ab85783f Mon Sep 17 00:00:00 2001 From: vuongminh1907 Date: Wed, 20 Aug 2025 16:52:03 +0700 Subject: [PATCH 1/5] [Docs] Add documentation for KontextInpaintingPipeline --- docs/source/en/api/pipelines/flux.md | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/docs/source/en/api/pipelines/flux.md b/docs/source/en/api/pipelines/flux.md index 64341ca4b918..ee78c1bc66dc 100644 --- a/docs/source/en/api/pipelines/flux.md +++ b/docs/source/en/api/pipelines/flux.md @@ -316,6 +316,62 @@ if integrity_checker.test_image(image_): raise ValueError("Your image has been flagged. Choose another prompt/image or try again.") ``` +### Kontext Inpainting +The Kontext Inpainting Pipeline enables image modification within a fixed mask region. It currently supports both text-based conditioning and image-reference conditioning. +#### Inpainting with text only + +```python +import torch +from diffusers import FluxKontextInpaintPipeline +from diffusers.utils import load_image + +prompt = "Change the yellow dinosaur to green one" +img_url = ( + "https://github.com/ZenAI-Vietnam/Flux-Kontext-pipelines/blob/main/assets/dinosaur_input.jpeg?raw=true" +) +mask_url = ( + "https://github.com/ZenAI-Vietnam/Flux-Kontext-pipelines/blob/main/assets/dinosaur_mask.png?raw=true" +) + +source = load_image(img_url) +mask = load_image(mask_url) + +pipe = FluxKontextInpaintPipeline.from_pretrained( + "black-forest-labs/FLUX.1-Kontext-dev", torch_dtype=torch.bfloat16 +) +pipe.to("cuda") + +image = pipe(prompt=prompt, image=source, mask_image=mask, strength=1.0).images[0] +image.save("kontext_inpainting_normal.png") +``` + +#### Inpainting with image conditioning +```python +import torch +from diffusers import FluxKontextInpaintPipeline +from diffusers.utils import load_image + +pipe = FluxKontextInpaintPipeline.from_pretrained( + "black-forest-labs/FLUX.1-Kontext-dev", torch_dtype=torch.bfloat16 +) +pipe.to("cuda") + +prompt = "Replace this ball" +img_url = "https://images.pexels.com/photos/39362/the-ball-stadion-football-the-pitch-39362.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" +mask_url = "https://github.com/ZenAI-Vietnam/Flux-Kontext-pipelines/blob/main/assets/ball_mask.png?raw=true" +image_reference_url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTah3x6OL_ECMBaZ5ZlJJhNsyC-OSMLWAI-xw&s" + +source = load_image(img_url) +mask = load_image(mask_url) +image_reference = load_image(image_reference_url) + +mask = pipe.mask_processor.blur(mask, blur_factor=12) +image = pipe( + prompt=prompt, image=source, mask_image=mask, image_reference=image_reference, strength=1.0 +).images[0] +image.save("kontext_inpainting_ref.png") +``` + ## Combining Flux Turbo LoRAs with Flux Control, Fill, and Redux 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") [[autodoc]] FluxFillPipeline - all - __call__ + +## FluxKontextPipeline + +[[autodoc]] FluxKontextPipeline + - all + - __call__ + +## FluxKontextInpaintPipeline + +[[autodoc]] FluxKontextInpaintPipeline + - all + - __call__ \ No newline at end of file From a8c93067a77727644baaf3bcb10b0a35aa263ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C6=B0=C6=A1ng=20=C4=90=C3=ACnh=20Minh?= <119489204+vuongminh1907@users.noreply.github.com> Date: Thu, 21 Aug 2025 09:09:31 +0700 Subject: [PATCH 2/5] Update docs/source/en/api/pipelines/flux.md Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com> --- docs/source/en/api/pipelines/flux.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/en/api/pipelines/flux.md b/docs/source/en/api/pipelines/flux.md index ee78c1bc66dc..ae1415c47a4e 100644 --- a/docs/source/en/api/pipelines/flux.md +++ b/docs/source/en/api/pipelines/flux.md @@ -317,7 +317,7 @@ if integrity_checker.test_image(image_): ``` ### Kontext Inpainting -The Kontext Inpainting Pipeline enables image modification within a fixed mask region. It currently supports both text-based conditioning and image-reference conditioning. +[`FluxKontextInpaintPipeline`] enables image modification within a fixed mask region. It currently supports both text-based conditioning and image-reference conditioning. #### Inpainting with text only ```python From cd5f8afee05539f4390d69c2159b3740731f8e12 Mon Sep 17 00:00:00 2001 From: vuongminh1907 Date: Thu, 21 Aug 2025 09:21:29 +0700 Subject: [PATCH 3/5] update kontext inpaint docs with hfoption --- docs/source/en/api/pipelines/flux.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/source/en/api/pipelines/flux.md b/docs/source/en/api/pipelines/flux.md index ae1415c47a4e..63780d359a22 100644 --- a/docs/source/en/api/pipelines/flux.md +++ b/docs/source/en/api/pipelines/flux.md @@ -317,7 +317,10 @@ if integrity_checker.test_image(image_): ``` ### Kontext Inpainting -[`FluxKontextInpaintPipeline`] enables image modification within a fixed mask region. It currently supports both text-based conditioning and image-reference conditioning. +`FluxKontextInpaintPipeline` enables image modification within a fixed mask region. It currently supports both text-based conditioning and image-reference conditioning. + + + #### Inpainting with text only ```python @@ -344,6 +347,8 @@ pipe.to("cuda") image = pipe(prompt=prompt, image=source, mask_image=mask, strength=1.0).images[0] image.save("kontext_inpainting_normal.png") ``` + + #### Inpainting with image conditioning ```python @@ -371,6 +376,8 @@ image = pipe( ).images[0] image.save("kontext_inpainting_ref.png") ``` + + ## Combining Flux Turbo LoRAs with Flux Control, Fill, and Redux From eb54b1b14d286119f4a082dd21b90180deac2a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C6=B0=C6=A1ng=20=C4=90=C3=ACnh=20Minh?= <119489204+vuongminh1907@users.noreply.github.com> Date: Fri, 22 Aug 2025 08:10:58 +0700 Subject: [PATCH 4/5] Update docs/source/en/api/pipelines/flux.md Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com> --- docs/source/en/api/pipelines/flux.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/en/api/pipelines/flux.md b/docs/source/en/api/pipelines/flux.md index 63780d359a22..a84d3d7ce444 100644 --- a/docs/source/en/api/pipelines/flux.md +++ b/docs/source/en/api/pipelines/flux.md @@ -321,7 +321,6 @@ if integrity_checker.test_image(image_): -#### Inpainting with text only ```python import torch From 3ef54fab462a687db7c5b71af9bcf6fa2de22a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C6=B0=C6=A1ng=20=C4=90=C3=ACnh=20Minh?= <119489204+vuongminh1907@users.noreply.github.com> Date: Fri, 22 Aug 2025 08:11:04 +0700 Subject: [PATCH 5/5] Update docs/source/en/api/pipelines/flux.md Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com> --- docs/source/en/api/pipelines/flux.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/en/api/pipelines/flux.md b/docs/source/en/api/pipelines/flux.md index a84d3d7ce444..bb7275822247 100644 --- a/docs/source/en/api/pipelines/flux.md +++ b/docs/source/en/api/pipelines/flux.md @@ -349,7 +349,6 @@ image.save("kontext_inpainting_normal.png") -#### Inpainting with image conditioning ```python import torch from diffusers import FluxKontextInpaintPipeline