Vladt-Tempest commited on
Commit
456c011
·
1 Parent(s): b713353

Working with HF server

Browse files
Files changed (3) hide show
  1. app.py +28 -0
  2. requirements.txt +4 -0
  3. test.py +7 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ from smolagents import InferenceClientModel, CodeAgent, MCPClient
5
+
6
+
7
+ try:
8
+ mcp_client = MCPClient(
9
+ #{"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"} # Example Server running on HF
10
+ #{"url": "http://127.0.0.1:7861/gradio_api/mcp/sse"} # Example Server running locally
11
+ {"url": "https://vladt-tempest-gradio-mcp-server.hf.space/gradio_api/mcp/sse"}, # My server
12
+ )
13
+ tools = mcp_client.get_tools()
14
+
15
+ model = InferenceClientModel(token=os.getenv("HF_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=["Analyze the sentiment of the following text 'This is awesome'"],
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()
27
+ finally:
28
+ mcp_client.disconnect()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ smolagents[mcp]
2
+ gradio[mcp]
3
+ mcp
4
+ fastmcp
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))