ui_postprocessing.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import gradio as gr
  2. from modules import scripts, shared, ui_common, postprocessing, call_queue
  3. import modules.generation_parameters_copypaste as parameters_copypaste
  4. def create_ui():
  5. tab_index = gr.State(value=0)
  6. with gr.Row().style(equal_height=False, variant='compact'):
  7. with gr.Column(variant='compact'):
  8. with gr.Tabs(elem_id="mode_extras"):
  9. with gr.TabItem('Single Image', id="single_image", elem_id="extras_single_tab") as tab_single:
  10. extras_image = gr.Image(label="Source", source="upload", interactive=True, type="pil", elem_id="extras_image")
  11. with gr.TabItem('Batch Process', id="batch_process", elem_id="extras_batch_process_tab") as tab_batch:
  12. image_batch = gr.Files(label="Batch Process", interactive=True, elem_id="extras_image_batch")
  13. with gr.TabItem('Batch from Directory', id="batch_from_directory", elem_id="extras_batch_directory_tab") as tab_batch_dir:
  14. 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")
  15. 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")
  16. show_extras_results = gr.Checkbox(label='Show result images', value=True, elem_id="extras_show_extras_results")
  17. submit = gr.Button('Generate', elem_id="extras_generate", variant='primary')
  18. script_inputs = scripts.scripts_postproc.setup_ui()
  19. with gr.Column():
  20. result_images, html_info_x, html_info, html_log = ui_common.create_output_panel("extras", shared.opts.outdir_extras_samples)
  21. tab_single.select(fn=lambda: 0, inputs=[], outputs=[tab_index])
  22. tab_batch.select(fn=lambda: 1, inputs=[], outputs=[tab_index])
  23. tab_batch_dir.select(fn=lambda: 2, inputs=[], outputs=[tab_index])
  24. submit.click(
  25. fn=call_queue.wrap_gradio_gpu_call(postprocessing.run_postprocessing, extra_outputs=[None, '']),
  26. inputs=[
  27. tab_index,
  28. extras_image,
  29. image_batch,
  30. extras_batch_input_dir,
  31. extras_batch_output_dir,
  32. show_extras_results,
  33. *script_inputs
  34. ],
  35. outputs=[
  36. result_images,
  37. html_info_x,
  38. html_info,
  39. ]
  40. )
  41. parameters_copypaste.add_paste_fields("extras", extras_image, None)
  42. extras_image.change(
  43. fn=scripts.scripts_postproc.image_changed,
  44. inputs=[], outputs=[]
  45. )