khaled06 commited on
Commit
5382e09
·
verified ·
1 Parent(s): e93281f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from dotenv import load_dotenv
4
+
5
+ from mcp import StdioServerParameters
6
+ from smolagents import InferenceClientModel, CodeAgent, ToolCollection,MCPClient
7
+
8
+ try:
9
+ mcp_client = MCPClient(
10
+ {
11
+ "url": "https://abidlabs-mcp-tool-http.hf.space/gradio_api/mcp/sse"
12
+ }
13
+
14
+ )
15
+ tools = mcp_client.get_tools()
16
+ load_dotenv()
17
+ model = InferenceClientModel(token=os.getenv("HF_TOKEN"))
18
+ agent = CodeAgent(tools=[*tools], model=model)
19
+
20
+ demo = gr.ChatInterface(
21
+ fn= lambda message, history: str(agent.run(message)),
22
+ type='messages',
23
+ examples=['prime factorization of 68'],
24
+ title='agent with mcp server',
25
+ description='this is a simple agent that uses MCP tools to answer questions'
26
+ )
27
+ demo.launch()
28
+
29
+ finally:
30
+ mcp_client.disconnect()