specimba's picture
Update app.py
a5ac968 verified
Raw
History Blame
7.22 kB
"""
integrated_nexus_app.py
NEXUS Visual Weaver - Integrated App (Phase A + HF MCP Bridge)
This is the main Gradio application for the hackathon Space.
It combines:
- Phase A: Orchestration + Governance Checkpoint UI
- HF MCP Bridge: Authentication + Repository tools exposed as MCP tools
Launch with mcp_server=True for agent integration.
"""
import gradio as gr
from nexus_hf_mcp_bridge import nexus_hf_bridge
# ============================================================
# Phase A - Original Orchestration Logic (Stub for now)
# ============================================================
def run_refine_and_plan(prompt: str, mode: str):
"""Phase A orchestration stub."""
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):
"""Phase A governance checkpoint stub."""
return {
"checkpoint_id": "phase_a_checkpoint",
"trust_score": 82,
"recommendation": "proceed",
"justification": "Phase A governance stub. Real thermodynamic detectors coming in next phase.",
"local_mode": True
}
# ============================================================
# HF MCP Bridge UI Functions
# ============================================================
def hf_authenticate():
"""Trigger HF OAuth Device Code flow."""
result = nexus_hf_bridge.tool_authenticate()
return result
def hf_create_or_update_file(repo_id: str, path_in_repo: str, content: str):
"""Create or update a file in a Hugging Face repo via the bridge."""
if not repo_id or not path_in_repo or not content:
return {"status": "error", "message": "Please fill all fields."}
result = nexus_hf_bridge.tool_create_or_update_file(
repo_id=repo_id,
path_in_repo=path_in_repo,
content=content
)
return result
def hf_list_files(repo_id: str):
"""List files in a repository."""
if not repo_id:
return {"status": "error", "message": "Please provide a repository ID."}
result = nexus_hf_bridge.tool_list_repo_files(repo_id=repo_id)
return result
# ============================================================
# Gradio UI
# ============================================================
with gr.Blocks(
title="NEXUS Visual Weaver",
theme=gr.themes.Soft(),
css="""
.nexus-header { font-size: 2.1rem; font-weight: 700; }
.section-box { border: 1px solid #374151; border-radius: 10px; padding: 16px; margin-top: 10px; }
"""
) as demo:
gr.HTML("""
<div style="text-align: center; margin-bottom: 1rem;">
<h1 class="nexus-header">NEXUS Visual Weaver</h1>
<span style="background:#1f2937; color:#93c5fd; padding:2px 10px; border-radius:9999px; font-size:0.75rem;">
Phase A + HF MCP Bridge
</span>
</div>
""")
with gr.Tabs():
# ===================== TAB 1: Phase A Orchestration =====================
with gr.Tab("πŸŽ›οΈ Orchestration (Phase A)"):
with gr.Row():
with gr.Column(scale=3):
prompt = gr.Textbox(
label="Creative Direction",
placeholder="A Slavic model in patent leather trench coat with crimson hardware...",
lines=5
)
mode = gr.Radio(
["Strict (High Fidelity)", "Frontier (Creative Exploration)"],
value="Strict (High Fidelity)",
label="Reasoning Mode"
)
with gr.Column(scale=2):
gr.Markdown("### Current Status")
gr.Markdown("- Phase A orchestration active\n- HF MCP Bridge ready\n- Governance layer: Stub mode")
with gr.Row():
refine_btn = gr.Button("πŸ”„ Refine & Create Plan", variant="primary")
judge_btn = gr.Button("βš–οΈ Run Judgment Checkpoint", variant="secondary")
with gr.Row():
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)
# ===================== TAB 2: HF MCP Bridge =====================
with gr.Tab("πŸ€– HF MCP Bridge"):
gr.Markdown("## Hugging Face MCP Bridge")
gr.Markdown("Authenticate once, then use the tools below. All operations go through the sovereign bridge.")
with gr.Row():
auth_btn = gr.Button("πŸ” Authenticate with Hugging Face (Device Code)", variant="primary", scale=1)
auth_status = gr.JSON(label="Authentication Status")
auth_btn.click(hf_authenticate, outputs=auth_status)
gr.Markdown("---")
with gr.Row():
with gr.Column():
repo_id = gr.Textbox(label="Repository ID", placeholder="username/my-model")
path_in_repo = gr.Textbox(label="Path in Repository", placeholder="README.md or folder/file.txt")
content = gr.Textbox(label="File Content", lines=8, placeholder="Write your content here...")
update_btn = gr.Button("πŸ“ Create / Update File", variant="primary")
update_result = gr.JSON(label="Result")
with gr.Column():
list_repo = gr.Textbox(label="Repository ID to List")
list_btn = gr.Button("πŸ“‚ List Files")
list_result = gr.JSON(label="Repository Files")
update_btn.click(
hf_create_or_update_file,
inputs=[repo_id, path_in_repo, content],
outputs=update_result
)
list_btn.click(
hf_list_files,
inputs=[list_repo],
outputs=list_result
)
# ===================== TAB 3: System =====================
with gr.Tab("πŸ“Š System"):
gr.Markdown("### NEXUS Visual Weaver Status")
gr.Markdown("""
- **Phase A**: Orchestration + Governance Checkpoint (active)
- **HF MCP Bridge**: Authentication + Repository tools (integrated)
- **MCP Server**: Enabled (`mcp_server=True`)
- **OAuth App**: X - GROK integration for HF
- **Next**: Thermodynamic governance layer + Zapier MCP integration
""")
# ============================================================
# Launch
# ============================================================
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=7860,
show_api=True,
mcp_server=True, # Important for MCP tools
ssr_mode=False
)