Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
9 |
+
try:
|
10 |
+
mcp_client = MCPClient(
|
11 |
+
# {"url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse"}
|
12 |
+
{"url": "https://rajeshthangaraj1-mcp-sentiment.hf.space/gradio_api/mcp/sse"}
|
13 |
+
)
|
14 |
+
tools = mcp_client.get_tools()
|
15 |
+
|
16 |
+
model = InferenceClientModel()
|
17 |
+
agent = CodeAgent(tools=[*tools], model=model)
|
18 |
+
|
19 |
+
def call_agent(message, history):
|
20 |
+
return str(agent.run(message))
|
21 |
+
|
22 |
+
|
23 |
+
demo = gr.ChatInterface(
|
24 |
+
fn=lambda message, history: str(agent.run(message)),
|
25 |
+
type="messages",
|
26 |
+
examples=["Prime factorization of 68"],
|
27 |
+
title="Agent with MCP Tools",
|
28 |
+
description="This is a simple agent that uses MCP tools to answer questions.",
|
29 |
+
messages=[],
|
30 |
+
)
|
31 |
+
|
32 |
+
demo.launch()
|
33 |
+
finally:
|
34 |
+
mcp_client.close()
|