Spaces:
Runtime error
Runtime error
File size: 1,452 Bytes
d6dcf1f c868868 bcaddf4 c868868 bcaddf4 c868868 bcaddf4 c868868 bcaddf4 c868868 bcaddf4 c868868 d6dcf1f a311b3d c868868 bcaddf4 | 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 43 44 45 | import gradio as gr
import httpx
import os
# Use the container's base URL (relative path works inside the same app)
BASE_URL = os.environ.get("BASE_URL", "") # "" means same host:port as Gradio
def query_agent(agent: str, message: str):
url = f"{BASE_URL}/api/{agent}"
try:
r = httpx.post(url, json={"text": message})
return r.json().get("response", "No response")
except Exception as e:
return str(e)
def query_all(message: str):
url = f"{BASE_URL}/api/run_all"
try:
r = httpx.post(url, json={"text": message})
return [resp["response"] for resp in r.json()["responses"]]
except Exception as e:
return [str(e)]
def build_ui():
with gr.Blocks() as demo:
gr.Markdown("## Multi-Agent Control Panel")
with gr.Tab("Single Agent"):
msg = gr.Textbox(label="Message")
agent = gr.Dropdown(["agent1", "agent2", "agent3", "agent4"], label="Choose Agent")
output = gr.Textbox(label="Agent Response")
btn = gr.Button("Send")
btn.click(fn=lambda m, a: query_agent(a, m), inputs=[msg, agent], outputs=output)
with gr.Tab("All Agents"):
msg_all = gr.Textbox(label="Message for All Agents")
outputs_all = gr.JSON(label="All Responses")
btn_all = gr.Button("Broadcast")
btn_all.click(fn=query_all, inputs=msg_all, outputs=outputs_all)
return demo
|