| """ | |
| Use Gradio as a MCP Client to connect to the BioMedNorm MCP server. | |
| Follows the MCP course docs: https://huggingface.co/learn/mcp-course/en/unit2/gradio-client | |
| """ | |
| import gradio as gr | |
| import os | |
| from smolagents import InferenceClientModel, CodeAgent, MCPClient | |
| mcp_client = None | |
| try: | |
| mcp_client = MCPClient( | |
| { | |
| "url": "https://agents-mcp-hackathon-biomednorm-mcp-server.hf.space/gradio_api/mcp/sse" | |
| } | |
| ) | |
| tools = mcp_client.get_tools() | |
| model = InferenceClientModel(provider="nebius", token=os.getenv("HF_TOKEN")) | |
| agent = CodeAgent(tools=[*tools], model=model) | |
| demo = gr.ChatInterface( | |
| fn=lambda message, history: str(agent.run(message)), | |
| type="messages", | |
| title="BioMed Normalization Agent", | |
| description="I can extract and standardize entities from biomedical text. Try me out!!!", | |
| ) | |
| demo.launch() | |
| finally: | |
| if mcp_client is not None: | |
| mcp_client.disconnect() | |