Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,33 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
from smolagents import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
)
|
| 32 |
-
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
from mcp.client.stdio import StdioServerParameters
|
| 4 |
+
from smolagents import CodeAgent, ToolCollection,InferenceClientModel
|
| 5 |
+
from smolagents.mcp_client import MCPClient
|
| 6 |
+
|
| 7 |
+
# define mcp server the clinet can communicate
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
mcp_client = MCPClient(
|
| 11 |
+
#{"url": "http://localhost:7860/gradio_api/mcp/sse"},
|
| 12 |
+
{"url": "https://MedHakim-MCP-Agent.hf.space/gradio_api/mcp/sse"},
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
tools = mcp_client.get_tools()
|
| 16 |
+
|
| 17 |
+
model = InferenceClientModel() # defne model to use
|
| 18 |
+
agent = CodeAgent(tools=[*tools],model=model) # create agent
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
# creating gradio interface
|
| 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 |
+
)
|
| 30 |
+
|
| 31 |
+
demo.launch(ssr_mode=False)
|
| 32 |
+
finally:
|
| 33 |
+
mcp_client.disconnect()
|