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