niikun commited on
Commit
3a4095e
·
0 Parent(s):

initial commit

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