captain-awesome commited on
Commit
6a73182
·
verified ·
1 Parent(s): dd04ca4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -1,29 +1,32 @@
1
  import gradio as gr
2
 
3
  from mcp.client.stdio import StdioServerParameters
4
- from smolagents import InferenceClientModel, CodeAgent, ToolCollection
5
  from smolagents.mcp_client import MCPClient
6
 
7
-
8
  try:
9
  mcp_client = MCPClient(
10
- ## Try this working example on the hub:
11
- # {"url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse"}
12
- {"url": "https://captain-awesome-alquranchapters.hf.space/gradio_api/mcp/sse"}
13
  )
 
14
  tools = mcp_client.get_tools()
15
 
16
  model = InferenceClientModel()
17
  agent = CodeAgent(tools=[*tools], model=model)
18
 
 
19
  demo = gr.ChatInterface(
20
  fn=lambda message, history: str(agent.run(message)),
21
- # type="messages",
22
- # examples=["Prime factorization of 68"],
23
  title="Agent with MCP Tools",
24
- description="This is a simple agent that uses MCP tools to get chapgters of Quran.",
25
  )
26
 
27
  demo.launch()
 
28
  finally:
29
- mcp_client.disconnect()
 
 
 
1
  import gradio as gr
2
 
3
  from mcp.client.stdio import StdioServerParameters
4
+ from smolagents import InferenceClientModel, CodeAgent
5
  from smolagents.mcp_client import MCPClient
6
 
7
+ # Initialize the MCP client correctly
8
  try:
9
  mcp_client = MCPClient(
10
+ server_parameters=StdioServerParameters(
11
+ url="https://captain-awesome-alquranchapters.hf.space/gradio_api/mcp/sse"
12
+ )
13
  )
14
+
15
  tools = mcp_client.get_tools()
16
 
17
  model = InferenceClientModel()
18
  agent = CodeAgent(tools=[*tools], model=model)
19
 
20
+ # Define Gradio ChatInterface
21
  demo = gr.ChatInterface(
22
  fn=lambda message, history: str(agent.run(message)),
 
 
23
  title="Agent with MCP Tools",
24
+ description="This is a simple agent that uses MCP tools to get chapters of the Quran.",
25
  )
26
 
27
  demo.launch()
28
+
29
  finally:
30
+ # Properly close the MCP client connection
31
+ if 'mcp_client' in locals():
32
+ mcp_client.disconnect()