SlipknotTN commited on
Commit
5c77188
·
1 Parent(s): ca30cbc

First commit

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. app.py +32 -0
  3. mcp_test.py +7 -0
  4. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ hf_api_key.txt
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ from smolagents import InferenceClientModel, CodeAgent, MCPClient
5
+
6
+
7
+ try:
8
+
9
+ mcp_client = MCPClient(
10
+ {"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"}
11
+ )
12
+ tools = mcp_client.get_tools()
13
+ print(tools)
14
+
15
+ model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN"))
16
+ agent = CodeAgent(tools=[*tools], model=model, additional_authorized_imports=["json", "ast", "urllib", "base64"])
17
+
18
+ demo = gr.ChatInterface(
19
+ fn=lambda message, history: str(agent.run(message)),
20
+ type="messages",
21
+ examples=[
22
+ "Prime factorization of 68",
23
+ "Analyze the sentiment of the following text 'This is awesome'", # No tool for this one
24
+ ],
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
+
31
+ finally:
32
+ mcp_client.disconnect()
mcp_test.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]