Files changed (1) hide show
  1. app.py +23 -8
app.py CHANGED
@@ -201,13 +201,19 @@ def select_the_right_preset(user_width, user_height):
201
  def toggle_custom_resize_slider(resize_option):
202
  return gr.update(visible=(resize_option == "Custom"))
203
 
 
 
 
 
 
 
 
204
  css = """
205
  .gradio-container {
206
  width: 1200px !important;
207
  }
208
  """
209
 
210
-
211
  title = """<h1 align="center">Diffusers Image Outpaint</h1>
212
  <div align="center">Drop an image you would like to extend, pick your expected ratio and hit Generate.</div>
213
  <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
@@ -308,6 +314,8 @@ with gr.Blocks(css=css) as demo:
308
  )
309
  use_as_input_button = gr.Button("Use as Input Image", visible=False)
310
 
 
 
311
  def use_output_as_input(output_image):
312
  """Sets the generated output as the new input image."""
313
  return gr.update(value=output_image[1])
@@ -346,35 +354,42 @@ with gr.Blocks(css=css) as demo:
346
  queue=False
347
  )
348
 
349
- run_button.click(
350
  fn=clear_result,
351
  inputs=None,
352
  outputs=result,
353
- ).then(
354
  fn=infer,
355
  inputs=[input_image, width_slider, height_slider, overlap_width, num_inference_steps,
356
  resize_option, custom_resize_size, prompt_input, alignment_dropdown],
357
  outputs=result,
358
- ).then(
 
 
 
 
359
  fn=lambda: gr.update(visible=True),
360
  inputs=None,
361
  outputs=use_as_input_button,
362
  )
363
 
364
- prompt_input.submit(
365
  fn=clear_result,
366
  inputs=None,
367
  outputs=result,
368
- ).then(
369
  fn=infer,
370
  inputs=[input_image, width_slider, height_slider, overlap_width, num_inference_steps,
371
  resize_option, custom_resize_size, prompt_input, alignment_dropdown],
372
  outputs=result,
373
- ).then(
 
 
 
 
374
  fn=lambda: gr.update(visible=True),
375
  inputs=None,
376
  outputs=use_as_input_button,
377
  )
378
 
379
-
380
  demo.queue(max_size=12).launch(share=False)
 
201
  def toggle_custom_resize_slider(resize_option):
202
  return gr.update(visible=(resize_option == "Custom"))
203
 
204
+ def update_history(new_image, history):
205
+ """Updates the history gallery with the new image."""
206
+ if history is None:
207
+ history = []
208
+ history.insert(0, new_image)
209
+ return history
210
+
211
  css = """
212
  .gradio-container {
213
  width: 1200px !important;
214
  }
215
  """
216
 
 
217
  title = """<h1 align="center">Diffusers Image Outpaint</h1>
218
  <div align="center">Drop an image you would like to extend, pick your expected ratio and hit Generate.</div>
219
  <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
 
314
  )
315
  use_as_input_button = gr.Button("Use as Input Image", visible=False)
316
 
317
+ history_gallery = gr.Gallery(label="History", columns=6, object_fit="contain")
318
+
319
  def use_output_as_input(output_image):
320
  """Sets the generated output as the new input image."""
321
  return gr.update(value=output_image[1])
 
354
  queue=False
355
  )
356
 
357
+ run_button.click( # Clear the result
358
  fn=clear_result,
359
  inputs=None,
360
  outputs=result,
361
+ ).then( # Generate the new image
362
  fn=infer,
363
  inputs=[input_image, width_slider, height_slider, overlap_width, num_inference_steps,
364
  resize_option, custom_resize_size, prompt_input, alignment_dropdown],
365
  outputs=result,
366
+ ).then( # Update the history gallery
367
+ fn=lambda x, history: update_history(x[1], history),
368
+ inputs=[result, history_gallery],
369
+ outputs=history_gallery,
370
+ ).then( # Show the "Use as Input Image" button
371
  fn=lambda: gr.update(visible=True),
372
  inputs=None,
373
  outputs=use_as_input_button,
374
  )
375
 
376
+ prompt_input.submit( # Clear the result
377
  fn=clear_result,
378
  inputs=None,
379
  outputs=result,
380
+ ).then( # Generate the new image
381
  fn=infer,
382
  inputs=[input_image, width_slider, height_slider, overlap_width, num_inference_steps,
383
  resize_option, custom_resize_size, prompt_input, alignment_dropdown],
384
  outputs=result,
385
+ ).then( # Update the history gallery
386
+ fn=lambda x, history: update_history(x[1], history),
387
+ inputs=[result, history_gallery],
388
+ outputs=history_gallery,
389
+ ).then( # Show the "Use as Input Image" button
390
  fn=lambda: gr.update(visible=True),
391
  inputs=None,
392
  outputs=use_as_input_button,
393
  )
394
 
 
395
  demo.queue(max_size=12).launch(share=False)