File size: 1,973 Bytes
b5ac208
 
 
 
3119b7f
b5ac208
 
 
 
 
 
 
3500e03
b5ac208
76aea54
b5ac208
3119b7f
b5ac208
3119b7f
b5ac208
 
 
2d31d6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3119b7f
2d31d6d
b5ac208
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
import os
import gradio as gr
from core.settings import *

from .imagegen_ui import create_ui as create_imagegen_ui

MAX_DYNAMIC_CONTROLS = 10

def build_ui(event_handler_function):
    ui_components = {}

    with gr.Blocks() as demo:
        gr.Markdown("# ImageGen")
        gr.Markdown(
            "This demo is a streamlined version of the [Comfy web UI](https://github.com/RioShiina47/comfy-webui)'s [ImageGen](https://huggingface.co/spaces/RioShiina/ImageGen) functionality. Support [High-Level MCP](https://rioshiina-imagegen.hf.space/gradio_api/mcp/)."
        )
        ui_components.update(create_imagegen_ui())
        
        gr.Markdown("<div style='text-align: left; 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)

        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
                fn.api_name = False

    return demo