Spaces:
Sleeping
Sleeping
Smol adaptations to avoid reloading the server
Browse files
app.py
CHANGED
@@ -2,26 +2,32 @@ import gradio as gr
|
|
2 |
import os
|
3 |
|
4 |
from mcp import StdioServerParameters
|
5 |
-
from smolagents import InferenceClientModel, CodeAgent,
|
6 |
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
mcp_client.disconnect()
|
|
|
2 |
import os
|
3 |
|
4 |
from mcp import StdioServerParameters
|
5 |
+
from smolagents import InferenceClientModel, CodeAgent, MCPClient
|
6 |
|
7 |
+
HF_MCP_URL = "https://alihmaou-mcp-tools.hf.space/gradio_api/mcp/sse"
|
8 |
|
9 |
+
mcp_client = MCPClient({"url": HF_MCP_URL})
|
10 |
+
model = InferenceClientModel(token=os.getenv("HUGGINGFACE_API_TOKEN"))
|
11 |
+
tools = mcp_client.get_tools()
|
12 |
+
agent = CodeAgent(tools=tools, model=model)
|
13 |
+
|
14 |
+
def run_agent(message, history):
|
15 |
+
return str(agent.run(message))
|
16 |
|
17 |
+
def reload_tools():
|
18 |
+
global tools, agent
|
19 |
+
tools = mcp_client.get_tools()
|
20 |
+
agent = CodeAgent(tools=tools, model=model)
|
21 |
+
return "\n".join(f"- **{t.name}**: {t.description}" for t in tools)
|
22 |
|
23 |
+
with gr.Blocks() as demo:
|
24 |
+
with gr.Row():
|
25 |
+
with gr.Column(scale=2):
|
26 |
+
chatbot = gr.ChatInterface(fn=run_agent)
|
27 |
+
with gr.Column(scale=1):
|
28 |
+
tool_list = gr.Markdown(value=reload_tools())
|
29 |
+
reload_btn = gr.Button("🔄 Recharger les outils MCP")
|
30 |
+
reload_btn.click(fn=reload_tools, outputs=tool_list)
|
31 |
|
32 |
+
demo.launch()
|
33 |
+
mcp_client.disconnect()
|
|