Spaces:
Runtime error
Runtime error
Commit
·
7e9c7b8
1
Parent(s):
fba89ac
Initial commit
Browse files- app.py +30 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
from smolagents import InferenceClientModel, CodeAgent#, ToolCollection
|
4 |
+
from smolagents.mcp_client import MCPClient
|
5 |
+
|
6 |
+
|
7 |
+
try:
|
8 |
+
mcp_client = MCPClient(
|
9 |
+
## Try this working example on the hub:
|
10 |
+
# {"url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse"} # --server: https://huggingface.co/spaces/abidlabs/mcp-tools
|
11 |
+
{"url": "https://rajaramesh-mcp-sentiment.hf.space/gradio_api/mcp/sse"} # --remote server: https://huggingface.co/spaces/rajaramesh/mcp-sentiment/
|
12 |
+
# {"url": "http://localhost:7860/gradio_api/mcp/sse"} # --local server
|
13 |
+
)
|
14 |
+
tools = mcp_client.get_tools()
|
15 |
+
print(f"my tools: {[*tools]}")
|
16 |
+
|
17 |
+
model = InferenceClientModel()
|
18 |
+
agent = CodeAgent(tools=[*tools], model=model)
|
19 |
+
|
20 |
+
demo = gr.ChatInterface(
|
21 |
+
fn=lambda message, history: str(agent.run(message)), #here chat interface will run the function and provides 2 arguments
|
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()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio[mcp]
|
2 |
+
smolagents[mcp]
|