| """ |
| NEXUS Visual Weaver - Fixed Gradio 6.5.1 Compatible Version |
| Phase A + HF MCP Bridge |
| """ |
|
|
| import gradio as gr |
| from nexus_hf_mcp_bridge import nexus_hf_bridge |
|
|
|
|
| def run_refine_and_plan(prompt: str, mode: str): |
| return { |
| "input_prompt": prompt, |
| "reasoning_mode": mode, |
| "selected_backbone": "flux_klein_9b" if "image" in prompt.lower() else "ltx_2.3", |
| "plan_summary": f"Plan generated for: {prompt[:80]}...", |
| "next_step": "Run judgment checkpoint or use HF Bridge" |
| } |
|
|
|
|
| def run_judgment_checkpoint(plan: dict): |
| return { |
| "checkpoint_id": "phase_a_checkpoint", |
| "trust_score": 82, |
| "recommendation": "proceed", |
| "justification": "Phase A governance stub", |
| "local_mode": True |
| } |
|
|
|
|
| def hf_authenticate(): |
| return nexus_hf_bridge.tool_authenticate() |
|
|
|
|
| def hf_create_or_update_file(repo_id: str, path_in_repo: str, content: str): |
| if not repo_id or not path_in_repo or not content: |
| return {"status": "error", "message": "Please fill all fields."} |
| return nexus_hf_bridge.tool_create_or_update_file( |
| repo_id=repo_id, path_in_repo=path_in_repo, content=content |
| ) |
|
|
|
|
| def hf_list_files(repo_id: str): |
| if not repo_id: |
| return {"status": "error", "message": "Please provide a repository ID."} |
| return nexus_hf_bridge.tool_list_repo_files(repo_id=repo_id) |
|
|
|
|
| |
| with gr.Blocks() as demo: |
| gr.HTML("<h1 style='text-align:center'>NEXUS Visual Weaver</h1>") |
| gr.Markdown("**Phase A + HF MCP Bridge** (Gradio 6.5.1 Fixed)") |
|
|
| with gr.Tabs(): |
| with gr.Tab("ποΈ Orchestration (Phase A)"): |
| prompt = gr.Textbox(label="Creative Direction", lines=5) |
| mode = gr.Radio(["Strict (High Fidelity)", "Frontier (Creative Exploration)"], value="Strict (High Fidelity)") |
| refine_btn = gr.Button("π Refine & Create Plan", variant="primary") |
| judge_btn = gr.Button("βοΈ Run Judgment Checkpoint") |
|
|
| plan_output = gr.JSON(label="Orchestration Plan") |
| checkpoint_output = gr.JSON(label="Governance Checkpoint") |
|
|
| refine_btn.click(run_refine_and_plan, inputs=[prompt, mode], outputs=plan_output) |
| judge_btn.click(run_judgment_checkpoint, inputs=[plan_output], outputs=checkpoint_output) |
|
|
| with gr.Tab("π€ HF MCP Bridge"): |
| gr.Markdown("## Hugging Face MCP Bridge") |
| auth_btn = gr.Button("π Authenticate with Hugging Face", variant="primary") |
| auth_status = gr.JSON() |
| auth_btn.click(hf_authenticate, outputs=auth_status) |
|
|
| gr.Markdown("---") |
|
|
| with gr.Row(): |
| with gr.Column(): |
| repo_id = gr.Textbox(label="Repository ID") |
| path_in_repo = gr.Textbox(label="Path in Repo") |
| content = gr.Textbox(label="Content", lines=8) |
| update_btn = gr.Button("π Create / Update File") |
| update_result = gr.JSON() |
| update_btn.click(hf_create_or_update_file, inputs=[repo_id, path_in_repo, content], outputs=update_result) |
|
|
| with gr.Column(): |
| list_repo = gr.Textbox(label="Repository ID to List") |
| list_btn = gr.Button("π List Files") |
| list_result = gr.JSON() |
| list_btn.click(hf_list_files, inputs=[list_repo], outputs=list_result) |
|
|
| with gr.Tab("π System"): |
| gr.Markdown("### Status\n- Phase A: Active\n- HF MCP Bridge: Integrated\n- Gradio: 6.5.1 Compatible") |
|
|
| demo.launch(mcp_server=True) |