Himanshu-AT commited on
Commit
98cede9
1 Parent(s): cfabc86

force push

Browse files
app.py CHANGED
@@ -1,21 +1,20 @@
1
  import gradio as gr
2
- import os
3
  from PIL import Image
4
  import torch
5
  from diffusers.utils import load_image, check_min_version
6
  from controlnet_flux import FluxControlNetModel
7
  from transformer_flux import FluxTransformer2DModel
8
  from pipeline_flux_controlnet_inpaint import FluxControlNetInpaintingPipeline
9
- import spaces
10
  import huggingface_hub
11
- huggingface_hub.login(os.getenv('HF_TOKEN_FLUX'))
12
 
13
  check_min_version("0.30.2")
14
  transformer = FluxTransformer2DModel.from_pretrained(
15
  "black-forest-labs/FLUX.1-dev", subfolder='transformer', torch_dytpe=torch.bfloat16
16
  )
17
 
18
-
19
  # Build pipeline
20
  controlnet = FluxControlNetModel.from_pretrained("alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Beta", torch_dtype=torch.bfloat16)
21
  pipe = FluxControlNetInpaintingPipeline.from_pretrained(
@@ -29,8 +28,9 @@ pipe.controlnet.to(torch.bfloat16)
29
 
30
 
31
  MARKDOWN = """
32
- # FLUX.1-dev-Inpainting-Model-Beta-GPU 🔥
33
- Model by alimama-creative
 
34
  """
35
 
36
  @spaces.GPU()
@@ -41,13 +41,13 @@ def process(input_image_editor,
41
  guidance_scale,
42
  seed,
43
  num_inference_steps,
44
- true_guidance_scale
45
  ):
46
  image = input_image_editor['background']
47
  mask = input_image_editor['layers'][0]
48
  size = (768, 768)
49
  image_or = image.copy()
50
-
51
  image = image.convert("RGB").resize(size)
52
  mask = mask.convert("RGB").resize(size)
53
  generator = torch.Generator(device="cuda").manual_seed(seed)
@@ -74,7 +74,7 @@ with gr.Blocks() as demo:
74
  input_image_editor_component = gr.ImageEditor(
75
  label='Image',
76
  type='pil',
77
- sources=["upload", "webcam"],
78
  image_mode='RGB',
79
  layers=False,
80
  brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"))
@@ -86,12 +86,12 @@ with gr.Blocks() as demo:
86
  seed = gr.Slider(minimum=0, step=1, maximum=10000000, value=124, label="Seed Value")
87
  num_inference_steps = gr.Slider(minimum=1, step=1, maximum=30, value=24, label="num_inference_steps")
88
  true_guidance_scale = gr.Slider(minimum=1, step=1, maximum=10, value=3.5, label="true_guidance_scale")
89
-
90
 
91
-
 
92
  submit_button_component = gr.Button(
93
  value='Submit', variant='primary', scale=0)
94
-
95
  with gr.Column():
96
  output_image_component = gr.Image(
97
  type='pil', image_mode='RGB', label='Generated image', format="png")
@@ -106,7 +106,7 @@ with gr.Blocks() as demo:
106
  guidance_scale,
107
  seed,
108
  num_inference_steps,
109
- true_guidance_scale
110
 
111
  ],
112
  outputs=[
@@ -116,4 +116,4 @@ with gr.Blocks() as demo:
116
 
117
 
118
 
119
- demo.launch(debug=False, show_error=True,share=True)
 
1
  import gradio as gr
2
+ import os
3
  from PIL import Image
4
  import torch
5
  from diffusers.utils import load_image, check_min_version
6
  from controlnet_flux import FluxControlNetModel
7
  from transformer_flux import FluxTransformer2DModel
8
  from pipeline_flux_controlnet_inpaint import FluxControlNetInpaintingPipeline
9
+ import spaces
10
  import huggingface_hub
11
+ huggingface_hub.login(os.getenv('HF_TOKEN'))
12
 
13
  check_min_version("0.30.2")
14
  transformer = FluxTransformer2DModel.from_pretrained(
15
  "black-forest-labs/FLUX.1-dev", subfolder='transformer', torch_dytpe=torch.bfloat16
16
  )
17
 
 
18
  # Build pipeline
19
  controlnet = FluxControlNetModel.from_pretrained("alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Beta", torch_dtype=torch.bfloat16)
20
  pipe = FluxControlNetInpaintingPipeline.from_pretrained(
 
28
 
29
 
30
  MARKDOWN = """
31
+ # FLUX.1-dev-Inpainting
32
+ Original Model: Flux.1-dev
33
+ FluxControlNet: alimama-creative
34
  """
35
 
36
  @spaces.GPU()
 
41
  guidance_scale,
42
  seed,
43
  num_inference_steps,
44
+ true_guidance_scale
45
  ):
46
  image = input_image_editor['background']
47
  mask = input_image_editor['layers'][0]
48
  size = (768, 768)
49
  image_or = image.copy()
50
+
51
  image = image.convert("RGB").resize(size)
52
  mask = mask.convert("RGB").resize(size)
53
  generator = torch.Generator(device="cuda").manual_seed(seed)
 
74
  input_image_editor_component = gr.ImageEditor(
75
  label='Image',
76
  type='pil',
77
+ sources=["upload"],
78
  image_mode='RGB',
79
  layers=False,
80
  brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"))
 
86
  seed = gr.Slider(minimum=0, step=1, maximum=10000000, value=124, label="Seed Value")
87
  num_inference_steps = gr.Slider(minimum=1, step=1, maximum=30, value=24, label="num_inference_steps")
88
  true_guidance_scale = gr.Slider(minimum=1, step=1, maximum=10, value=3.5, label="true_guidance_scale")
 
89
 
90
+
91
+
92
  submit_button_component = gr.Button(
93
  value='Submit', variant='primary', scale=0)
94
+
95
  with gr.Column():
96
  output_image_component = gr.Image(
97
  type='pil', image_mode='RGB', label='Generated image', format="png")
 
106
  guidance_scale,
107
  seed,
108
  num_inference_steps,
109
+ true_guidance_scale
110
 
111
  ],
112
  outputs=[
 
116
 
117
 
118
 
119
+ demo.launch(debug=False, show_error=True,share=True)
images/0.jpg DELETED
Binary file (322 kB)
 
images/1.jpg DELETED
Binary file (474 kB)
 
images/2.jpg DELETED
Binary file (196 kB)
 
images/3.jpg DELETED
Binary file (556 kB)
 
images/alibaba.png DELETED
Binary file (13 kB)
 
images/alibabaalimama.png DELETED
Binary file (89.6 kB)
 
images/alimama.png DELETED
Binary file (30.2 kB)
 
images/flux1.jpg DELETED
Binary file (160 kB)
 
images/flux2.jpg DELETED
Binary file (210 kB)
 
images/flux3.jpg DELETED
Binary file (287 kB)
 
main.py DELETED
@@ -1,50 +0,0 @@
1
- import torch
2
- from diffusers.utils import load_image, check_min_version
3
- from controlnet_flux import FluxControlNetModel
4
- from transformer_flux import FluxTransformer2DModel
5
- from pipeline_flux_controlnet_inpaint import FluxControlNetInpaintingPipeline
6
-
7
- check_min_version("0.30.2")
8
-
9
- # Set image path , mask path and prompt
10
- image_path='https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/bucket.png',
11
- mask_path='https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/bucket_mask.jpeg',
12
- prompt='a person wearing a white shoe, carrying a white bucket with text "FLUX" on it'
13
-
14
- # Build pipeline
15
- controlnet = FluxControlNetModel.from_pretrained("alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha", torch_dtype=torch.bfloat16)
16
- transformer = FluxTransformer2DModel.from_pretrained(
17
- "black-forest-labs/FLUX.1-dev", subfolder='transformer', torch_dytpe=torch.bfloat16
18
- )
19
- pipe = FluxControlNetInpaintingPipeline.from_pretrained(
20
- "black-forest-labs/FLUX.1-dev",
21
- controlnet=controlnet,
22
- transformer=transformer,
23
- torch_dtype=torch.bfloat16
24
- ).to("cuda")
25
- pipe.transformer.to(torch.bfloat16)
26
- pipe.controlnet.to(torch.bfloat16)
27
-
28
- # Load image and mask
29
- size = (768, 768)
30
- image = load_image(image_path).convert("RGB").resize(size)
31
- mask = load_image(mask_path).convert("RGB").resize(size)
32
- generator = torch.Generator(device="cuda").manual_seed(24)
33
-
34
- # Inpaint
35
- result = pipe(
36
- prompt=prompt,
37
- height=size[1],
38
- width=size[0],
39
- control_image=image,
40
- control_mask=mask,
41
- num_inference_steps=28,
42
- generator=generator,
43
- controlnet_conditioning_scale=0.9,
44
- guidance_scale=3.5,
45
- negative_prompt="",
46
- true_guidance_scale=3.5
47
- ).images[0]
48
-
49
- result.save('flux_inpaint.png')
50
- print("Successfully inpaint image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.md CHANGED
@@ -1,78 +1,11 @@
1
- <div style="display: flex;align-items: center;">
2
- <img src="images/alibabaalimama.png" alt="alibaba" style="width: 40%; height: auto; margin: 0 10px;">
3
- </div>
4
-
5
- This repository provides a Inpainting ControlNet checkpoint for [FLUX.1-dev](https://huggingface.co/black-forest-labs/FLUX.1-dev) model released by researchers from AlimamaCreative Team.
6
-
7
- ## News
8
-
9
- 🎉 Thanks to @comfyanonymous,ComfyUI now supports inference for Alimama inpainting ControlNet. Workflow can be downloaded from [here](https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/alimama-flux-controlnet-inpaint.json).
10
-
11
- ComfyUI Usage Tips:
12
-
13
- * Using the `t5xxl-FP16` and `flux1-dev-fp8` models for 28-step inference, the GPU memory usage is 27GB. The inference time with `cfg=3.5` is 27 seconds, while without `cfg=1` it is 15 seconds. `Hyper-FLUX-lora` can be used to accelerate inference.
14
- * You can try adjusting(lower) the parameters `control-strength`, `control-end-percent`, and `cfg` to achieve better results.
15
- * The following example uses `control-strength` = 0.9 & `control-end-percent` = 1.0 & `cfg` = 3.5
16
-
17
- | Input | Output | Prompt |
18
- |------------------------------|------------------------------|-------------|
19
- | ![Image1](https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/comfy_in_1.png) | ![Image2](https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/comfy_out_1.png) | <small><i>The image depicts a scene from the anime series Dragon Ball Z, with the characters Goku, <span style="color:red; font-weight:bold;">Elon Musk</span>, and a child version of Gohan sharing a meal of ramen noodles. They are all sitting around a dining table, with Goku and Gohan on one side and Naruto on the other. They are all holding chopsticks and eating the noodles. The table is set with bowls of ramen, cups, and bowls of drinks. The arrangement of the characters and the food creates a sense of camaraderie and shared enjoyment of the meal. |
20
- | ![Image3](https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/comfy_in_2.png) | ![Image4](https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/comfy_out_2.png) | <small><i>The image is an illustration of a man standing in a cafe. He is wearing a white turtleneck, a camel-colored trench coat, and brown shoes. He is holding a cell phone and appears to be looking at it. There is a small table with <span style="color:red; font-weight:bold;">a cat</span> on it to his right. In the background, there is another man sitting at a table with a laptop. The man is wearing a black turtleneck and a tie. </i></small>|
21
- | ![Image5](https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/comfy_in_3.png) | ![Image6](https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/comfy_out_3.png) | <small><i>A woman with blonde hair is sitting on a table wearing a <span style="color:red; font-weight:bold;">red and white long dress</span>. She is holding a green phone in her hand and appears to be taking a photo. There is a bag next to her on the table and a handbag beside her on the chair. The woman is looking at the phone with a smile on her face. The background includes a TV on the left wall and a couch on the right. A chair is also present in the scene. </i></small>|
22
- | ![Image7](https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/comfy_in_4.png) | ![Image8](https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha/resolve/main/images/comfy_out_4.png) | <small><i>The image depicts a beautiful young woman sitting at a desk, reading a book. She has long, wavy brown hair and is wearing a grey shirt with a black cardigan. She is holding a <span style="color:red; font-weight:bold;">red pencil</span> in her left hand and appears to be deep in thought. Surrounding her are numerous books, some stacked on the desk and others placed on a shelf behind her. A potted plant is also visible in the background, adding a touch of greenery to the scene. The image conveys a sense of serenity and intellectual pursuits. </i></small>|
23
-
24
-
25
- ## Model Cards
26
-
27
- <!-- 使用HTML来调整图标大小 -->
28
- <a href="https://huggingface.co/alimama-creative/FLUX.1-dev-Controlnet-Inpainting-Alpha" target="_blank">
29
- <img src="https://huggingface.co/favicon.ico" alt="Hugging Face" width="25" height="25" /> The model weights have been uploaded to Hugging Face.
30
- </a>
31
-
32
- * The model was trained on 12M laion2B and internal source images at resolution 768x768. The inference performs best at this size, with other sizes yielding suboptimal results.
33
-
34
- * The recommended controlnet_conditioning_scale is 0.9 - 0.95.
35
-
36
- * **Please note: This is only the alpha version during the training process. We will release an updated version when we feel ready.**
37
-
38
- ## Showcase
39
-
40
- ![flux1](images/flux1.jpg)
41
- ![flux2](images/flux2.jpg)
42
- ![flux3](images/flux3.jpg)
43
-
44
- ## Comparison with SDXL-Inpainting
45
-
46
- Compared with [SDXL-Inpainting](https://huggingface.co/diffusers/stable-diffusion-xl-1.0-inpainting-0.1)
47
-
48
- From left to right: Input image | Masked image | SDXL inpainting | Ours
49
-
50
- ![0](images/0.jpg)
51
- <small><i>*The image depicts a beautiful young woman sitting at a desk, reading a book. She has long, wavy brown hair and is wearing a grey shirt with a black cardigan. She is holding a pencil in her left hand and appears to be deep in thought. Surrounding her are numerous books, some stacked on the desk and others placed on a shelf behind her. A potted plant is also visible in the background, adding a touch of greenery to the scene. The image conveys a sense of serenity and intellectual pursuits.*</i></small>
52
-
53
- ![0](images/1.jpg)
54
- <small><i>A woman with blonde hair is sitting on a table wearing a blue and white long dress. She is holding a green phone in her hand and appears to be taking a photo. There is a bag next to her on the table and a handbag beside her on the chair. The woman is looking at the phone with a smile on her face. The background includes a TV on the left wall and a couch on the right. A chair is also present in the scene.</i></small>
55
-
56
- ![0](images/2.jpg)
57
- <small><i>The image is an illustration of a man standing in a cafe. He is wearing a white turtleneck, a camel-colored trench coat, and brown shoes. He is holding a cell phone and appears to be looking at it. There is a small table with a cup of coffee on it to his right. In the background, there is another man sitting at a table with a laptop. The man is wearing a black turtleneck and a tie. There are several cups and a cake on the table in the background. The man sitting at the table appears to be typing on the laptop.</i></small>
58
-
59
- ![0](images/3.jpg)
60
- <small><i>The image depicts a scene from the anime series Dragon Ball Z, with the characters Goku, Naruto, and a child version of Gohan sharing a meal of ramen noodles. They are all sitting around a dining table, with Goku and Gohan on one side and Naruto on the other. They are all holding chopsticks and eating the noodles. The table is set with bowls of ramen, cups, and bowls of drinks. The arrangement of the characters and the food creates a sense of camaraderie and shared enjoyment of the meal.</i></small>
61
-
62
- ## Using with Diffusers
63
- Step1: install diffusers
64
- ``` Shell
65
- pip install diffusers==0.30.2
66
- ```
67
-
68
- Step2: clone repo from github
69
- ``` Shell
70
- git clone https://github.com/alimama-creative/FLUX-Controlnet-Inpainting.git
71
- ```
72
-
73
- Step3: modify the image_path, mask_path, prompt and run
74
- ``` Shell
75
- python main.py
76
- ```
77
- ## LICENSE
78
- Our weights fall under the [FLUX.1 [dev]](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md) Non-Commercial License.
 
1
+ ---
2
+ title: FluxInpaint
3
+ emoji: 🎨
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 5.8.0
8
+ app_file: main.py
9
+ short_description: Demonstration of Flux inpainting capabilities
10
+ pinned: true
11
+ ---