Spaces:
Runtime error
Runtime error
Download app.py from mdeevan/mcp-client: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/mdeevan/mcp-client/resolve/main/app.py
- Command line
-
hf download hf://spaces/mdeevan/mcp-client/app.py
-
curl -L -o app.py https://huggingface.co/spaces/mdeevan/mcp-client/resolve/main/app.py
1.39 kB
| import json | |
| import gradio as gr | |
| import os | |
| from mcp import StdioServerParameters | |
| from smolagents import InferenceClientModel, CodeAgent, ToolCollection, MCPClient | |
| with MCPClient( | |
| {"url": "https://mdeevan-mcp-sentiment.hf.space/gradio_api/mcp/sse"} | |
| ) as tools: | |
| # Tools from the remote server are available | |
| print("\n".join(f"{t.name}: {t.description}" for t in tools)) | |
| mcp_client = MCPClient( | |
| {"url": "https://mdeevan-mcp-sentiment.hf.space/gradio_api/mcp/sse"} # This is the MCP Client we created in the previous section | |
| ) | |
| tools = mcp_client.get_tools() | |
| model = InferenceClientModel(token=os.getenv("HF_TOKEN")) | |
| agent = CodeAgent(tools=[*tools], model=model) | |
| demo = gr.ChatInterface( | |
| fn=lambda message, history: str(agent.run(message)), | |
| type="messages", | |
| examples=["today weather is nice"], | |
| title="Agent with MCP Tools", | |
| description="This is a simple agent that uses MCP tools to answer questions." | |
| ) | |
| # if __name__ == "__main__": | |
| demo.launch() | |
| # Create gradio interface | |
| # demo = gr.Interface( | |
| # fn = sentiment_analysis, | |
| # inputs = gr.Textbox(placeholder="Enter trext to analyze sentiments ..."), | |
| # outputs = gr.Textbox(), | |
| # title = "Text Sentiment Analysis", | |
| # description = "Analyze the sentiment of text using TextBlob" | |
| # ) | |
| # # Launch the interface and MCP server | |
| # demo.launch(mcp_server=True) |