MedHakim commited on
Commit
43ff022
·
verified ·
1 Parent(s): c188351

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -32
app.py CHANGED
@@ -1,32 +1,33 @@
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://huggingface.co/spaces/MedHakim/MCP-Agent/gradio_api/mcp/sse",
10
- "transport": "sse", }
11
- )
12
- tools = mcp_client.get_tools()
13
-
14
- model = InferenceClientModel(token=os.getenv(" Hakim_inference"))
15
- agent = CodeAgent(tools=[*tools], model=model,
16
- additional_authorized_imports=["json", "ast", "urllib", "base64"])
17
-
18
- demo = gr.ChatInterface(
19
- fn=lambda message, history: str(agent.run(message)),
20
- type="messages",
21
- examples=["Analyze the sentiment of the following text 'This is awesome'"],
22
- title="Agent with MCP Tools",
23
- description="This is a simple agent that uses MCP tools to answer questions.",
24
- )
25
-
26
- demo.launch()
27
- finally:
28
- mcp_client = MCPClient(
29
- {"url": "https://huggingface.co/spaces/MedHakim/MCP-Agent/gradio_api/mcp/sse",
30
- "transport": "sse", }
31
- )
32
- mcp_client.disconnect()
 
 
1
+ import gradio as gr
2
+
3
+ from mcp.client.stdio import StdioServerParameters
4
+ from smolagents import CodeAgent, ToolCollection,InferenceClientModel
5
+ from smolagents.mcp_client import MCPClient
6
+
7
+ # define mcp server the clinet can communicate
8
+
9
+ try:
10
+ mcp_client = MCPClient(
11
+ #{"url": "http://localhost:7860/gradio_api/mcp/sse"},
12
+ {"url": "https://MedHakim-MCP-Agent.hf.space/gradio_api/mcp/sse"},
13
+ )
14
+
15
+ tools = mcp_client.get_tools()
16
+
17
+ model = InferenceClientModel() # defne model to use
18
+ agent = CodeAgent(tools=[*tools],model=model) # create agent
19
+
20
+
21
+ # creating gradio interface
22
+
23
+ demo = gr.ChatInterface(
24
+ fn=lambda message, history: str(agent.run(message)),
25
+ type="messages",
26
+ examples=["Prime factorization of 68"],
27
+ title="Agent with MCP Tools",
28
+ description="This is a simple agent that uses MCP tools to answer questions.",
29
+ )
30
+
31
+ demo.launch(ssr_mode=False)
32
+ finally:
33
+ mcp_client.disconnect()