Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -31,8 +31,8 @@ controlnet_model = 'InstantX/FLUX.1-dev-Controlnet-Canny-alpha'
|
|
31 |
|
32 |
|
33 |
@spaces.GPU(duration=200)
|
34 |
-
def generate(slider_x, prompt, seed, iterations, steps, guidance_scale,
|
35 |
-
x_concept_1, x_concept_2,
|
36 |
avg_diff_x,
|
37 |
img2img_type = None, img = None,
|
38 |
controlnet_scale= None, ip_adapter_scale=None,
|
@@ -43,11 +43,10 @@ def generate(slider_x, prompt, seed, iterations, steps, guidance_scale,
|
|
43 |
print("slider_x", slider_x)
|
44 |
print("x_concept_1", x_concept_1, "x_concept_2", x_concept_2)
|
45 |
|
46 |
-
if not sorted(slider_x) == sorted([x_concept_1, x_concept_2]):
|
47 |
avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations).to(torch.float16)
|
48 |
x_concept_1, x_concept_2 = slider_x[0], slider_x[1]
|
49 |
|
50 |
-
|
51 |
if img2img_type=="controlnet canny" and img is not None:
|
52 |
control_img = process_controlnet_img(img)
|
53 |
image = clip_slider.generate(prompt, guidance_scale=guidance_scale, image=control_img, controlnet_conditioning_scale =controlnet_scale, scale=0, scale_2nd=0, seed=seed, num_inference_steps=steps, avg_diff=avg_diff, avg_diff_2nd=avg_diff_2nd)
|
@@ -100,7 +99,8 @@ def update_y(x,y,prompt,seed, steps,
|
|
100 |
image = clip_slider.generate(prompt, scale=x, scale_2nd=y, seed=seed, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
|
101 |
return image
|
102 |
|
103 |
-
|
|
|
104 |
|
105 |
css = '''
|
106 |
#group {
|
@@ -135,6 +135,8 @@ with gr.Blocks(css=css) as demo:
|
|
135 |
|
136 |
avg_diff_x = gr.State()
|
137 |
#avg_diff_y = gr.State()
|
|
|
|
|
138 |
|
139 |
with gr.Tab("text2image"):
|
140 |
with gr.Row():
|
@@ -219,9 +221,11 @@ with gr.Blocks(css=css) as demo:
|
|
219 |
# 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],
|
220 |
# outputs=[x, y, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, output_image])
|
221 |
submit.click(fn=generate,
|
222 |
-
inputs=[slider_x, prompt, seed, iterations, steps, guidance_scale, x_concept_1, x_concept_2, avg_diff_x],
|
223 |
outputs=[x, x_concept_1, x_concept_2, avg_diff_x, output_image])
|
224 |
|
|
|
|
|
225 |
x.change(fn=update_scales, inputs=[x, prompt, seed, steps, guidance_scale, avg_diff_x], outputs=[output_image])
|
226 |
# generate_butt_a.click(fn=update_scales, inputs=[x_a,y_a, prompt_a, seed_a, steps_a, guidance_scale_a, avg_diff_x, avg_diff_y, img2img_type, image, controlnet_conditioning_scale, ip_adapter_scale], outputs=[output_image_a])
|
227 |
# submit_a.click(fn=generate,
|
|
|
31 |
|
32 |
|
33 |
@spaces.GPU(duration=200)
|
34 |
+
def generate(slider_x, prompt, seed, recalc_directions, iterations, steps, guidance_scale,
|
35 |
+
x_concept_1, x_concept_2,
|
36 |
avg_diff_x,
|
37 |
img2img_type = None, img = None,
|
38 |
controlnet_scale= None, ip_adapter_scale=None,
|
|
|
43 |
print("slider_x", slider_x)
|
44 |
print("x_concept_1", x_concept_1, "x_concept_2", x_concept_2)
|
45 |
|
46 |
+
if not sorted(slider_x) == sorted([x_concept_1, x_concept_2]) or recalc_directions:
|
47 |
avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations).to(torch.float16)
|
48 |
x_concept_1, x_concept_2 = slider_x[0], slider_x[1]
|
49 |
|
|
|
50 |
if img2img_type=="controlnet canny" and img is not None:
|
51 |
control_img = process_controlnet_img(img)
|
52 |
image = clip_slider.generate(prompt, guidance_scale=guidance_scale, image=control_img, controlnet_conditioning_scale =controlnet_scale, scale=0, scale_2nd=0, seed=seed, num_inference_steps=steps, avg_diff=avg_diff, avg_diff_2nd=avg_diff_2nd)
|
|
|
99 |
image = clip_slider.generate(prompt, scale=x, scale_2nd=y, seed=seed, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
|
100 |
return image
|
101 |
|
102 |
+
def reset_recalc_directions():
|
103 |
+
return True
|
104 |
|
105 |
css = '''
|
106 |
#group {
|
|
|
135 |
|
136 |
avg_diff_x = gr.State()
|
137 |
#avg_diff_y = gr.State()
|
138 |
+
|
139 |
+
recalc_directions = gr.State(False)
|
140 |
|
141 |
with gr.Tab("text2image"):
|
142 |
with gr.Row():
|
|
|
221 |
# 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],
|
222 |
# outputs=[x, y, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, output_image])
|
223 |
submit.click(fn=generate,
|
224 |
+
inputs=[slider_x, prompt, seed, recalc_directions, iterations, steps, guidance_scale, x_concept_1, x_concept_2, avg_diff_x],
|
225 |
outputs=[x, x_concept_1, x_concept_2, avg_diff_x, output_image])
|
226 |
|
227 |
+
iterations.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
228 |
+
seed.change(fn=reset_recalc_directions, outputs=[recalc_directions])
|
229 |
x.change(fn=update_scales, inputs=[x, prompt, seed, steps, guidance_scale, avg_diff_x], outputs=[output_image])
|
230 |
# generate_butt_a.click(fn=update_scales, inputs=[x_a,y_a, prompt_a, seed_a, steps_a, guidance_scale_a, avg_diff_x, avg_diff_y, img2img_type, image, controlnet_conditioning_scale, ip_adapter_scale], outputs=[output_image_a])
|
231 |
# submit_a.click(fn=generate,
|