Spaces:
Runtime error
Runtime error
Commit
·
5f75330
1
Parent(s):
96368d2
Add init MCP file
Browse files
app.py
CHANGED
|
@@ -1,7 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
from mcp.client.stdio import StdioServerParameters
|
| 4 |
+
from smolagents import ToolCollection, CodeAgent
|
| 5 |
+
from smolagents import CodeAgent, InferenceClientModel
|
| 6 |
+
from smolagents.mcp_client import MCPClient
|
| 7 |
|
| 8 |
+
mcp_client = MCPClient(
|
| 9 |
+
{"url"="http://localhost:7860/gradio_api/mcp/sse"}
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
tools=mcp_client.get_tools()
|
| 13 |
+
|
| 14 |
+
model = InferenceClientModel()
|
| 15 |
+
agent = CodeAgent(tools=[*tools], model=model)
|
| 16 |
+
|
| 17 |
+
demo = gr.ChatInterface(
|
| 18 |
+
fn=lambda message, history: str(agent.run(message)),
|
| 19 |
+
type="messages",
|
| 20 |
+
examples=["Prime factorization of 68"],
|
| 21 |
+
title="Agent with MCP Tools",
|
| 22 |
+
description="This is a simple agent that uses MCP tools to answer questions.",
|
| 23 |
+
messages=[],
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
demo.launch()
|