rahermur commited on
Commit
a3871b9
·
1 Parent(s): 69f3fcf

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv, find_dotenv
2
+ import gradio as gr
3
+ import os
4
+ from smolagents import InferenceClientModel, CodeAgent, MCPClient
5
+
6
+
7
+ try:
8
+ load_dotenv(find_dotenv())
9
+ mcp_client = MCPClient(
10
+ {"url": "https://rahermur-mcp-sentiment.hf.space/gradio_api/mcp/sse",
11
+ "transport": "sse"}
12
+ )
13
+ tools = mcp_client.get_tools()
14
+
15
+ model = InferenceClientModel(token=os.getenv("HF_TOKEN"))
16
+ agent = CodeAgent(tools=[*tools], model=model, 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.disconnect()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio[mcp]
2
+ smolagents[mcp]