Spaces:
Sleeping
Sleeping
create gradio app
Browse files- app_gradio.py +27 -0
app_gradio.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
{"url": "http://localhost:7860/gradio_api/mcp/sse"}
|
| 10 |
+
)
|
| 11 |
+
tools = mcp_client.get_tools()
|
| 12 |
+
|
| 13 |
+
model = InferenceClientModel()
|
| 14 |
+
agent = CodeAgent(tools=[*tools], model=model)
|
| 15 |
+
|
| 16 |
+
demo = gr.ChatInterface(
|
| 17 |
+
fn=lambda message, history: str(agent.run(message)),
|
| 18 |
+
type="messages",
|
| 19 |
+
examples=["Prime factorization of 68"],
|
| 20 |
+
title="Agent with MCP Tools",
|
| 21 |
+
description="This is a simple agent that uses MCP tools to answer questions.",
|
| 22 |
+
messages=[],
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
demo.launch()
|
| 26 |
+
finally:
|
| 27 |
+
mcp_client.disconnect()
|