Update app.py
Browse files
app.py
CHANGED
|
@@ -2,26 +2,36 @@ import gradio as gr
|
|
| 2 |
from mcp import StdioServerParameters
|
| 3 |
from smolagents import MCPClient, CodeAgent
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
params = StdioServerParameters(command="python", args=["mcp_server.py"])
|
| 8 |
with MCPClient(params) as tools:
|
| 9 |
-
agent = CodeAgent(tools=tools, model="gpt-4") #
|
| 10 |
-
|
| 11 |
-
history.append((
|
| 12 |
return history, history
|
| 13 |
|
|
|
|
| 14 |
with gr.Blocks() as demo:
|
| 15 |
-
|
| 16 |
chatbot = gr.Chatbot(label="Enterprise SQL Agent")
|
| 17 |
-
|
| 18 |
-
textbox.
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 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()
|