Spaces:
Runtime error
Runtime error
Alexi Canales
commited on
Commit
·
e9d3bd2
1
Parent(s):
e5dac0e
initial commit
Browse files- .gitignore +1 -0
- README.md +4 -0
- app.py +28 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.venv
|
README.md
CHANGED
@@ -11,3 +11,7 @@ short_description: 'Prime Factorization '
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
pip install "smolagents[mcp]" "gradio[mcp]" mcp
|
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
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"}
|
11 |
+
{"url": "http://localhost:7860/gradio_api/mcp/sse"}
|
12 |
+
)
|
13 |
+
tools = mcp_client.get_tools()
|
14 |
+
|
15 |
+
model = InferenceClientModel()
|
16 |
+
agent = CodeAgent(tools=[*tools], model=model)
|
17 |
+
|
18 |
+
demo = gr.ChatInterface(
|
19 |
+
fn=lambda message, history: str(agent.run(message)),
|
20 |
+
type="messages",
|
21 |
+
examples=["Prime factorization of 68"],
|
22 |
+
title="Agent with MCP Tools",
|
23 |
+
description="This is a simple agent that uses MCP tools to answer questions.",
|
24 |
+
)
|
25 |
+
|
26 |
+
demo.launch()
|
27 |
+
finally:
|
28 |
+
mcp_client.disconnect()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio[mcp]
|
2 |
+
smolagents[mcp]
|