Download scripts/test_active_learning_api.py from gitmodelmujtaba/medical-guidelines-kg: direct link, hf CLI and curl.
- Browser
- Download file 2.54 kB
-
https://huggingface.co/spaces/gitmodelmujtaba/medical-guidelines-kg/resolve/main/scripts/test_active_learning_api.py
- Command line
-
hf download hf://spaces/gitmodelmujtaba/medical-guidelines-kg/scripts/test_active_learning_api.py
-
curl -L -o test_active_learning_api.py https://huggingface.co/spaces/gitmodelmujtaba/medical-guidelines-kg/resolve/main/scripts/test_active_learning_api.py
2.54 kB
| import json | |
| import urllib.request | |
| import urllib.parse | |
| # 1. Test GET /api/active-learning/status | |
| print("1. Testing GET /api/active-learning/status...") | |
| req = urllib.request.Request("http://localhost:8088/api/active-learning/status") | |
| with urllib.request.urlopen(req, timeout=5) as resp: | |
| data = json.loads(resp.read().decode("utf-8")) | |
| print(" -> Status Response:", data) | |
| assert "total_contrastive_triplets" in data | |
| # 2. Test GET /api/standard-concepts/search?q=caesarean | |
| print("\n2. Testing GET /api/standard-concepts/search?q=caesarean...") | |
| req = urllib.request.Request("http://localhost:8088/api/standard-concepts/search?q=caesarean") | |
| with urllib.request.urlopen(req, timeout=5) as resp: | |
| data = json.loads(resp.read().decode("utf-8")) | |
| print(f" -> Found {len(data['results'])} standard concepts:") | |
| for r in data['results'][:3]: | |
| print(f" * {r['vocab']}:{r['code']} - {r['name']}") | |
| assert len(data['results']) > 0 | |
| # 3. Test POST /api/feedback/override-concept | |
| print("\n3. Testing POST /api/feedback/override-concept...") | |
| override_payload = { | |
| "guideline_id": "RCOG-GTG-45", | |
| "triplet_id": "TRIP_RCOG-GTG-45_v2_00001", | |
| "mention": "VBAC", | |
| "old_concept_id": "441097003", | |
| "old_term": "Trial of labour after caesarean delivery", | |
| "new_concept_id": "237313003", | |
| "new_term": "Vaginal delivery following previous caesarean section", | |
| "vocabulary": "SNOMED-CT", | |
| "category": "PROCEDURE", | |
| "user_id": "dr_clinical_lead", | |
| "context": "Implementation of a vaginal birth after caesarean (VBAC) protocol is recommended." | |
| } | |
| req = urllib.request.Request( | |
| "http://localhost:8088/api/feedback/override-concept", | |
| data=json.dumps(override_payload).encode("utf-8"), | |
| headers={"Content-Type": "application/json"} | |
| ) | |
| with urllib.request.urlopen(req, timeout=5) as resp: | |
| res = json.loads(resp.read().decode("utf-8")) | |
| print(" -> Override Response:", res) | |
| assert res["status"] == "SUCCESS" | |
| # 4. Test POST /api/active-learning/retrain | |
| print("\n4. Testing POST /api/active-learning/retrain...") | |
| retrain_payload = {"epochs": 3} | |
| req = urllib.request.Request( | |
| "http://localhost:8088/api/active-learning/retrain", | |
| data=json.dumps(retrain_payload).encode("utf-8"), | |
| headers={"Content-Type": "application/json"} | |
| ) | |
| with urllib.request.urlopen(req, timeout=5) as resp: | |
| res = json.loads(resp.read().decode("utf-8")) | |
| print(" -> Retrain Response:", res) | |
| assert res["status"] in ["COMPLETED", "SUCCESS"] | |
| print("\nALL API ENDPOINTS FUNCTIONING PERFECTLY!") | |