Download mcp/clinicaltrials.py from mgbam/MCP_Res: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/mgbam/MCP_Res/resolve/93e7f22c8a06d6500b8b952902a1d54af6dd3307/mcp/clinicaltrials.py
- Command line
-
hf download hf://spaces/mgbam/MCP_Res@93e7f22c8a06d6500b8b952902a1d54af6dd3307/mcp/clinicaltrials.py
-
curl -L -o clinicaltrials.py https://huggingface.co/spaces/mgbam/MCP_Res/resolve/93e7f22c8a06d6500b8b952902a1d54af6dd3307/mcp/clinicaltrials.py
1.06 kB
| # mcp/clinicaltrials.py – 403-proof CPU-only helper | |
| import httpx, asyncio, datetime | |
| from typing import List, Dict | |
| BASE = "https://clinicaltrials.gov/api/query/study_fields" | |
| UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) " | |
| "AppleWebKit/537.36 (KHTML, like Gecko) " | |
| "Chrome/124.0 Safari/537.36") # real browser UA | |
| _HEADERS = {"User-Agent": UA} | |
| async def _fetch(url: str, params: Dict) -> Dict: | |
| async with httpx.AsyncClient(timeout=20, headers=_HEADERS) as c: | |
| r = await c.get(url, params=params) | |
| # If still 4xx/5xx, return empty dict – keep app alive | |
| if r.status_code != 200: | |
| return {} | |
| return r.json() | |
| async def search_trials(term: str, max_studies: int = 10) -> List[Dict]: | |
| params = dict( | |
| expr=term, | |
| fields="NCTId,BriefTitle,Condition,InterventionName,Phase,OverallStatus,StartDate", | |
| max_rnk=max_studies, | |
| min_rnk=1, | |
| fmt="json", | |
| ) | |
| data = await _fetch(BASE, params) | |
| return data.get("StudyFieldsResponse", {}).get("StudyFields", []) | |