Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,33 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from mcp import StdioServerParameters
|
| 3 |
from smolagents import MCPClient, CodeAgent
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
with MCPClient(params) as tools:
|
| 10 |
-
agent = CodeAgent(tools=tools, model="gpt-4") #
|
| 11 |
answer = agent.run(message)
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 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 |
|
|
@@ -30,8 +38,9 @@ with gr.Blocks() as demo:
|
|
| 30 |
- List customers sorted by last order date.
|
| 31 |
- Find clients from the West with recent orders.
|
| 32 |
|
| 33 |
-
|
| 34 |
"""
|
| 35 |
)
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
| 1 |
+
import pathlib
|
| 2 |
import gradio as gr
|
| 3 |
from mcp import StdioServerParameters
|
| 4 |
from smolagents import MCPClient, CodeAgent
|
| 5 |
|
| 6 |
+
# Absolute path to the MCP server script that lives next to this file
|
| 7 |
+
SERVER_PATH = pathlib.Path(__file__).with_name("mcp_server.py")
|
| 8 |
|
| 9 |
+
|
| 10 |
+
def respond(message: str, history: list):
|
| 11 |
+
"""Send the user message to the MCP‑powered agent and return the reply."""
|
| 12 |
+
# Launch the MCP server as a subprocess via stdio
|
| 13 |
+
params = StdioServerParameters(command="python", args=[str(SERVER_PATH)])
|
| 14 |
with MCPClient(params) as tools:
|
| 15 |
+
agent = CodeAgent(tools=tools, model="gpt-4") # change to your LLM if needed
|
| 16 |
answer = agent.run(message)
|
| 17 |
+
|
| 18 |
+
# Update chat history using the new Gradio 'messages' format
|
| 19 |
+
history.append({"role": "user", "content": message})
|
| 20 |
+
history.append({"role": "assistant", "content": answer})
|
| 21 |
return history, history
|
| 22 |
|
| 23 |
|
| 24 |
+
with gr.Blocks(title="Enterprise SQL Agent") as demo:
|
| 25 |
chat_state = gr.State([])
|
|
|
|
| 26 |
|
| 27 |
+
chatbot = gr.Chatbot(label="Enterprise SQL Agent", type="messages")
|
| 28 |
textbox = gr.Textbox(
|
|
|
|
| 29 |
placeholder="Ask: Who are my inactive Northeast customers?",
|
| 30 |
+
show_label=False,
|
| 31 |
)
|
| 32 |
textbox.submit(respond, [textbox, chat_state], [chatbot, chat_state])
|
| 33 |
|
|
|
|
| 38 |
- List customers sorted by last order date.
|
| 39 |
- Find clients from the West with recent orders.
|
| 40 |
|
| 41 |
+
_Built with MCP, smolagents, and Gradio_
|
| 42 |
"""
|
| 43 |
)
|
| 44 |
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
demo.launch()
|