Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
from
|
| 4 |
-
from smolagents import InferenceClientModel, CodeAgent, ToolCollection
|
| 5 |
from smolagents.mcp_client import MCPClient
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
## Try this working example on the hub:
|
| 11 |
-
# {"url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse"}
|
| 12 |
-
{"url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse"}
|
| 13 |
-
)
|
| 14 |
tools = mcp_client.get_tools()
|
| 15 |
|
|
|
|
| 16 |
model = InferenceClientModel()
|
| 17 |
-
agent = CodeAgent(tools=
|
| 18 |
|
|
|
|
| 19 |
demo = gr.ChatInterface(
|
| 20 |
-
fn=lambda message, history: str(agent.run(message)),
|
| 21 |
type="messages",
|
| 22 |
examples=["Prime factorization of 68"],
|
| 23 |
title="Agent with MCP Tools",
|
| 24 |
-
description="This is a simple agent that uses MCP tools to answer questions."
|
| 25 |
)
|
| 26 |
|
| 27 |
demo.launch()
|
| 28 |
-
finally:
|
| 29 |
-
mcp_client.disconnect()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
from smolagents import InferenceClientModel, CodeAgent
|
|
|
|
| 4 |
from smolagents.mcp_client import MCPClient
|
| 5 |
|
| 6 |
+
# Use a 'with' block to ensure proper disconnection
|
| 7 |
+
with MCPClient({"url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse"}) as mcp_client:
|
| 8 |
+
# Fetch the available tools from the remote MCP server
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
tools = mcp_client.get_tools()
|
| 10 |
|
| 11 |
+
# Set up the agent with tools and a default language model
|
| 12 |
model = InferenceClientModel()
|
| 13 |
+
agent = CodeAgent(tools=tools, model=model)
|
| 14 |
|
| 15 |
+
# Launch Gradio interface
|
| 16 |
demo = gr.ChatInterface(
|
| 17 |
+
fn=lambda message, history: (str(agent.run(message)), history),
|
| 18 |
type="messages",
|
| 19 |
examples=["Prime factorization of 68"],
|
| 20 |
title="Agent with MCP Tools",
|
| 21 |
+
description="This is a simple agent that uses MCP tools to answer questions."
|
| 22 |
)
|
| 23 |
|
| 24 |
demo.launch()
|
|
|
|
|
|