Spaces:
Paused
Paused
Commit
·
b93bdb6
1
Parent(s):
3e154cd
Add initial implementation of sentiment analysis agent using Gradio and MCP tools
Browse files- app.py +26 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from smolagents import InferenceClientModel, CodeAgent
|
| 3 |
+
from smolagents.mcp_client import MCPClient
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
try:
|
| 7 |
+
mcp_client = MCPClient(
|
| 8 |
+
{"url": "https://serverdaun-mcp-sentiment-test.hf.space/gradio_api/mcp/sse",
|
| 9 |
+
"transport": "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=["I am very happy today"],
|
| 20 |
+
title="Agent with MCP Tools",
|
| 21 |
+
description="This is a simple agent that uses MCP tools to do sentiment analysis.",
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
demo.launch()
|
| 25 |
+
finally:
|
| 26 |
+
mcp_client.disconnect()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
smolagents[mcp]
|
| 2 |
+
mcp
|
| 3 |
+
gradio
|