konsgavriil commited on
Commit
ac3efa3
·
1 Parent(s): c998976

Add application file

Browse files
Files changed (2) hide show
  1. app.py +25 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from smolagents import InferenceClientModel, CodeAgent, MCPClient
4
+
5
+
6
+ try:
7
+ mcp_client = MCPClient(
8
+ {"url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse", "transport": "sse",}
9
+ )
10
+ tools = mcp_client.get_tools()
11
+
12
+ model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN"))
13
+ agent = CodeAgent(tools=[*tools], model=model, additional_authorized_imports=["json", "ast", "urllib", "base64"])
14
+
15
+ demo = gr.ChatInterface(
16
+ fn=lambda message, history: str(agent.run(message)),
17
+ type="messages",
18
+ examples=["Analyze the sentiment of the following text 'This is awesome'"],
19
+ title="Agent with MCP Tools",
20
+ description="This is a simple agent that uses MCP tools to answer questions.",
21
+ )
22
+
23
+ demo.launch()
24
+ finally:
25
+ mcp_client.disconnect()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ smolagents[mcp]