Spaces:
Running
Running
use customer diffuser
Browse files- app.py +145 -145
- requirements.txt +1 -1
app.py
CHANGED
@@ -1,148 +1,8 @@
|
|
1 |
-
# import gradio as gr
|
2 |
-
# import numpy as np
|
3 |
-
# import random
|
4 |
-
# # import spaces
|
5 |
-
# import torch
|
6 |
-
# from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler, AutoencoderTiny, AutoencoderKL
|
7 |
-
# from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
|
8 |
-
# # from live_preview_helpers import calculate_shift, retrieve_timesteps, flux_pipe_call_that_returns_an_iterable_of_images
|
9 |
-
#
|
10 |
-
# dtype = torch.bfloat16
|
11 |
-
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
-
#
|
13 |
-
# taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
|
14 |
-
# good_vae = AutoencoderKL.from_pretrained("black-forest-labs/FLUX.1-schnell", subfolder="vae", torch_dtype=dtype).to(device)
|
15 |
-
# pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype, vae=taef1).to(device)
|
16 |
-
# torch.cuda.empty_cache()
|
17 |
-
#
|
18 |
-
# MAX_SEED = np.iinfo(np.int32).max
|
19 |
-
# MAX_IMAGE_SIZE = 2048
|
20 |
-
#
|
21 |
-
# # pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
|
22 |
-
#
|
23 |
-
# # @spaces.GPU(duration=75)
|
24 |
-
# def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
|
25 |
-
# if randomize_seed:
|
26 |
-
# seed = random.randint(0, MAX_SEED)
|
27 |
-
# generator = torch.Generator().manual_seed(seed)
|
28 |
-
#
|
29 |
-
# for img in pipe.flux_pipe_call_that_returns_an_iterable_of_images(
|
30 |
-
# prompt=prompt,
|
31 |
-
# guidance_scale=guidance_scale,
|
32 |
-
# num_inference_steps=num_inference_steps,
|
33 |
-
# width=width,
|
34 |
-
# height=height,
|
35 |
-
# generator=generator,
|
36 |
-
# output_type="pil",
|
37 |
-
# good_vae=good_vae,
|
38 |
-
# ):
|
39 |
-
# yield img, seed
|
40 |
-
#
|
41 |
-
# examples = [
|
42 |
-
# "a tiny astronaut hatching from an egg on the moon",
|
43 |
-
# "a cat holding a sign that says hello world",
|
44 |
-
# "an anime illustration of a wiener schnitzel",
|
45 |
-
# ]
|
46 |
-
#
|
47 |
-
# css="""
|
48 |
-
# #col-container {
|
49 |
-
# margin: 0 auto;
|
50 |
-
# max-width: 520px;
|
51 |
-
# }
|
52 |
-
# """
|
53 |
-
#
|
54 |
-
# with gr.Blocks(css=css) as demo:
|
55 |
-
#
|
56 |
-
# with gr.Column(elem_id="col-container"):
|
57 |
-
# gr.Markdown(f"""# FLUX.1 [dev]
|
58 |
-
# 12B param rectified flow transformer guidance-distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/)
|
59 |
-
# [[non-commercial license](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md)] [[blog](https://blackforestlabs.ai/announcing-black-forest-labs/)] [[model](https://huggingface.co/black-forest-labs/FLUX.1-dev)]
|
60 |
-
# """)
|
61 |
-
#
|
62 |
-
# with gr.Row():
|
63 |
-
#
|
64 |
-
# prompt = gr.Text(
|
65 |
-
# label="Prompt",
|
66 |
-
# show_label=False,
|
67 |
-
# max_lines=1,
|
68 |
-
# placeholder="Enter your prompt",
|
69 |
-
# container=False,
|
70 |
-
# )
|
71 |
-
#
|
72 |
-
# run_button = gr.Button("Run", scale=0)
|
73 |
-
#
|
74 |
-
# result = gr.Image(label="Result", show_label=False)
|
75 |
-
#
|
76 |
-
# with gr.Accordion("Advanced Settings", open=False):
|
77 |
-
#
|
78 |
-
# seed = gr.Slider(
|
79 |
-
# label="Seed",
|
80 |
-
# minimum=0,
|
81 |
-
# maximum=MAX_SEED,
|
82 |
-
# step=1,
|
83 |
-
# value=0,
|
84 |
-
# )
|
85 |
-
#
|
86 |
-
# randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
87 |
-
#
|
88 |
-
# with gr.Row():
|
89 |
-
#
|
90 |
-
# width = gr.Slider(
|
91 |
-
# label="Width",
|
92 |
-
# minimum=256,
|
93 |
-
# maximum=MAX_IMAGE_SIZE,
|
94 |
-
# step=32,
|
95 |
-
# value=1024,
|
96 |
-
# )
|
97 |
-
#
|
98 |
-
# height = gr.Slider(
|
99 |
-
# label="Height",
|
100 |
-
# minimum=256,
|
101 |
-
# maximum=MAX_IMAGE_SIZE,
|
102 |
-
# step=32,
|
103 |
-
# value=1024,
|
104 |
-
# )
|
105 |
-
#
|
106 |
-
# with gr.Row():
|
107 |
-
#
|
108 |
-
# guidance_scale = gr.Slider(
|
109 |
-
# label="Guidance Scale",
|
110 |
-
# minimum=1,
|
111 |
-
# maximum=15,
|
112 |
-
# step=0.1,
|
113 |
-
# value=3.5,
|
114 |
-
# )
|
115 |
-
#
|
116 |
-
# num_inference_steps = gr.Slider(
|
117 |
-
# label="Number of inference steps",
|
118 |
-
# minimum=1,
|
119 |
-
# maximum=50,
|
120 |
-
# step=1,
|
121 |
-
# value=28,
|
122 |
-
# )
|
123 |
-
#
|
124 |
-
# gr.Examples(
|
125 |
-
# examples = examples,
|
126 |
-
# fn = infer,
|
127 |
-
# inputs = [prompt],
|
128 |
-
# outputs = [result, seed],
|
129 |
-
# cache_examples="lazy"
|
130 |
-
# )
|
131 |
-
#
|
132 |
-
# gr.on(
|
133 |
-
# triggers=[run_button.click, prompt.submit],
|
134 |
-
# fn = infer,
|
135 |
-
# inputs = [prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
136 |
-
# outputs = [result, seed]
|
137 |
-
# )
|
138 |
-
#
|
139 |
-
# demo.launch()
|
140 |
-
|
141 |
-
import torch
|
142 |
import sentencepiece
|
|
|
143 |
import spaces
|
144 |
import gradio as gr
|
145 |
-
from diffusers.pipelines.flux.
|
146 |
from diffusers.models.controlnet_flux import FluxControlNetModel
|
147 |
from controlnet_aux import CannyDetector
|
148 |
|
@@ -153,12 +13,11 @@ base_model = "black-forest-labs/FLUX.1-schnell"
|
|
153 |
controlnet_model = "YishaoAI/flux-dev-controlnet-canny-kid-clothes"
|
154 |
|
155 |
controlnet = FluxControlNetModel.from_pretrained(controlnet_model, torch_dtype=dtype)
|
156 |
-
pipe =
|
157 |
base_model, controlnet=controlnet, torch_dtype=dtype
|
158 |
).to(device)
|
159 |
|
160 |
pipe.enable_model_cpu_offload()
|
161 |
-
# pipe.to("cuda")
|
162 |
|
163 |
canny = CannyDetector()
|
164 |
|
@@ -202,6 +61,147 @@ iface = gr.Interface(
|
|
202 |
outputs=gr.Image(type="pil", label="Output Image"),
|
203 |
title="Flux Inpaint AI Model",
|
204 |
description="Upload an image and a mask, then provide a prompt to generate an inpainted image.",
|
205 |
-
)
|
206 |
|
207 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import sentencepiece
|
2 |
+
import torch
|
3 |
import spaces
|
4 |
import gradio as gr
|
5 |
+
from diffusers.pipelines.flux.pipeline_flux_controlnet_inpaint import FluxControlNetInpaintPipeline
|
6 |
from diffusers.models.controlnet_flux import FluxControlNetModel
|
7 |
from controlnet_aux import CannyDetector
|
8 |
|
|
|
13 |
controlnet_model = "YishaoAI/flux-dev-controlnet-canny-kid-clothes"
|
14 |
|
15 |
controlnet = FluxControlNetModel.from_pretrained(controlnet_model, torch_dtype=dtype)
|
16 |
+
pipe = FluxControlNetInpaintPipeline.from_pretrained(
|
17 |
base_model, controlnet=controlnet, torch_dtype=dtype
|
18 |
).to(device)
|
19 |
|
20 |
pipe.enable_model_cpu_offload()
|
|
|
21 |
|
22 |
canny = CannyDetector()
|
23 |
|
|
|
61 |
outputs=gr.Image(type="pil", label="Output Image"),
|
62 |
title="Flux Inpaint AI Model",
|
63 |
description="Upload an image and a mask, then provide a prompt to generate an inpainted image.",
|
64 |
+
)
|
65 |
|
66 |
iface.launch()
|
67 |
+
|
68 |
+
# import gradio as gr
|
69 |
+
# import numpy as np
|
70 |
+
# import random
|
71 |
+
# # import spaces
|
72 |
+
# import torch
|
73 |
+
# from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler, AutoencoderTiny, AutoencoderKL
|
74 |
+
# from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
|
75 |
+
# # from live_preview_helpers import calculate_shift, retrieve_timesteps, flux_pipe_call_that_returns_an_iterable_of_images
|
76 |
+
#
|
77 |
+
# dtype = torch.bfloat16
|
78 |
+
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
79 |
+
#
|
80 |
+
# taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
|
81 |
+
# good_vae = AutoencoderKL.from_pretrained("black-forest-labs/FLUX.1-schnell", subfolder="vae", torch_dtype=dtype).to(device)
|
82 |
+
# pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype, vae=taef1).to(device)
|
83 |
+
# torch.cuda.empty_cache()
|
84 |
+
#
|
85 |
+
# MAX_SEED = np.iinfo(np.int32).max
|
86 |
+
# MAX_IMAGE_SIZE = 2048
|
87 |
+
#
|
88 |
+
# # pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
|
89 |
+
#
|
90 |
+
# # @spaces.GPU(duration=75)
|
91 |
+
# def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=28, progress=gr.Progress(track_tqdm=True)):
|
92 |
+
# if randomize_seed:
|
93 |
+
# seed = random.randint(0, MAX_SEED)
|
94 |
+
# generator = torch.Generator().manual_seed(seed)
|
95 |
+
#
|
96 |
+
# for img in pipe.flux_pipe_call_that_returns_an_iterable_of_images(
|
97 |
+
# prompt=prompt,
|
98 |
+
# guidance_scale=guidance_scale,
|
99 |
+
# num_inference_steps=num_inference_steps,
|
100 |
+
# width=width,
|
101 |
+
# height=height,
|
102 |
+
# generator=generator,
|
103 |
+
# output_type="pil",
|
104 |
+
# good_vae=good_vae,
|
105 |
+
# ):
|
106 |
+
# yield img, seed
|
107 |
+
#
|
108 |
+
# examples = [
|
109 |
+
# "a tiny astronaut hatching from an egg on the moon",
|
110 |
+
# "a cat holding a sign that says hello world",
|
111 |
+
# "an anime illustration of a wiener schnitzel",
|
112 |
+
# ]
|
113 |
+
#
|
114 |
+
# css="""
|
115 |
+
# #col-container {
|
116 |
+
# margin: 0 auto;
|
117 |
+
# max-width: 520px;
|
118 |
+
# }
|
119 |
+
# """
|
120 |
+
#
|
121 |
+
# with gr.Blocks(css=css) as demo:
|
122 |
+
#
|
123 |
+
# with gr.Column(elem_id="col-container"):
|
124 |
+
# gr.Markdown(f"""# FLUX.1 [dev]
|
125 |
+
# 12B param rectified flow transformer guidance-distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/)
|
126 |
+
# [[non-commercial license](https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md)] [[blog](https://blackforestlabs.ai/announcing-black-forest-labs/)] [[model](https://huggingface.co/black-forest-labs/FLUX.1-dev)]
|
127 |
+
# """)
|
128 |
+
#
|
129 |
+
# with gr.Row():
|
130 |
+
#
|
131 |
+
# prompt = gr.Text(
|
132 |
+
# label="Prompt",
|
133 |
+
# show_label=False,
|
134 |
+
# max_lines=1,
|
135 |
+
# placeholder="Enter your prompt",
|
136 |
+
# container=False,
|
137 |
+
# )
|
138 |
+
#
|
139 |
+
# run_button = gr.Button("Run", scale=0)
|
140 |
+
#
|
141 |
+
# result = gr.Image(label="Result", show_label=False)
|
142 |
+
#
|
143 |
+
# with gr.Accordion("Advanced Settings", open=False):
|
144 |
+
#
|
145 |
+
# seed = gr.Slider(
|
146 |
+
# label="Seed",
|
147 |
+
# minimum=0,
|
148 |
+
# maximum=MAX_SEED,
|
149 |
+
# step=1,
|
150 |
+
# value=0,
|
151 |
+
# )
|
152 |
+
#
|
153 |
+
# randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
154 |
+
#
|
155 |
+
# with gr.Row():
|
156 |
+
#
|
157 |
+
# width = gr.Slider(
|
158 |
+
# label="Width",
|
159 |
+
# minimum=256,
|
160 |
+
# maximum=MAX_IMAGE_SIZE,
|
161 |
+
# step=32,
|
162 |
+
# value=1024,
|
163 |
+
# )
|
164 |
+
#
|
165 |
+
# height = gr.Slider(
|
166 |
+
# label="Height",
|
167 |
+
# minimum=256,
|
168 |
+
# maximum=MAX_IMAGE_SIZE,
|
169 |
+
# step=32,
|
170 |
+
# value=1024,
|
171 |
+
# )
|
172 |
+
#
|
173 |
+
# with gr.Row():
|
174 |
+
#
|
175 |
+
# guidance_scale = gr.Slider(
|
176 |
+
# label="Guidance Scale",
|
177 |
+
# minimum=1,
|
178 |
+
# maximum=15,
|
179 |
+
# step=0.1,
|
180 |
+
# value=3.5,
|
181 |
+
# )
|
182 |
+
#
|
183 |
+
# num_inference_steps = gr.Slider(
|
184 |
+
# label="Number of inference steps",
|
185 |
+
# minimum=1,
|
186 |
+
# maximum=50,
|
187 |
+
# step=1,
|
188 |
+
# value=28,
|
189 |
+
# )
|
190 |
+
#
|
191 |
+
# gr.Examples(
|
192 |
+
# examples = examples,
|
193 |
+
# fn = infer,
|
194 |
+
# inputs = [prompt],
|
195 |
+
# outputs = [result, seed],
|
196 |
+
# cache_examples="lazy"
|
197 |
+
# )
|
198 |
+
#
|
199 |
+
# gr.on(
|
200 |
+
# triggers=[run_button.click, prompt.submit],
|
201 |
+
# fn = infer,
|
202 |
+
# inputs = [prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
203 |
+
# outputs = [result, seed]
|
204 |
+
# )
|
205 |
+
#
|
206 |
+
# demo.launch()
|
207 |
+
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
torch
|
2 |
-
git+https://github.com/
|
3 |
transformers
|
4 |
accelerate
|
5 |
controlnet_aux
|
|
|
1 |
torch
|
2 |
+
git+https://github.com/culda/flux-controlnet-inpaint.git
|
3 |
transformers
|
4 |
accelerate
|
5 |
controlnet_aux
|