ecyht2 commited on
Commit
d3800cc
·
verified ·
1 Parent(s): 1970d4d

Upload gradio-client.py

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