Spaces:
Runtime error
Runtime error
Initial commit
Browse files- .gitignore +1 -0
- app.py +28 -0
- requirements.txt +2 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
venv
|
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
from mcp import StdioServerParameters
|
| 5 |
+
from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClient
|
| 6 |
+
|
| 7 |
+
mcp_client = None
|
| 8 |
+
try:
|
| 9 |
+
mcp_client = MCPClient(
|
| 10 |
+
{"url": "http://localhost:7860/gradio_api/mcp/sse"} # This is the MCP Server we created in the previous section
|
| 11 |
+
)
|
| 12 |
+
tools = mcp_client.get_tools()
|
| 13 |
+
|
| 14 |
+
model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN"))
|
| 15 |
+
agent = CodeAgent(tools=[*tools], model=model)
|
| 16 |
+
|
| 17 |
+
demo = gr.ChatInterface(
|
| 18 |
+
fn=lambda message, history: str(agent.run(message)),
|
| 19 |
+
type="messages",
|
| 20 |
+
examples=["I'm feeling great!"],
|
| 21 |
+
title="Sentiment Analysis Chat",
|
| 22 |
+
description="This is a simple agent that uses MCP tools to answer questions.",
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
demo.launch()
|
| 26 |
+
finally:
|
| 27 |
+
if(mcp_client != None):
|
| 28 |
+
mcp_client.disconnect()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio[mcp]
|
| 2 |
+
smolagents[mcp]
|