[email protected] commited on
Commit
66ab23c
·
0 Parent(s):

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +32 -0
  2. requirements.txt +2 -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 CodeAgent, ToolCollection,InferenceClientModel
5
+ from smolagents.mcp_client import MCPClient
6
+
7
+ # define mcp server the clinet can communicate
8
+
9
+ try:
10
+ mcp_client = MCPClient(
11
+ {"url": "http://localhost:7860/gradio_api/mcp/sse"},
12
+ )
13
+
14
+ tools = mcp_client.get_tools()
15
+
16
+ model = InferenceClientModel() # defne model to use
17
+ agent = CodeAgent(tools=[*tools],model=model) # create agent
18
+
19
+
20
+ # creating gradio interface
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,2 @@
 
 
 
1
+ gradio[mcp]
2
+ smolagents[mcp]