liztan commited on
Commit
f6f3ca8
·
1 Parent(s): 9884d6c

Initial commit

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