multimodalart HF staff commited on
Commit
5e49d53
β€’
1 Parent(s): 5451ab9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -82,13 +82,14 @@ def generate(concept_1, concept_2, scale, prompt, seed, recalc_directions, itera
82
 
83
  comma_concepts_x = f"{slider_x[1]}, {slider_x[0]}"
84
 
85
- scale_min = convert_to_centered_scale(interm_steps)[0]
86
- scale_max = convert_to_centered_scale(interm_steps)[-1]
87
-
88
- post_generation_slider_update = gr.update(minimum=scale_min, maximum=scale_max, visible=True)
 
89
  avg_diff_x = avg_diff.cpu()
90
 
91
- return gr.update(label=comma_concepts_x, interactive=True, value=scale), x_concept_1, x_concept_2, avg_diff_x, export_to_gif(images, "clip.gif", fps=5), canvas, images, post_generation_slider_update
92
 
93
  @spaces.GPU
94
  def update_scales(x,prompt,seed, steps, interm_steps, guidance_scale,
@@ -120,12 +121,13 @@ def update_scales(x,prompt,seed, steps, interm_steps, guidance_scale,
120
  for i, im in enumerate(images):
121
  canvas.paste(im.resize((256,256)), (256 * i, 0))
122
 
123
- scale_min = convert_to_centered_scale(interm_steps)[0]
124
- scale_max = convert_to_centered_scale(interm_steps)[-1]
125
-
 
126
  post_generation_slider_update = gr.update(minimum=scale_min, maximum=scale_max, visible=True)
127
 
128
- return export_to_gif(images, "clip.gif", fps=5), canvas, images, post_generation_slider_update
129
 
130
  def update_pre_generated_images(slider_value, total_images):
131
  number_images = len(total_images)
@@ -216,9 +218,9 @@ with gr.Blocks() as demo:
216
  post_generation_slider = gr.Slider(minimum=-2, maximum=2, value=0, step=1, interactive=False)
217
  #y = gr.Slider(minimum=-10, value=0, maximum=10, elem_id="y", interactive=False)
218
  with gr.Row():
219
- with gr.Column(scale=4):
220
  output_image = gr.Image(elem_id="image_out", label="Gif")
221
- with gr.Column(scale=1):
222
  image_seq = gr.Image(label="Strip")
223
  # with gr.Row():
224
  # generate_butt = gr.Button("generate")
@@ -287,16 +289,16 @@ with gr.Blocks() as demo:
287
  # outputs=[x, y, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, output_image])
288
  submit.click(fn=generate,
289
  inputs=[concept_1, concept_2, x, prompt, seed, recalc_directions, iterations, steps, interm_steps, guidance_scale, x_concept_1, x_concept_2, avg_diff_x, total_images],
290
- outputs=[x, x_concept_1, x_concept_2, avg_diff_x, output_image, image_seq, total_images, post_generation_slider])
291
 
292
  iterations.change(fn=reset_recalc_directions, outputs=[recalc_directions])
293
  seed.change(fn=reset_recalc_directions, outputs=[recalc_directions])
294
- x.release(fn=update_scales, inputs=[x, prompt, seed, steps, interm_steps, guidance_scale, avg_diff_x, total_images], outputs=[output_image, image_seq, total_images, post_generation_slider], trigger_mode='always_last')
295
  # 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])
296
  # submit_a.click(fn=generate,
297
  # inputs=[slider_x_a, slider_y_a, prompt_a, seed_a, iterations_a, steps_a, guidance_scale_a, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, img2img_type, image, controlnet_conditioning_scale, ip_adapter_scale],
298
  # outputs=[x_a, y_a, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, output_image_a])
299
- post_generation_slider.release(fn=update_pre_generated_images, inputs=[post_generation_slider, total_images], outputs=[post_generation_image], trigger_mode='always_last')
300
 
301
  if __name__ == "__main__":
302
  demo.launch()
 
82
 
83
  comma_concepts_x = f"{slider_x[1]}, {slider_x[0]}"
84
 
85
+ scale_total = convert_to_centered_scale(interm_steps)
86
+ scale_min = scale_total[0]
87
+ scale_max = scale_total[-1]
88
+ scale_middle = scale_total.index(0)
89
+ post_generation_slider_update = gr.update(label=comma_concepts_x, minimum=scale_min, maximum=scale_max, interactive=True)
90
  avg_diff_x = avg_diff.cpu()
91
 
92
+ return gr.update(label=comma_concepts_x, interactive=True, value=scale), x_concept_1, x_concept_2, avg_diff_x, export_to_gif(images, "clip.gif", fps=5), canvas, images, images[scale_middle], post_generation_slider_update
93
 
94
  @spaces.GPU
95
  def update_scales(x,prompt,seed, steps, interm_steps, guidance_scale,
 
121
  for i, im in enumerate(images):
122
  canvas.paste(im.resize((256,256)), (256 * i, 0))
123
 
124
+ scale_total = convert_to_centered_scale(interm_steps)
125
+ scale_min = scale_total[0]
126
+ scale_max = scale_total[-1]
127
+ scale_middle = scale_total.index(0)
128
  post_generation_slider_update = gr.update(minimum=scale_min, maximum=scale_max, visible=True)
129
 
130
+ return export_to_gif(images, "clip.gif", fps=5), canvas, images, images[scale_middle], post_generation_slider_update
131
 
132
  def update_pre_generated_images(slider_value, total_images):
133
  number_images = len(total_images)
 
218
  post_generation_slider = gr.Slider(minimum=-2, maximum=2, value=0, step=1, interactive=False)
219
  #y = gr.Slider(minimum=-10, value=0, maximum=10, elem_id="y", interactive=False)
220
  with gr.Row():
221
+ with gr.Column(scale=4, min_width=50):
222
  output_image = gr.Image(elem_id="image_out", label="Gif")
223
+ with gr.Column(scale=1, min_width=50):
224
  image_seq = gr.Image(label="Strip")
225
  # with gr.Row():
226
  # generate_butt = gr.Button("generate")
 
289
  # outputs=[x, y, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, output_image])
290
  submit.click(fn=generate,
291
  inputs=[concept_1, concept_2, x, prompt, seed, recalc_directions, iterations, steps, interm_steps, guidance_scale, x_concept_1, x_concept_2, avg_diff_x, total_images],
292
+ outputs=[x, x_concept_1, x_concept_2, avg_diff_x, output_image, image_seq, total_images, post_generation_image, post_generation_slider])
293
 
294
  iterations.change(fn=reset_recalc_directions, outputs=[recalc_directions])
295
  seed.change(fn=reset_recalc_directions, outputs=[recalc_directions])
296
+ x.release(fn=update_scales, inputs=[x, prompt, seed, steps, interm_steps, guidance_scale, avg_diff_x, total_images], outputs=[output_image, image_seq, total_images, post_generation_image, post_generation_slider], trigger_mode='always_last')
297
  # 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])
298
  # submit_a.click(fn=generate,
299
  # inputs=[slider_x_a, slider_y_a, prompt_a, seed_a, iterations_a, steps_a, guidance_scale_a, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, img2img_type, image, controlnet_conditioning_scale, ip_adapter_scale],
300
  # outputs=[x_a, y_a, x_concept_1, x_concept_2, y_concept_1, y_concept_2, avg_diff_x, avg_diff_y, output_image_a])
301
+ post_generation_slider.change(fn=update_pre_generated_images, inputs=[post_generation_slider, total_images], outputs=[post_generation_image], queue=False)
302
 
303
  if __name__ == "__main__":
304
  demo.launch()