charlesscottwilliams commited on
Commit
2d686b8
·
1 Parent(s): 99e5545
Files changed (2) hide show
  1. app.py +28 -4
  2. requirements.txt +2 -0
app.py CHANGED
@@ -1,7 +1,31 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
1
  import gradio as gr
2
+ import os
3
 
4
+ from mcp import StdioServerParameters
5
+ from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClient
6
+
7
+ try:
8
+ mcp_client = MCPClient(
9
+ {
10
+ "url": "http://localhost:7860/gradio_api/mcp/sse",
11
+ "transport": "sse",
12
+ }
13
+ )
14
+ tools = mcp_client.get_tools()
15
+
16
+ model = InferenceClientModel(token=os.getenv("HF_TOKEN"))
17
+
18
+ agent = CodeAgent(tools=[*tools], model=model)
19
+
20
+ demo = gr.ChatInterface(
21
+ fn = lambda message, history: str(agent.run(message)),
22
+ type="messages",
23
+ examples=["Prime factorization of 68"],
24
+ title="Agent with MCP Tools",
25
+ description="This is a simple agent that uses MCP tools to answer questions"
26
+ )
27
+
28
+ demo.launch()
29
+ finally:
30
+ mcp_client.disconnect()
31
 
 
 
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ smolagent[mcp]