linoyts HF staff commited on
Commit
47fa492
1 Parent(s): 74526f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -31,29 +31,29 @@ 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
- avg_diff[0] = avg_diff[0].to(torch.float16)
35
- avg_diff[1] = 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] = avg_diff_2nd[0].to(torch.float16)
42
- avg_diff_2nd[1] = 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")
46
  start_time = time.time()
47
- image = clip_slider.generate(prompt, scale=0, scale_2nd=0, seed=seed, num_inference_steps=steps, avg_diff=avg_diff, avg_diff_2nd=avg_diff_2nd)
48
  end_time = time.time()
49
  print(f"generation time: {end_time - start_time:.2f} ms")
50
  comma_concepts_x = ', '.join(slider_x)
51
  comma_concepts_y = ', '.join(slider_y)
52
 
53
- avg_diff_x_1 = avg_diff[0].cpu()
54
- avg_diff_x_2 = avg_diff[1].cpu()
55
- avg_diff_y_1 = avg_diff_2nd[0].cpu()
56
- avg_diff_y_2 = avg_diff_2nd[1].cpu()
57
 
58
  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_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2, image
59
 
 
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 = avg_diff[0].to(torch.float16)
35
+ avg_diff_1 = 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 = avg_diff_2nd[0].to(torch.float16)
42
+ avg_diff_2nd_1 = 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")
46
  start_time = time.time()
47
+ image = clip_slider.generate(prompt, scale=0, scale_2nd=0, seed=seed, num_inference_steps=steps, avg_diff=(avg_diff_0,avg_diff_1), avg_diff_2nd=(avg_diff_2nd_0,avg_diff_2nd_1))
48
  end_time = time.time()
49
  print(f"generation time: {end_time - start_time:.2f} ms")
50
  comma_concepts_x = ', '.join(slider_x)
51
  comma_concepts_y = ', '.join(slider_y)
52
 
53
+ avg_diff_x_1 = avg_diff_0.cpu()
54
+ avg_diff_x_2 = avg_diff_1.cpu()
55
+ avg_diff_y_1 = avg_diff_2nd_0.cpu()
56
+ avg_diff_y_2 = avg_diff_2nd_1.cpu()
57
 
58
  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_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2, image
59