Download mcp/umls_rel.py from mgbam/MCP_Res: direct link, hf CLI and curl.
- Browser
- Download file 832 Bytes
-
https://huggingface.co/spaces/mgbam/MCP_Res/resolve/1f7d1c0d89b17a6183262c4cefdae7ac182f97fd/mcp/umls_rel.py
- Command line
-
hf download hf://spaces/mgbam/MCP_Res@1f7d1c0d89b17a6183262c4cefdae7ac182f97fd/mcp/umls_rel.py
-
curl -L -o umls_rel.py https://huggingface.co/spaces/mgbam/MCP_Res/resolve/1f7d1c0d89b17a6183262c4cefdae7ac182f97fd/mcp/umls_rel.py
832 Bytes
| # mcp/umls_rel.py | |
| import os, httpx | |
| from functools import lru_cache | |
| UMLS_API_KEY = os.getenv("UMLS_KEY") | |
| REL_URL = "https://uts-ws.nlm.nih.gov/rest/content/current/CUI/{cui}/relations" | |
| async def _get_ticket() -> str: | |
| from mcp.umls import _get_ticket as fn | |
| return await fn() | |
| async def fetch_relations(cui: str) -> list[dict]: | |
| ticket = await _get_ticket() | |
| params = {"ticket": ticket, "pageSize": 50} | |
| async with httpx.AsyncClient(timeout=10) as c: | |
| r = await c.get(REL_URL.format(cui=cui), params=params) | |
| r.raise_for_status() | |
| rels = r.json().get("result", {}).get("relation", []) | |
| return [ | |
| {"label": rel["relationLabel"], | |
| "cui2": rel["relatedId"], | |
| "name2": rel["relatedLabel"]} | |
| for rel in rels | |
| ] | |