steveg07 commited on
Commit
9b3fb28
·
1 Parent(s): 48fac2c

Other client

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