Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,33 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
|
4 |
-
from
|
|
|
|
|
|
|
5 |
|
|
|
6 |
|
7 |
try:
|
8 |
mcp_client = MCPClient(
|
9 |
-
{"url": "https://abidlabs-mcp-
|
10 |
)
|
|
|
11 |
tools = mcp_client.get_tools()
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
|
16 |
demo = gr.ChatInterface(
|
17 |
-
fn=
|
18 |
type="messages",
|
19 |
-
examples=["
|
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()
|
|
|
|
|
25 |
finally:
|
26 |
-
mcp_client.
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
+
from mcp.client.stdio import StdioServerParameters
|
4 |
+
from smolagents import ToolCollection, CodeAgent
|
5 |
+
from smolagents import CodeAgent, InferenceClientModel
|
6 |
+
from smolagents.mcp_client import MCPClient
|
7 |
|
8 |
+
model = InferenceClientModel()
|
9 |
|
10 |
try:
|
11 |
mcp_client = MCPClient(
|
12 |
+
{"url": "https://abidlabs-mcp-tools2.hf.space/gradio_api/mcp/sse"}
|
13 |
)
|
14 |
+
|
15 |
tools = mcp_client.get_tools()
|
16 |
+
agent = CodeAgent(tools=[*tools], model=model)
|
17 |
|
18 |
+
def call_agent(message, history):
|
19 |
+
return str(agent.run(message))
|
20 |
|
21 |
demo = gr.ChatInterface(
|
22 |
+
fn=call_agent,
|
23 |
type="messages",
|
24 |
+
examples=["Prime factorization of 68"],
|
25 |
title="Agent with MCP Tools",
|
26 |
description="This is a simple agent that uses MCP tools to answer questions.",
|
27 |
)
|
28 |
|
29 |
demo.launch()
|
30 |
+
except Exception as e:
|
31 |
+
raise e
|
32 |
finally:
|
33 |
+
mcp_client.stop()
|