i.litvinov commited on
Commit
1ec107c
·
1 Parent(s): cddbf43

init commit

Browse files
Files changed (3) hide show
  1. app.py +26 -0
  2. client.py +7 -0
  3. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ from mcp import StdioServerParameters
5
+ from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClient
6
+
7
+
8
+ mcp_client = MCPClient(
9
+ {"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"} # This is the MCP Client we created in the previous section
10
+ )
11
+ tools = mcp_client.get_tools()
12
+
13
+
14
+ model = InferenceClientModel(token=os.getenv("HF_TOKEN"))
15
+ agent = CodeAgent(tools=[*tools], model=model)
16
+
17
+
18
+ demo = gr.ChatInterface(
19
+ fn=lambda message, history: str(agent.run(message)),
20
+ type="messages",
21
+ examples=["Prime factorization of 68"],
22
+ title="Agent with MCP Tools",
23
+ description="This is a simple agent that uses MCP tools to answer questions."
24
+ )
25
+
26
+ demo.launch()
client.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ from smolagents.mcp_client import MCPClient
2
+
3
+ with MCPClient(
4
+ {"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"}
5
+ ) as tools:
6
+ # Tools from the remote server are available
7
+ print("\n".join(f"{t.name}: {t.description}" for t in tools))
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ smolagents[mcp]