applemuncy commited on
Commit
837a945
·
verified ·
1 Parent(s): c99244a

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +32 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from mcp.client.stdio import StdioServerParameters
4
+ from smolagents import InferenceClientModel, CodeAgent, ToolCollection
5
+ from smolagents.mcp_client import MCPClient
6
+
7
+
8
+ try:
9
+ mcp_client = MCPClient(
10
+ ## Try this working example on the hub:
11
+ #{"url": "https://abidlabs-mcp-tools2.hf.space/gradio_api/mcp/sse"}
12
+ {"url": "https://applemuncy-mcp-sentiment.hf.space/gradio_api/mcp/sse"}
13
+ #{"url": "http://localhost:7860/gradio_api/mcp/sse"}
14
+ #"transport": "sse"
15
+
16
+ )
17
+ tools = mcp_client.get_tools()
18
+
19
+ model = InferenceClientModel()
20
+ agent = CodeAgent(tools=[*tools], model=model)
21
+
22
+ demo = gr.ChatInterface(
23
+ fn=lambda message, history: str(agent.run(message)),
24
+ type="messages",
25
+ examples=["Prime factorization of 68"],
26
+ title="Agent with MCP Tools",
27
+ description="This is a simple agent that uses MCP tools to answer questions.",
28
+ )
29
+
30
+ demo.launch()
31
+ finally:
32
+ mcp_client.disconnect()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ smolagents[mcp]
2
+ gradio[mcp]
3
+ mcp>=1.9.2