import os import gradio as gr 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() as demo: gr.Markdown("# ControlNet 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 }) gr.Markdown("
Made by RioShiina with ❤️
GitHub | Hugging Face | Civitai
") event_handler_function(ui_components, demo) return demo