linoyts HF staff commited on
Commit
e4f255d
1 Parent(s): a87598e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -31,10 +31,15 @@ def generate(slider_x, slider_y, prompt, seed, iterations, steps,
31
  print("x_concept_1", x_concept_1, "x_concept_2", x_concept_2)
32
  if not sorted(slider_x) == sorted([x_concept_1, x_concept_2]):
33
  avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations)
 
 
34
  x_concept_1, x_concept_2 = slider_x[0], slider_x[1]
 
35
  print("avg_diff[0].dtype", avg_diff[0].dtype)
36
  if not sorted(slider_y) == sorted([y_concept_1, y_concept_2]):
37
  avg_diff_2nd = clip_slider.find_latent_direction(slider_y[0], slider_y[1], num_iterations=iterations)
 
 
38
  y_concept_1, y_concept_2 = slider_y[0], slider_y[1]
39
  end_time = time.time()
40
  print(f"direction time: {end_time - start_time:.2f} ms")
@@ -119,11 +124,7 @@ with gr.Blocks(css=css) as demo:
119
  steps = gr.Slider(label = "num inference steps", minimum=1, value=8, maximum=30)
120
  seed = gr.Slider(minimum=0, maximum=np.iinfo(np.int32).max, label="Seed", interactive=True, randomize=True)
121
 
122
- submit.click(fn=generate,
123
- inputs=[slider_x, slider_y, prompt, seed, iterations, steps, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2],
124
- outputs=[x, y, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2, output_image])
125
- x.change(fn=update_x, inputs=[x,y, prompt, seed, steps, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2], outputs=[output_image])
126
- y.change(fn=update_y, inputs=[x,y, prompt, seed, steps, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2], outputs=[output_image])
127
  with gr.Tab(label="image2image"):
128
  with gr.Row():
129
  with gr.Column():
@@ -142,11 +143,16 @@ with gr.Blocks(css=css) as demo:
142
  steps_a = gr.Slider(label = "num inference steps", minimum=1, value=8, maximum=30)
143
  seed_a = gr.Slider(minimum=0, maximum=np.iinfo(np.int32).max, label="Seed", interactive=True, randomize=True)
144
 
145
- submit.click(fn=generate,
 
 
 
 
 
146
  inputs=[slider_x_a, slider_y_a, prompt_a, seed_a, iterations_a, steps_a, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2],
147
  outputs=[x_a, y_a, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2, output_image_a])
148
- x.change(fn=update_x, inputs=[x_a,y_a, prompt_a, seed_a, steps_a, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2], outputs=[output_image_a])
149
- y.change(fn=update_y, inputs=[x_a,y_a, prompt, seed_a, steps_a, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2], outputs=[output_image_a])
150
 
151
 
152
  if __name__ == "__main__":
 
31
  print("x_concept_1", x_concept_1, "x_concept_2", x_concept_2)
32
  if not sorted(slider_x) == sorted([x_concept_1, x_concept_2]):
33
  avg_diff = clip_slider.find_latent_direction(slider_x[0], slider_x[1], num_iterations=iterations)
34
+ avg_diff[0].to(torch.float16)
35
+ avg_diff[1].to(torch.float16)
36
  x_concept_1, x_concept_2 = slider_x[0], slider_x[1]
37
+
38
  print("avg_diff[0].dtype", avg_diff[0].dtype)
39
  if not sorted(slider_y) == sorted([y_concept_1, y_concept_2]):
40
  avg_diff_2nd = clip_slider.find_latent_direction(slider_y[0], slider_y[1], num_iterations=iterations)
41
+ avg_diff_2nd[0].to(torch.float16)
42
+ avg_diff_2nd[1].to(torch.float16)
43
  y_concept_1, y_concept_2 = slider_y[0], slider_y[1]
44
  end_time = time.time()
45
  print(f"direction time: {end_time - start_time:.2f} ms")
 
124
  steps = gr.Slider(label = "num inference steps", minimum=1, value=8, maximum=30)
125
  seed = gr.Slider(minimum=0, maximum=np.iinfo(np.int32).max, label="Seed", interactive=True, randomize=True)
126
 
127
+
 
 
 
 
128
  with gr.Tab(label="image2image"):
129
  with gr.Row():
130
  with gr.Column():
 
143
  steps_a = gr.Slider(label = "num inference steps", minimum=1, value=8, maximum=30)
144
  seed_a = gr.Slider(minimum=0, maximum=np.iinfo(np.int32).max, label="Seed", interactive=True, randomize=True)
145
 
146
+ submit.click(fn=generate,
147
+ inputs=[slider_x, slider_y, prompt, seed, iterations, steps, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2],
148
+ outputs=[x, y, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2, output_image])
149
+ x.change(fn=update_x, inputs=[x,y, prompt, seed, steps, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2], outputs=[output_image])
150
+ y.change(fn=update_y, inputs=[x,y, prompt, seed, steps, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2], outputs=[output_image])
151
+ submit_a.click(fn=generate,
152
  inputs=[slider_x_a, slider_y_a, prompt_a, seed_a, iterations_a, steps_a, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2],
153
  outputs=[x_a, y_a, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2, output_image_a])
154
+ x_a.change(fn=update_x, inputs=[x_a,y_a, prompt_a, seed_a, steps_a, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2], outputs=[output_image_a])
155
+ y_a.change(fn=update_y, inputs=[x_a,y_a, prompt, seed_a, steps_a, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2], outputs=[output_image_a])
156
 
157
 
158
  if __name__ == "__main__":