Hieu Tran commited on
Commit
2496d18
·
1 Parent(s): 07f4c06

gradio mcp client

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +29 -0
  3. requirements.txt +5 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ load_dotenv()
3
+ import gradio as gr
4
+ import os
5
+
6
+ from smolagents import InferenceClientModel, CodeAgent, MCPClient
7
+
8
+
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,
20
+ history: str(agent.run(message)),
21
+ type="messages",
22
+ examples=["Analyze the sentiment of the following text 'This is awesome'"],
23
+ title="Agent with MCP Tools",
24
+ description="This is a simple agent that uses MCP tools to answer questions.",
25
+ )
26
+
27
+ demo.launch()
28
+ finally:
29
+ mcp_client.disconnect()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ smolagents[mcp]
2
+ gradio[mcp]
3
+ mcp
4
+ fastmcp
5
+ python-dotenv