Alina Buzachis commited on
Commit
8d86b47
·
0 Parent(s):

Initial commit

Browse files
Files changed (3) hide show
  1. README.md +9 -0
  2. app.py +30 -0
  3. requirements.txt +2 -0
README.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Gradio as an MCP Client
3
+ colorFrom: gray
4
+ colorTo: pink
5
+ sdk: gradio
6
+ sdk_version: "4.44.1"
7
+ app_file: app.py
8
+ pinned: false
9
+ ---
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Connect to the MCP Server and get the tools that we can use to answer questions.
9
+ try:
10
+ mcp_client = MCPClient(
11
+ {"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"}
12
+ )
13
+ tools = mcp_client.get_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=["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 is a long-lived object that needs to be closed when the program exits.
29
+ mcp_client.disconnect()
30
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ smolagents[mcp]