Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -58,17 +58,13 @@ def generate(slider_x, slider_y, prompt, seed, iterations, steps, guidance_scale
|
|
58 |
print("x_concept_1", x_concept_1, "x_concept_2", x_concept_2)
|
59 |
|
60 |
if not sorted(slider_x) == sorted([x_concept_1, x_concept_2]):
|
61 |
-
avg_diff = t5_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations)
|
62 |
-
avg_diff_0 = avg_diff[0].to(torch.float16)
|
63 |
-
avg_diff_1 = avg_diff[1].to(torch.float16)
|
64 |
x_concept_1, x_concept_2 = slider_x[0], slider_x[1]
|
65 |
|
66 |
print("avg_diff_0", avg_diff_0.dtype)
|
67 |
|
68 |
if not sorted(slider_y) == sorted([y_concept_1, y_concept_2]):
|
69 |
-
avg_diff_2nd = t5_slider.find_latent_direction(slider_y[0], slider_y[1], num_iterations=iterations)
|
70 |
-
avg_diff_2nd_0 = avg_diff_2nd[0].to(torch.float16)
|
71 |
-
avg_diff_2nd_1 = avg_diff_2nd[1].to(torch.float16)
|
72 |
y_concept_1, y_concept_2 = slider_y[0], slider_y[1]
|
73 |
end_time = time.time()
|
74 |
print(f"direction time: {end_time - start_time:.2f} ms")
|
@@ -77,11 +73,11 @@ def generate(slider_x, slider_y, prompt, seed, iterations, steps, guidance_scale
|
|
77 |
|
78 |
if img2img_type=="controlnet canny" and img is not None:
|
79 |
control_img = process_controlnet_img(img)
|
80 |
-
image = t5_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=
|
81 |
elif img2img_type=="ip adapter" and img is not None:
|
82 |
-
image = t5_slider.generate(prompt, guidance_scale=guidance_scale, ip_adapter_image=img, scale=0, scale_2nd=0, seed=seed, num_inference_steps=steps, avg_diff=
|
83 |
else: # text to image
|
84 |
-
image = t5_slider.generate(prompt, guidance_scale=guidance_scale, scale=0, scale_2nd=0, seed=seed, num_inference_steps=steps, avg_diff=
|
85 |
|
86 |
end_time = time.time()
|
87 |
print(f"generation time: {end_time - start_time:.2f} ms")
|
@@ -89,20 +85,18 @@ def generate(slider_x, slider_y, prompt, seed, iterations, steps, guidance_scale
|
|
89 |
comma_concepts_x = ', '.join(slider_x)
|
90 |
comma_concepts_y = ', '.join(slider_y)
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
avg_diff_y_1 = avg_diff_2nd_0.cpu()
|
95 |
-
avg_diff_y_2 = avg_diff_2nd_1.cpu()
|
96 |
|
97 |
-
return gr.update(label=comma_concepts_x, interactive=True),gr.update(label=comma_concepts_y, interactive=True), x_concept_1, x_concept_2, y_concept_1, y_concept_2,
|
98 |
|
99 |
@spaces.GPU
|
100 |
def update_scales(x,y,prompt,seed, steps, guidance_scale,
|
101 |
-
|
102 |
img2img_type = None, img = None,
|
103 |
controlnet_scale= None, ip_adapter_scale=None,):
|
104 |
-
avg_diff =
|
105 |
-
avg_diff_2nd =
|
106 |
if img2img_type=="controlnet canny" and img is not None:
|
107 |
control_img = process_controlnet_img(img)
|
108 |
image = t5_slider.generate(prompt, guidance_scale=guidance_scale, image=control_img, controlnet_conditioning_scale =controlnet_scale, scale=x, scale_2nd=y, seed=seed, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
|
@@ -112,23 +106,25 @@ def update_scales(x,y,prompt,seed, steps, guidance_scale,
|
|
112 |
image = t5_slider.generate(prompt, guidance_scale=guidance_scale, scale=x, scale_2nd=y, seed=seed, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
|
113 |
return image
|
114 |
|
|
|
|
|
115 |
@spaces.GPU
|
116 |
def update_x(x,y,prompt,seed, steps,
|
117 |
-
|
118 |
img2img_type = None,
|
119 |
img = None):
|
120 |
-
avg_diff =
|
121 |
-
avg_diff_2nd =
|
122 |
-
image =
|
123 |
return image
|
124 |
|
125 |
@spaces.GPU
|
126 |
-
def update_y(x,y,prompt,
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
avg_diff =
|
131 |
-
avg_diff_2nd =
|
132 |
image = t5_slider.generate(prompt, scale=x, scale_2nd=y, seed=seed, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
|
133 |
return image
|
134 |
|
|
|
58 |
print("x_concept_1", x_concept_1, "x_concept_2", x_concept_2)
|
59 |
|
60 |
if not sorted(slider_x) == sorted([x_concept_1, x_concept_2]):
|
61 |
+
avg_diff = t5_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations).to(torch.float16)
|
|
|
|
|
62 |
x_concept_1, x_concept_2 = slider_x[0], slider_x[1]
|
63 |
|
64 |
print("avg_diff_0", avg_diff_0.dtype)
|
65 |
|
66 |
if not sorted(slider_y) == sorted([y_concept_1, y_concept_2]):
|
67 |
+
avg_diff_2nd = t5_slider.find_latent_direction(slider_y[0], slider_y[1], num_iterations=iterations).to(torch.float16)
|
|
|
|
|
68 |
y_concept_1, y_concept_2 = slider_y[0], slider_y[1]
|
69 |
end_time = time.time()
|
70 |
print(f"direction time: {end_time - start_time:.2f} ms")
|
|
|
73 |
|
74 |
if img2img_type=="controlnet canny" and img is not None:
|
75 |
control_img = process_controlnet_img(img)
|
76 |
+
image = t5_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)
|
77 |
elif img2img_type=="ip adapter" and img is not None:
|
78 |
+
image = t5_slider.generate(prompt, guidance_scale=guidance_scale, ip_adapter_image=img, scale=0, scale_2nd=0, seed=seed, num_inference_steps=steps, avg_diff=avg_diff, avg_diff_2nd=avg_diff_2nd)
|
79 |
else: # text to image
|
80 |
+
image = t5_slider.generate(prompt, guidance_scale=guidance_scale, scale=0, scale_2nd=0, seed=seed, num_inference_steps=steps, avg_diff=avg_diff, avg_diff_2nd=avg_diff_2nd)
|
81 |
|
82 |
end_time = time.time()
|
83 |
print(f"generation time: {end_time - start_time:.2f} ms")
|
|
|
85 |
comma_concepts_x = ', '.join(slider_x)
|
86 |
comma_concepts_y = ', '.join(slider_y)
|
87 |
|
88 |
+
avg_diff_x = avg_diff.cpu()
|
89 |
+
avg_diff_y = avg_diff_2nd.cpu()
|
|
|
|
|
90 |
|
91 |
+
return gr.update(label=comma_concepts_x, interactive=True),gr.update(label=comma_concepts_y, interactive=True), x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, image
|
92 |
|
93 |
@spaces.GPU
|
94 |
def update_scales(x,y,prompt,seed, steps, guidance_scale,
|
95 |
+
avg_diff_x, avg_diff_y,
|
96 |
img2img_type = None, img = None,
|
97 |
controlnet_scale= None, ip_adapter_scale=None,):
|
98 |
+
avg_diff = avg_diff_x.cuda()
|
99 |
+
avg_diff_2nd = avg_diff_y.cuda()
|
100 |
if img2img_type=="controlnet canny" and img is not None:
|
101 |
control_img = process_controlnet_img(img)
|
102 |
image = t5_slider.generate(prompt, guidance_scale=guidance_scale, image=control_img, controlnet_conditioning_scale =controlnet_scale, scale=x, scale_2nd=y, seed=seed, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
|
|
|
106 |
image = t5_slider.generate(prompt, guidance_scale=guidance_scale, scale=x, scale_2nd=y, seed=seed, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
|
107 |
return image
|
108 |
|
109 |
+
|
110 |
+
|
111 |
@spaces.GPU
|
112 |
def update_x(x,y,prompt,seed, steps,
|
113 |
+
avg_diff_x, avg_diff_y,
|
114 |
img2img_type = None,
|
115 |
img = None):
|
116 |
+
avg_diff = avg_diff_x.cuda()
|
117 |
+
avg_diff_2nd = avg_diff_y.cuda()
|
118 |
+
image = t5_slider.generate(prompt, scale=x, scale_2nd=y, seed=seed, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
|
119 |
return image
|
120 |
|
121 |
@spaces.GPU
|
122 |
+
def update_y(x,y,prompt,seed, steps,
|
123 |
+
avg_diff_x, avg_diff_y,
|
124 |
+
img2img_type = None,
|
125 |
+
img = None):
|
126 |
+
avg_diff = avg_diff_x.cuda()
|
127 |
+
avg_diff_2nd = avg_diff_y.cuda()
|
128 |
image = t5_slider.generate(prompt, scale=x, scale_2nd=y, seed=seed, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
|
129 |
return image
|
130 |
|