linoyts HF staff commited on
Commit
b486cec
1 Parent(s): 80d35a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -11,7 +11,7 @@ flash_pipe.scheduler = EulerDiscreteScheduler.from_config(flash_pipe.scheduler.c
11
  clip_slider = CLIPSliderXL(flash_pipe, device=torch.device("cuda"))
12
 
13
  @spaces.GPU
14
- def generate(slider_x, slider_y, prompt, iterations, steps,
15
  x_concept_1, x_concept_2, y_concept_1, y_concept_2,
16
  avg_diff_x_1, avg_diff_x_2,
17
  avg_diff_y_1, avg_diff_y_2):
@@ -27,7 +27,7 @@ def generate(slider_x, slider_y, prompt, iterations, steps,
27
  end_time = time.time()
28
  print(f"direction time: {end_time - start_time:.2f} ms")
29
  start_time = time.time()
30
- image = clip_slider.generate(prompt, scale=0, scale_2nd=0, num_inference_steps=steps, avg_diff=avg_diff, avg_diff_2nd=avg_diff_2nd)
31
  end_time = time.time()
32
  print(f"generation time: {end_time - start_time:.2f} ms")
33
  comma_concepts_x = ', '.join(slider_x)
@@ -41,19 +41,19 @@ def generate(slider_x, slider_y, prompt, iterations, steps,
41
  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
42
 
43
  @spaces.GPU
44
- def update_x(x,y,prompt, steps, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2):
45
  avg_diff = (avg_diff_x_1.cuda(), avg_diff_x_2.cuda())
46
  avg_diff_2nd = (avg_diff_y_1.cuda(), avg_diff_y_2.cuda())
47
- image = clip_slider.generate(prompt, scale=x, scale_2nd=y, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
48
  return image
49
 
50
  @spaces.GPU
51
- def update_y(x,y,prompt, steps, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2):
52
  avg_diff = (avg_diff_x_1.cuda(), avg_diff_x_2.cuda())
53
  avg_diff_2nd = (avg_diff_y_1.cuda(), avg_diff_y_2.cuda())
54
- image = clip_slider.generate(prompt, scale=x, scale_2nd=y, num_inference_steps=steps, avg_diff=avg_diff,avg_diff_2nd=avg_diff_2nd)
55
  return image
56
-
57
  css = '''
58
  #group {
59
  position: relative;
@@ -104,13 +104,13 @@ with gr.Blocks(css=css) as demo:
104
  with gr.Accordion(label="advanced options", open=False):
105
  iterations = gr.Slider(label = "num iterations", minimum=0, value=100, maximum=300)
106
  steps = gr.Slider(label = "num inference steps", minimum=1, value=8, maximum=30)
107
-
108
 
109
  submit.click(fn=generate,
110
- inputs=[slider_x, slider_y, prompt, 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],
111
  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])
112
- x.change(fn=update_x, inputs=[x,y, prompt, steps, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2], outputs=[output_image])
113
- y.change(fn=update_y, inputs=[x,y, prompt, steps, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2], outputs=[output_image])
114
 
115
  if __name__ == "__main__":
116
  demo.launch()
 
11
  clip_slider = CLIPSliderXL(flash_pipe, device=torch.device("cuda"))
12
 
13
  @spaces.GPU
14
+ def generate(slider_x, slider_y, prompt, seed, iterations, steps,
15
  x_concept_1, x_concept_2, y_concept_1, y_concept_2,
16
  avg_diff_x_1, avg_diff_x_2,
17
  avg_diff_y_1, avg_diff_y_2):
 
27
  end_time = time.time()
28
  print(f"direction time: {end_time - start_time:.2f} ms")
29
  start_time = time.time()
30
+ 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)
31
  end_time = time.time()
32
  print(f"generation time: {end_time - start_time:.2f} ms")
33
  comma_concepts_x = ', '.join(slider_x)
 
41
  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
42
 
43
  @spaces.GPU
44
+ def update_x(x,y,prompt, seed, steps, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2):
45
  avg_diff = (avg_diff_x_1.cuda(), avg_diff_x_2.cuda())
46
  avg_diff_2nd = (avg_diff_y_1.cuda(), avg_diff_y_2.cuda())
47
+ 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)
48
  return image
49
 
50
  @spaces.GPU
51
+ def update_y(x,y,prompt, seed, steps, avg_diff_x_1, avg_diff_x_2, avg_diff_y_1, avg_diff_y_2):
52
  avg_diff = (avg_diff_x_1.cuda(), avg_diff_x_2.cuda())
53
  avg_diff_2nd = (avg_diff_y_1.cuda(), avg_diff_y_2.cuda())
54
+ 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)
55
  return image
56
+
57
  css = '''
58
  #group {
59
  position: relative;
 
104
  with gr.Accordion(label="advanced options", open=False):
105
  iterations = gr.Slider(label = "num iterations", minimum=0, value=100, maximum=300)
106
  steps = gr.Slider(label = "num inference steps", minimum=1, value=8, maximum=30)
107
+ seed = gr.Slider(minimum=0, maximum=np.iinfo(np.int32).max, label="Seed", interactive=True, randomize=True)
108
 
109
  submit.click(fn=generate,
110
+ 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],
111
  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])
112
+ 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])
113
+ 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])
114
 
115
  if __name__ == "__main__":
116
  demo.launch()