Spaces:
Running
on
Zero
Running
on
Zero
Upload 4 files
Browse files- README.md +1 -1
- app.py +43 -26
- requirements.txt +1 -1
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title: FLUX.1 [dev]
|
3 |
emoji: 🖥️
|
4 |
colorFrom: yellow
|
5 |
colorTo: pink
|
|
|
1 |
---
|
2 |
+
title: FLUX.1 [dev] sigmas test
|
3 |
emoji: 🖥️
|
4 |
colorFrom: yellow
|
5 |
colorTo: pink
|
app.py
CHANGED
@@ -7,13 +7,14 @@ from diffusers import DiffusionPipeline, FlowMatchEulerDiscreteScheduler, Autoe
|
|
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 |
from gradio_imageslider import ImageSlider
|
|
|
10 |
|
11 |
dtype = torch.bfloat16
|
12 |
#model_id = "black-forest-labs/FLUX.1-dev"
|
13 |
model_id = "camenduru/FLUX.1-dev-diffusers"
|
14 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
15 |
|
16 |
-
taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
|
17 |
good_vae = AutoencoderKL.from_pretrained(model_id, subfolder="vae", torch_dtype=dtype).to(device)
|
18 |
#pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=dtype, vae=taef1).to(device)
|
19 |
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=dtype, vae=good_vae).to(device)
|
@@ -24,23 +25,24 @@ MAX_IMAGE_SIZE = 2048
|
|
24 |
|
25 |
pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
@spaces.GPU(duration=90)
|
28 |
-
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=28,
|
29 |
if randomize_seed:
|
30 |
seed = random.randint(0, MAX_SEED)
|
31 |
generator = torch.Generator().manual_seed(seed)
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
guidance_scale=guidance_scale,
|
37 |
-
num_inference_steps=num_inference_steps,
|
38 |
-
width=width,
|
39 |
-
height=height,
|
40 |
-
generator=generator,
|
41 |
-
output_type="pil",
|
42 |
-
).images[0]
|
43 |
-
# yield img, seed
|
44 |
image_sigmas = pipe(
|
45 |
prompt=prompt,
|
46 |
guidance_scale=guidance_scale,
|
@@ -49,10 +51,22 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidan
|
|
49 |
height=height,
|
50 |
generator=generator,
|
51 |
output_type="pil",
|
52 |
-
|
53 |
).images[0]
|
54 |
-
return [image_def, image_sigmas], seed
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
examples = [
|
57 |
"a tiny astronaut hatching from an egg on the moon",
|
58 |
"a cat holding a sign that says hello world",
|
@@ -87,16 +101,19 @@ with gr.Blocks(css=css) as demo:
|
|
87 |
run_button = gr.Button("Run", scale=0)
|
88 |
|
89 |
#result = gr.Image(label="Result", show_label=False)
|
90 |
-
result = ImageSlider(label="Result", show_label=False, type="pil", slider_color="pink")
|
|
|
91 |
|
92 |
with gr.Accordion("Advanced Settings", open=True):
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
100 |
|
101 |
seed = gr.Slider(
|
102 |
label="Seed",
|
@@ -148,15 +165,15 @@ with gr.Blocks(css=css) as demo:
|
|
148 |
examples = examples,
|
149 |
fn = infer,
|
150 |
inputs = [prompt],
|
151 |
-
outputs = [result, seed],
|
152 |
cache_examples="lazy"
|
153 |
)
|
154 |
|
155 |
gr.on(
|
156 |
triggers=[run_button.click, prompt.submit],
|
157 |
fn = infer,
|
158 |
-
inputs = [prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, sigmas],
|
159 |
-
outputs = [result, seed]
|
160 |
)
|
161 |
|
162 |
demo.launch()
|
|
|
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 |
from gradio_imageslider import ImageSlider
|
10 |
+
from PIL import Image, ImageDraw
|
11 |
|
12 |
dtype = torch.bfloat16
|
13 |
#model_id = "black-forest-labs/FLUX.1-dev"
|
14 |
model_id = "camenduru/FLUX.1-dev-diffusers"
|
15 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
16 |
|
17 |
+
#taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device)
|
18 |
good_vae = AutoencoderKL.from_pretrained(model_id, subfolder="vae", torch_dtype=dtype).to(device)
|
19 |
#pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=dtype, vae=taef1).to(device)
|
20 |
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=dtype, vae=good_vae).to(device)
|
|
|
25 |
|
26 |
pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
|
27 |
|
28 |
+
def get_cmp_image(im1: Image.Image, im2: Image.Image, sigmas: float):
|
29 |
+
dst = Image.new('RGB', (im1.width + im2.width, im1.height))
|
30 |
+
dst.paste(im1.convert('RGB'), (0, 0))
|
31 |
+
dst.paste(im2.convert('RGB'), (im1.width, 0))
|
32 |
+
draw = ImageDraw.Draw(dst)
|
33 |
+
draw.text((64, 64), 'Sigmas: 1.0', 'red')
|
34 |
+
draw.text((im1.width + 64, 64), f'Sigmas: {sigmas}', 'red')
|
35 |
+
return dst
|
36 |
+
|
37 |
@spaces.GPU(duration=90)
|
38 |
+
def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=3.5, num_inference_steps=28, mul_sigmas=0.95, is_cmp=True, progress=gr.Progress(track_tqdm=True)):
|
39 |
if randomize_seed:
|
40 |
seed = random.randint(0, MAX_SEED)
|
41 |
generator = torch.Generator().manual_seed(seed)
|
42 |
|
43 |
+
sigmas = np.linspace(1.0, 1 / num_inference_steps, num_inference_steps)
|
44 |
+
sigmas = sigmas * mul_sigmas
|
45 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
image_sigmas = pipe(
|
47 |
prompt=prompt,
|
48 |
guidance_scale=guidance_scale,
|
|
|
51 |
height=height,
|
52 |
generator=generator,
|
53 |
output_type="pil",
|
54 |
+
sigmas=sigmas
|
55 |
).images[0]
|
|
|
56 |
|
57 |
+
if is_cmp:
|
58 |
+
image_def = pipe(
|
59 |
+
prompt=prompt,
|
60 |
+
guidance_scale=guidance_scale,
|
61 |
+
num_inference_steps=num_inference_steps,
|
62 |
+
width=width,
|
63 |
+
height=height,
|
64 |
+
generator=generator,
|
65 |
+
output_type="pil",
|
66 |
+
).images[0]
|
67 |
+
return [image_def, image_sigmas], get_cmp_image(image_def, image_sigmas), seed
|
68 |
+
else: return [image_sigmas, image_sigmas], None, seed
|
69 |
+
|
70 |
examples = [
|
71 |
"a tiny astronaut hatching from an egg on the moon",
|
72 |
"a cat holding a sign that says hello world",
|
|
|
101 |
run_button = gr.Button("Run", scale=0)
|
102 |
|
103 |
#result = gr.Image(label="Result", show_label=False)
|
104 |
+
result = ImageSlider(label="Result", show_label=False, type="pil", slider_color="pink", format="png")
|
105 |
+
result_cmp = gr.Image(label="Result (comparing)", show_label=False, type="pil", format="png", height=256)
|
106 |
|
107 |
with gr.Accordion("Advanced Settings", open=True):
|
108 |
+
with gr.Row():
|
109 |
+
sigmas = gr.Slider(
|
110 |
+
label="Sigmas",
|
111 |
+
minimum=0,
|
112 |
+
maximum=1.0,
|
113 |
+
step=0.01,
|
114 |
+
value=0.95,
|
115 |
+
)
|
116 |
+
is_cmp = gr.Checkbox("Compare images with/without sigmas")
|
117 |
|
118 |
seed = gr.Slider(
|
119 |
label="Seed",
|
|
|
165 |
examples = examples,
|
166 |
fn = infer,
|
167 |
inputs = [prompt],
|
168 |
+
outputs = [result, result_cmp, seed],
|
169 |
cache_examples="lazy"
|
170 |
)
|
171 |
|
172 |
gr.on(
|
173 |
triggers=[run_button.click, prompt.submit],
|
174 |
fn = infer,
|
175 |
+
inputs = [prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, sigmas, is_cmp],
|
176 |
+
outputs = [result, result_cmp, seed]
|
177 |
)
|
178 |
|
179 |
demo.launch()
|
requirements.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
accelerate
|
2 |
#git+https://github.com/huggingface/diffusers.git
|
3 |
-
git+https://github.com/huggingface/diffusers.git@
|
4 |
torch
|
5 |
transformers==4.42.4
|
6 |
xformers
|
|
|
1 |
accelerate
|
2 |
#git+https://github.com/huggingface/diffusers.git
|
3 |
+
#git+https://github.com/huggingface/diffusers.git@6b1c4a766b7f83fe06ddb9bbb58c1122072efefegit+https://github.com/huggingface/diffusers.git@ad3344e2be033887d854d2731757db8b80dcfb06
|
4 |
torch
|
5 |
transformers==4.42.4
|
6 |
xformers
|