Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,7 +36,7 @@ controlnet_model = 'InstantX/FLUX.1-dev-Controlnet-Canny-alpha'
|
|
| 36 |
# t5_slider_controlnet = T5SliderFlux(sd_pipe=pipe_controlnet,device=torch.device("cuda"))
|
| 37 |
|
| 38 |
@spaces.GPU(duration=200)
|
| 39 |
-
def generate(slider_x, prompt, seed, recalc_directions, iterations, steps, guidance_scale,
|
| 40 |
x_concept_1, x_concept_2,
|
| 41 |
avg_diff_x,
|
| 42 |
img2img_type = None, img = None,
|
|
@@ -54,26 +54,24 @@ def generate(slider_x, prompt, seed, recalc_directions, iterations, steps, guida
|
|
| 54 |
avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations)
|
| 55 |
x_concept_1, x_concept_2 = slider_x[0], slider_x[1]
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
else: # text to image
|
| 63 |
-
print("WHY 1")
|
| 64 |
image = clip_slider.generate(prompt,
|
| 65 |
#guidance_scale=guidance_scale,
|
| 66 |
-
scale=
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
comma_concepts_x = f"{slider_x[1]}, {slider_x[0]}"
|
| 73 |
|
| 74 |
avg_diff_x = avg_diff.cpu()
|
| 75 |
|
| 76 |
-
return gr.update(label=comma_concepts_x, interactive=True, value=0), x_concept_1, x_concept_2, avg_diff_x
|
| 77 |
|
| 78 |
@spaces.GPU
|
| 79 |
def update_scales(x,prompt,seed, steps, interm_steps, guidance_scale,
|
|
@@ -157,10 +155,7 @@ intro = """
|
|
| 157 |
</p>
|
| 158 |
"""
|
| 159 |
with gr.Blocks(css=css) as demo:
|
| 160 |
-
|
| 161 |
-
# ## Exploring CLIP text space with FLUX.1 schnell 🪐
|
| 162 |
-
# [[code](https://github.com/linoytsaban/semantic-sliders)]
|
| 163 |
-
# """)
|
| 164 |
gr.HTML(intro)
|
| 165 |
|
| 166 |
x_concept_1 = gr.State("")
|
|
@@ -200,13 +195,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 200 |
step=0.1,
|
| 201 |
value=5,
|
| 202 |
)
|
| 203 |
-
|
| 204 |
-
# label="correlation",
|
| 205 |
-
# minimum=0.1,
|
| 206 |
-
# maximum=1.0,
|
| 207 |
-
# step=0.05,
|
| 208 |
-
# value=0.6,
|
| 209 |
-
# )
|
| 210 |
seed = gr.Slider(minimum=0, maximum=np.iinfo(np.int32).max, label="Seed", interactive=True, randomize=True)
|
| 211 |
|
| 212 |
|
|
@@ -258,8 +247,8 @@ with gr.Blocks(css=css) as demo:
|
|
| 258 |
# inputs=[slider_x, slider_y, prompt, seed, iterations, steps, guidance_scale, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y],
|
| 259 |
# outputs=[x, y, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, output_image])
|
| 260 |
submit.click(fn=generate,
|
| 261 |
-
inputs=[slider_x, prompt, seed, recalc_directions, iterations, steps, guidance_scale, x_concept_1, x_concept_2, avg_diff_x],
|
| 262 |
-
outputs=[x, x_concept_1, x_concept_2, avg_diff_x, output_image
|
| 263 |
|
| 264 |
iterations.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
| 265 |
seed.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
|
|
|
| 36 |
# t5_slider_controlnet = T5SliderFlux(sd_pipe=pipe_controlnet,device=torch.device("cuda"))
|
| 37 |
|
| 38 |
@spaces.GPU(duration=200)
|
| 39 |
+
def generate(slider_x, prompt, seed, recalc_directions, iterations, steps, interm_steps, guidance_scale,
|
| 40 |
x_concept_1, x_concept_2,
|
| 41 |
avg_diff_x,
|
| 42 |
img2img_type = None, img = None,
|
|
|
|
| 54 |
avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations)
|
| 55 |
x_concept_1, x_concept_2 = slider_x[0], slider_x[1]
|
| 56 |
|
| 57 |
+
images = []
|
| 58 |
+
high_scale = x
|
| 59 |
+
low_scale = -1 * x
|
| 60 |
+
for i in range(interm_steps):
|
| 61 |
+
cur_scale = low_scale + (high_scale - low_scale) * i / (steps - 1)
|
|
|
|
|
|
|
| 62 |
image = clip_slider.generate(prompt,
|
| 63 |
#guidance_scale=guidance_scale,
|
| 64 |
+
scale=cur_scale, seed=seed, num_inference_steps=steps, avg_diff=avg_diff)
|
| 65 |
+
images.append(image)
|
| 66 |
+
canvas = Image.new('RGB', (256*interm_steps, 256))
|
| 67 |
+
for i, im in enumerate(images):
|
| 68 |
+
canvas.paste(im.resize((256,256)), (256 * i, 0))
|
| 69 |
+
|
| 70 |
comma_concepts_x = f"{slider_x[1]}, {slider_x[0]}"
|
| 71 |
|
| 72 |
avg_diff_x = avg_diff.cpu()
|
| 73 |
|
| 74 |
+
return gr.update(label=comma_concepts_x, interactive=True, value=0), x_concept_1, x_concept_2, avg_diff_x, export_to_gif(images, "clip.gif", fps=5), canvas
|
| 75 |
|
| 76 |
@spaces.GPU
|
| 77 |
def update_scales(x,prompt,seed, steps, interm_steps, guidance_scale,
|
|
|
|
| 155 |
</p>
|
| 156 |
"""
|
| 157 |
with gr.Blocks(css=css) as demo:
|
| 158 |
+
|
|
|
|
|
|
|
|
|
|
| 159 |
gr.HTML(intro)
|
| 160 |
|
| 161 |
x_concept_1 = gr.State("")
|
|
|
|
| 195 |
step=0.1,
|
| 196 |
value=5,
|
| 197 |
)
|
| 198 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
seed = gr.Slider(minimum=0, maximum=np.iinfo(np.int32).max, label="Seed", interactive=True, randomize=True)
|
| 200 |
|
| 201 |
|
|
|
|
| 247 |
# inputs=[slider_x, slider_y, prompt, seed, iterations, steps, guidance_scale, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y],
|
| 248 |
# outputs=[x, y, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, output_image])
|
| 249 |
submit.click(fn=generate,
|
| 250 |
+
inputs=[slider_x, prompt, seed, recalc_directions, iterations, steps, interm_steps, guidance_scale, x_concept_1, x_concept_2, avg_diff_x],
|
| 251 |
+
outputs=[x, x_concept_1, x_concept_2, avg_diff_x, output_image, image_seq])
|
| 252 |
|
| 253 |
iterations.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
| 254 |
seed.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|