Derfel2025 commited on
Commit
2eca8cb
·
1 Parent(s): f6290b9

Add application file

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from mcp.client.stdio import StdioServerParameters
3
+ from smolagents import InferenceClientModel, CodeAgent, ToolCollection
4
+ from smolagents.mcp_client import MCPClient
5
+ from dotenv import load_dotenv
6
+ import os
7
+
8
+ #print("Current working directory:", os.getcwd())
9
+ #load_dotenv(dotenv_path='./.env')
10
+
11
+ #hf_token = os.getenv("HF_TOKEN")
12
+
13
+ #print("hf_token is:" + str(hf_token))
14
+
15
+
16
+
17
+ #from huggingface_hub import login
18
+
19
+
20
+ #login(token=hf_token, new_session=False, add_to_git_credential=False)
21
+
22
+ try:
23
+ mcp_client = MCPClient(
24
+ ## Try this working example on the hub:
25
+ # {"url": "https://abidlabs-mcp-tools.hf.space/gradio_api/mcp/sse"}
26
+ {"url": "https://baon2024-gradiomcpserver2.hf.space/gradio_api/mcp/sse"}
27
+ )
28
+ tools = mcp_client.get_tools()
29
+
30
+ model = InferenceClientModel()
31
+
32
+ agent = CodeAgent(tools=[*tools], model=model)#presumingly can also add non-MCP tools under their own names??
33
+
34
+ demo = gr.ChatInterface(
35
+ fn=lambda message, history: str(agent.run(message)),
36
+ type="messages",
37
+ examples=["Prime factorization of 68"],
38
+ title="Agent with MCP Tools",
39
+ description="This is a simple agent that uses MCP tools to answer questions.",
40
+ )
41
+
42
+ demo.launch()
43
+ finally:
44
+ mcp_client.disconnect()