Spaces:
Running
on
Zero
Running
on
Zero
File size: 7,208 Bytes
1875ee2 48f68fc 1875ee2 7691c50 3d61150 1875ee2 48f68fc 1875ee2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
import os
import gradio as gr
from core.settings import *
from .shared import txt2img_ui, img2img_ui, inpaint_ui, outpaint_ui, hires_fix_ui
MAX_DYNAMIC_CONTROLS = 10
def get_preprocessor_choices():
from nodes import NODE_DISPLAY_NAME_MAPPINGS
preprocessor_names = [
display_name for class_name, display_name in NODE_DISPLAY_NAME_MAPPINGS.items()
if "Preprocessor" in class_name or "Segmentor" in class_name or
"Estimator" in class_name or "Detector" in class_name
]
return sorted(list(set(preprocessor_names)))
def build_ui(event_handler_function):
ui_components = {}
with gr.Blocks(css="#col-container {margin: 0 auto; max-width: 1024px;}") as demo:
gr.Markdown("# ImageGen - NoobAI")
gr.Markdown(
"This demo is a streamlined version of the [Comfy web UI](https://github.com/RioShiina47/comfy-webui)'s ImgGen functionality. "
"Due to storage limitations on Spaces, this demo features the NoobAI series of models.\n"
"Other versions are also available: "
"[Illstrious](https://huggingface.co/spaces/RioShiina/ImageGen-Illstrious), "
"[Pony](https://huggingface.co/spaces/RioShiina/ImageGen-Pony1), "
"[SDXL](https://huggingface.co/spaces/RioShiina/ImageGen-SDXL), "
"[SD1.5](https://huggingface.co/spaces/RioShiina/ImageGen-SD15)"
)
with gr.Tabs(elem_id="tabs_container") as tabs:
with gr.TabItem("NoobAI", id=0):
with gr.Tabs(elem_id="image_gen_tabs") as image_gen_tabs:
with gr.TabItem("Txt2Img", id=0):
ui_components.update(txt2img_ui.create_ui())
with gr.TabItem("Img2Img", id=1):
ui_components.update(img2img_ui.create_ui())
with gr.TabItem("Inpaint", id=2):
ui_components.update(inpaint_ui.create_ui())
with gr.TabItem("Outpaint", id=3):
ui_components.update(outpaint_ui.create_ui())
with gr.TabItem("Hires. Fix", id=4):
ui_components.update(hires_fix_ui.create_ui())
ui_components['image_gen_tabs'] = image_gen_tabs
with gr.TabItem("Controlnet Preprocessors", id=1):
gr.Markdown("## ControlNet Auxiliary Preprocessors")
gr.Markdown("Powered by [Fannovel16/comfyui_controlnet_aux](https://github.com/Fannovel16/comfyui_controlnet_aux).")
gr.Markdown("Upload an image or video to process it with a ControlNet preprocessor.")
with gr.Row():
with gr.Column(scale=1):
cn_input_type = gr.Radio(["Image", "Video"], label="Input Type", value="Image")
cn_image_input = gr.Image(type="pil", label="Input Image", visible=True, height=384)
cn_video_input = gr.Video(label="Input Video", visible=False)
preprocessor_cn = gr.Dropdown(label="Preprocessor", choices=get_preprocessor_choices(), value="Canny Edge")
preprocessor_model_cn = gr.Dropdown(label="Preprocessor Model", choices=[], value=None, visible=False)
with gr.Column() as preprocessor_settings_ui:
cn_sliders, cn_dropdowns, cn_checkboxes = [], [], []
for i in range(MAX_DYNAMIC_CONTROLS):
cn_sliders.append(gr.Slider(visible=False, label=f"dyn_slider_{i}"))
cn_dropdowns.append(gr.Dropdown(visible=False, label=f"dyn_dropdown_{i}"))
cn_checkboxes.append(gr.Checkbox(visible=False, label=f"dyn_checkbox_{i}"))
run_cn = gr.Button("Run Preprocessor", variant="primary")
with gr.Column(scale=1):
output_gallery_cn = gr.Gallery(label="Output", show_label=False, object_fit="contain", height=512)
zero_gpu_cn = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional")
ui_components.update({
"cn_input_type": cn_input_type, "cn_image_input": cn_image_input, "cn_video_input": cn_video_input,
"preprocessor_cn": preprocessor_cn, "preprocessor_model_cn": preprocessor_model_cn, "run_cn": run_cn,
"zero_gpu_cn": zero_gpu_cn, "output_gallery_cn": output_gallery_cn,
"preprocessor_settings_ui": preprocessor_settings_ui, "cn_sliders": cn_sliders,
"cn_dropdowns": cn_dropdowns, "cn_checkboxes": cn_checkboxes
})
with gr.TabItem("PNG Info", id=2):
with gr.Column():
info_image_input = gr.Image(type="pil", label="Upload Image", height=512)
with gr.Row():
info_get_button = gr.Button("Get Info")
send_to_txt2img_button = gr.Button("Send to Txt2Img", variant="primary")
with gr.Row():
send_to_img2img_button = gr.Button("Send to Img2Img")
send_to_inpaint_button = gr.Button("Send to Inpaint")
send_to_outpaint_button = gr.Button("Send to Outpaint")
send_to_hires_fix_button = gr.Button("Send to Hires. Fix")
gr.Markdown("### Positive Prompt"); info_prompt_output = gr.Textbox(lines=3, interactive=False, show_label=False)
gr.Markdown("### Negative Prompt"); info_neg_prompt_output = gr.Textbox(lines=3, interactive=False, show_label=False)
gr.Markdown("### Other Parameters"); info_params_output = gr.Textbox(lines=5, interactive=False, show_label=False)
ui_components.update({
"info_image_input": info_image_input, "info_get_button": info_get_button,
"send_to_txt2img_button": send_to_txt2img_button,
"send_to_img2img_button": send_to_img2img_button,
"send_to_inpaint_button": send_to_inpaint_button,
"send_to_outpaint_button": send_to_outpaint_button,
"send_to_hires_fix_button": send_to_hires_fix_button,
"info_prompt_output": info_prompt_output, "info_neg_prompt_output": info_neg_prompt_output,
"info_params_output": info_params_output
})
ui_components["tabs"] = tabs
gr.Markdown("<div style='text-align: center; margin-top: 20px;'>Made by RioShiina with ❤️<br><a href='https://github.com/RioShiina47' target='_blank'>GitHub</a> | <a href='https://huggingface.co/RioShiina' target='_blank'>Hugging Face</a> | <a href='https://civitai.com/user/RioShiina' target='_blank'>Civitai</a></div>")
event_handler_function(ui_components, demo)
return demo |