NLarchive commited on
Commit
1c3e3c4
·
verified ·
1 Parent(s): b059456

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+
4
+ from mcp import StdioServerParameters
5
+ from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClient, HfApiModel
6
+
7
+
8
+ try:
9
+ mcp_client = MCPClient(
10
+ {"url": "https://nlarchive-mcp-sentiment.hf.space/gradio_api/mcp/sse"} # This is the MCP Server we created in the previous section
11
+ )
12
+ tools = mcp_client.get_tools()
13
+ model = HfApiModel(provider="together", model="Qwen/Qwen2.5-Coder-32B-Instruct")
14
+ agent = CodeAgent(tools=[*tools], model=model)
15
+
16
+ demo = gr.ChatInterface(
17
+ fn=lambda message, history: str(agent.run(message)),
18
+ type="messages",
19
+ examples=["Prime factorization of 68"],
20
+ title="Agent with MCP Tools",
21
+ description="This is a simple agent that uses MCP tools to answer questions.",
22
+ )
23
+
24
+ demo.launch()
25
+ finally:
26
+ mcp_client.disconnect()