ui_postprocessing.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import gradio as gr
  2. from modules import scripts, shared, ui_common, postprocessing, call_queue, ui_toprow
  3. import modules.generation_parameters_copypaste as parameters_copypaste
  4. def create_ui():
  5. dummy_component = gr.Label(visible=False)
  6. tab_index = gr.State(value=0)
  7. with gr.Row(equal_height=False, variant='compact'):
  8. with gr.Column(variant='compact'):
  9. with gr.Tabs(elem_id="mode_extras"):
  10. with gr.TabItem('Single Image', id="single_image", elem_id="extras_single_tab") as tab_single:
  11. extras_image = gr.Image(label="Source", source="upload", interactive=True, type="pil", elem_id="extras_image")
  12. with gr.TabItem('Batch Process', id="batch_process", elem_id="extras_batch_process_tab") as tab_batch:
  13. image_batch = gr.Files(label="Batch Process", interactive=True, elem_id="extras_image_batch")
  14. with gr.TabItem('Batch from Directory', id="batch_from_directory", elem_id="extras_batch_directory_tab") as tab_batch_dir:
  15. extras_batch_input_dir = gr.Textbox(label="Input directory", **shared.hide_dirs, placeholder="A directory on the same machine where the server is running.", elem_id="extras_batch_input_dir")
  16. extras_batch_output_dir = gr.Textbox(label="Output directory", **shared.hide_dirs, placeholder="Leave blank to save images to the default path.", elem_id="extras_batch_output_dir")
  17. show_extras_results = gr.Checkbox(label='Show result images', value=True, elem_id="extras_show_extras_results")
  18. script_inputs = scripts.scripts_postproc.setup_ui()
  19. with gr.Column():
  20. toprow = ui_toprow.Toprow(is_compact=True, is_img2img=False, id_part="extras")
  21. toprow.create_inline_toprow_image()
  22. submit = toprow.submit
  23. result_images, html_info_x, html_info, html_log = ui_common.create_output_panel("extras", shared.opts.outdir_extras_samples)
  24. tab_single.select(fn=lambda: 0, inputs=[], outputs=[tab_index])
  25. tab_batch.select(fn=lambda: 1, inputs=[], outputs=[tab_index])
  26. tab_batch_dir.select(fn=lambda: 2, inputs=[], outputs=[tab_index])
  27. submit.click(
  28. fn=call_queue.wrap_gradio_gpu_call(postprocessing.run_postprocessing, extra_outputs=[None, '']),
  29. _js="submit_extras",
  30. inputs=[
  31. dummy_component,
  32. tab_index,
  33. extras_image,
  34. image_batch,
  35. extras_batch_input_dir,
  36. extras_batch_output_dir,
  37. show_extras_results,
  38. *script_inputs
  39. ],
  40. outputs=[
  41. result_images,
  42. html_info_x,
  43. html_log,
  44. ],
  45. show_progress=False,
  46. )
  47. parameters_copypaste.add_paste_fields("extras", extras_image, None)
  48. extras_image.change(
  49. fn=scripts.scripts_postproc.image_changed,
  50. inputs=[], outputs=[]
  51. )