mgbam commited on
Commit
5997785
·
verified ·
1 Parent(s): 2e76b4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -15
app.py CHANGED
@@ -2,26 +2,36 @@ import gradio as gr
2
  from mcp import StdioServerParameters
3
  from smolagents import MCPClient, CodeAgent
4
 
5
- def respond(prompt, history=[]):
6
- # Launch MCP subprocess
 
7
  params = StdioServerParameters(command="python", args=["mcp_server.py"])
8
  with MCPClient(params) as tools:
9
- agent = CodeAgent(tools=tools, model="gpt-4") # Replace with your local or API model
10
- result = agent.run(prompt)
11
- history.append((prompt, result))
12
  return history, history
13
 
 
14
  with gr.Blocks() as demo:
15
- chat_history = gr.State([])
16
  chatbot = gr.Chatbot(label="Enterprise SQL Agent")
17
- textbox = gr.Textbox(show_label=False, placeholder="Ask questions like 'List inactive customers in Northeast'")
18
- textbox.submit(respond, [textbox, chat_history], [chatbot, chat_history])
19
-
20
- gr.Markdown(\"\"\"\n
21
- ### Example Prompts:
22
- - Who are my Northeast customers who haven’t ordered in 6 months?
23
- - List customers sorted by last order date.
24
- - Find clients from the West with recent orders.
25
- \"\"\")
 
 
 
 
 
 
 
 
26
 
27
  demo.launch()
 
2
  from mcp import StdioServerParameters
3
  from smolagents import MCPClient, CodeAgent
4
 
5
+
6
+ def respond(message, history):
7
+ """Send the user's message to the MCP-powered agent and return its reply."""
8
  params = StdioServerParameters(command="python", args=["mcp_server.py"])
9
  with MCPClient(params) as tools:
10
+ agent = CodeAgent(tools=tools, model="gpt-4") # swap for your LLM
11
+ answer = agent.run(message)
12
+ history.append((message, answer))
13
  return history, history
14
 
15
+
16
  with gr.Blocks() as demo:
17
+ chat_state = gr.State([])
18
  chatbot = gr.Chatbot(label="Enterprise SQL Agent")
19
+
20
+ textbox = gr.Textbox(
21
+ show_label=False,
22
+ placeholder="Ask: Who are my inactive Northeast customers?",
23
+ )
24
+ textbox.submit(respond, [textbox, chat_state], [chatbot, chat_state])
25
+
26
+ gr.Markdown(
27
+ """
28
+ ### Example Prompts
29
+ - Who are my Northeast customers who haven’t ordered in 6 months?
30
+ - List customers sorted by last order date.
31
+ - Find clients from the West with recent orders.
32
+
33
+ Built with MCP, smolagents, and Gradio
34
+ """
35
+ )
36
 
37
  demo.launch()