ui_postprocessing.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import gradio as gr
  2. from modules import scripts, shared, ui_common, postprocessing, call_queue, ui_toprow
  3. import modules.infotext_utils as parameters_copypaste
  4. from modules.ui_components import ResizeHandleRow
  5. def create_ui():
  6. dummy_component = gr.Label(visible=False)
  7. tab_index = gr.Number(value=0, visible=False)
  8. with ResizeHandleRow(equal_height=False, variant='compact'):
  9. with gr.Column(variant='compact'):
  10. with gr.Tabs(elem_id="mode_extras"):
  11. with gr.TabItem('Single Image', id="single_image", elem_id="extras_single_tab") as tab_single:
  12. extras_image = gr.Image(label="Source", source="upload", interactive=True, type="pil", elem_id="extras_image", image_mode="RGBA")
  13. with gr.TabItem('Batch Process', id="batch_process", elem_id="extras_batch_process_tab") as tab_batch:
  14. image_batch = gr.Files(label="Batch Process", interactive=True, elem_id="extras_image_batch")
  15. with gr.TabItem('Batch from Directory', id="batch_from_directory", elem_id="extras_batch_directory_tab") as tab_batch_dir:
  16. 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")
  17. 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")
  18. show_extras_results = gr.Checkbox(label='Show result images', value=True, elem_id="extras_show_extras_results")
  19. script_inputs = scripts.scripts_postproc.setup_ui()
  20. with gr.Column():
  21. toprow = ui_toprow.Toprow(is_compact=True, is_img2img=False, id_part="extras")
  22. toprow.create_inline_toprow_image()
  23. submit = toprow.submit
  24. output_panel = ui_common.create_output_panel("extras", shared.opts.outdir_extras_samples)
  25. tab_single.select(fn=lambda: 0, inputs=[], outputs=[tab_index])
  26. tab_batch.select(fn=lambda: 1, inputs=[], outputs=[tab_index])
  27. tab_batch_dir.select(fn=lambda: 2, inputs=[], outputs=[tab_index])
  28. submit.click(
  29. fn=call_queue.wrap_gradio_gpu_call(postprocessing.run_postprocessing_webui, extra_outputs=[None, '']),
  30. _js="submit_extras",
  31. inputs=[
  32. dummy_component,
  33. tab_index,
  34. extras_image,
  35. image_batch,
  36. extras_batch_input_dir,
  37. extras_batch_output_dir,
  38. show_extras_results,
  39. *script_inputs
  40. ],
  41. outputs=[
  42. output_panel.gallery,
  43. output_panel.generation_info,
  44. output_panel.html_log,
  45. ],
  46. show_progress=False,
  47. preprocess=False,
  48. )
  49. parameters_copypaste.add_paste_fields("extras", extras_image, None)
  50. extras_image.change(
  51. fn=scripts.scripts_postproc.image_changed,
  52. inputs=[], outputs=[]
  53. )