Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- gr_sm_agents.py +49 -0
- requirements.txt +2 -0
gr_sm_agents.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
+
# import os
|
| 3 |
+
|
| 4 |
+
# from mcp import StdioServerParameters
|
| 5 |
+
# from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClient
|
| 6 |
+
# mcp_client = MCPClient(
|
| 7 |
+
# {"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse","transport":"sse"} # This is the MCP Client we created in the previous section
|
| 8 |
+
# )
|
| 9 |
+
# tools = mcp_client.get_tools()
|
| 10 |
+
|
| 11 |
+
# model = InferenceClientModel(token=os.getenv("HF_TOKEN"))
|
| 12 |
+
# agent = CodeAgent(tools=[*tools], model=model)
|
| 13 |
+
|
| 14 |
+
# demo = gr.ChatInterface(
|
| 15 |
+
# fn=lambda message, history: str(agent.run(message)),
|
| 16 |
+
# type="messages",
|
| 17 |
+
# examples=["Prime factorization of 68"],
|
| 18 |
+
# title="Agent with MCP Tools",
|
| 19 |
+
# description="This is a simple agent that uses MCP tools to answer questions."
|
| 20 |
+
# )
|
| 21 |
+
|
| 22 |
+
# demo.launch()
|
| 23 |
+
|
| 24 |
+
import gradio as gr
|
| 25 |
+
import os
|
| 26 |
+
|
| 27 |
+
from smolagents import InferenceClientModel, CodeAgent, MCPClient
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
mcp_client = MCPClient(
|
| 32 |
+
{"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"}
|
| 33 |
+
)
|
| 34 |
+
tools = mcp_client.get_tools()
|
| 35 |
+
|
| 36 |
+
model = InferenceClientModel(token=os.getenv("HF_TOKEN"))
|
| 37 |
+
agent = CodeAgent(tools=[*tools], model=model, additional_authorized_imports=["json", "ast", "urllib", "base64"])
|
| 38 |
+
|
| 39 |
+
demo = gr.ChatInterface(
|
| 40 |
+
fn=lambda message, history: str(agent.run(message)),
|
| 41 |
+
type="messages",
|
| 42 |
+
examples=["Analyze the sentiment of the following text 'This is awesome'"],
|
| 43 |
+
title="Agent with MCP Tools",
|
| 44 |
+
description="This is a simple agent that uses MCP tools to answer questions.",
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
demo.launch()
|
| 48 |
+
finally:
|
| 49 |
+
mcp_client.disconnect()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio[mcp]
|
| 2 |
+
textblob
|