File size: 1,241 Bytes
ba3687a
 
 
1f7c21d
 
ba3687a
 
 
 
 
 
 
 
 
 
1f7c21d
 
ba3687a
 
1f7c21d
ba3687a
 
 
 
 
 
1f7c21d
ba3687a
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from mcp import StdioServerParameters
from smolagents import MCPClient, CodeAgent


def respond(prompt, history=[]):
    """Send the user prompt to the MCP‑powered agent and return the reply."""
    # Launch the MCP server as a subprocess (stdio transport)
    params = StdioServerParameters(command="python", args=["mcp_server.py"])
    with MCPClient(params) as tools:
        # Replace "gpt-4" with your preferred local or API‑based LLM
        agent = CodeAgent(tools=tools, model="gpt-4")
        result = agent.run(prompt)
    history.append((prompt, result))
    return history, history


with gr.Blocks() as demo:
    chat_history = gr.State([])

    chatbot = gr.Chatbot(label="Enterprise SQL Agent")
    prompt_box = gr.Textbox(
        show_label=False,
        placeholder="Ask questions like: 'Who are my inactive Northeast customers?'",
    )
    prompt_box.submit(respond, [prompt_box, chat_history], [chatbot, chat_history])

    gr.Markdown(
        """
        ### Example Prompts
        - Who are my Northeast customers who haven’t ordered in 6 months?
        - List customers sorted by last order date.
        - Find clients from the West with recent orders.
        """
    )

demo.launch()