Spaces:
Running on Zero
Running on Zero
| 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 build_ui(event_handler_function): | |
| ui_components = {} | |
| with gr.Blocks() as demo: | |
| gr.Markdown(" ") | |
| gr.Markdown( | |
| " " | |
| ) | |
| with gr.Tabs(elem_id="tabs_container") as 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["tabs"] = tabs | |
| ui_components["image_gen_tabs"] = tabs | |
| gr.Markdown(" ") | |
| event_handler_function(ui_components, demo) | |
| try: | |
| import mcp_tools as mcp | |
| if hasattr(mcp, "register_high_level_mcp_apis"): | |
| mcp.register_high_level_mcp_apis(demo) | |
| mcp.cleanup_dependencies_api_names(demo) | |
| elif hasattr(mcp, 'MCP_FUNCTIONS') and isinstance(mcp.MCP_FUNCTIONS, list): | |
| for func in mcp.MCP_FUNCTIONS: | |
| gr.api(func) | |
| print(f"✅ Registered MCP API endpoint: '{func.__name__}'") | |
| except Exception as e: | |
| print(f"⚠️ Warning registering MCP functions: {e}") | |
| # Disable API exposure for all atomic UI event handlers | |
| high_level_names = getattr(mcp, "HIGH_LEVEL_MCP_API_NAMES", set()) | |
| for fn in demo.fns.values(): | |
| if getattr(fn, "api_name", None) not in high_level_names: | |
| fn.show_api = False | |
| return demo |