"""Application layout: one shared workspace for all image tasks.""" from __future__ import annotations import gradio as gr from core.runtime_config import CONFIG from .shared import studio_ui from .theme import APP_CSS def build_ui(event_handler_function): ui_components = {} theme = gr.themes.Soft( primary_hue="indigo", secondary_hue="violet", neutral_hue="slate", radius_size="lg", ) with gr.Blocks( theme=theme, css=APP_CSS, title="ImageGen Studio", fill_width=True, ) as demo: gr.HTML( """

ImageGen Studio

一套界面完成文生图、图生图、局部重绘、扩图和高清修复。模型与任务切换会保留你的提示词和已上传素材。

① 选任务先决定生成、编辑,还是修复图片
② 选模型并描述不确定时使用快速方案和模型提示
③ 生成并迭代先用默认参数出图,再逐项微调
""" ) ui_components.update(studio_ui.create_ui()) with gr.Accordion("使用说明与常见问题", open=False): gr.Markdown( """ - **切换任务会丢内容吗?** 不会。提示词、模型、参数和上传素材都保留,只切换当前需要的控件。 - **中文提示词是否可用?** Qwen-Image、Z-Image、HunyuanImage 等优先支持中文;SDXL 动漫模型更适合英文标签,模型说明会给出建议。 - **为什么显示排队?** GPU 任务通过同一队列调度,避免 UI 和 MCP 同时抢占显存。等待期间可以修改表单,但同一按钮不会重复提交。 - **第一次为什么较慢?** 首次使用某模型会下载权重;下载过程有互斥保护,避免并发请求重复下载或写坏文件。 - **扩展能力为什么会变化?** LoRA、ControlNet、IP-Adapter 等只在当前模型兼容时显示;不兼容的隐藏状态不会送入生成管线。 """ ) gr.HTML( """ """ ) event_handler_function(ui_components, demo) high_level_names = set() if CONFIG.enable_mcp: try: import mcp_tools as mcp high_level_names = getattr(mcp, "HIGH_LEVEL_MCP_API_NAMES", set()) 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) except Exception as exc: print(f"⚠️ MCP 接口注册失败:{exc}") # Only the intentional high-level MCP surface is public. for fn in demo.fns.values(): if getattr(fn, "api_name", None) not in high_level_names: fn.show_api = False return demo