Spaces:
Sleeping
Sleeping
Update app.py
Browse filesswitch to nlm db interactions
app.py
CHANGED
|
@@ -14,23 +14,24 @@ from typing import Optional, Dict, Any
|
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
| 16 |
def drug_interaction_checker(drug_1: str, drug_2: str) -> str:
|
| 17 |
-
"""Checks for potential interactions between two medications using the
|
| 18 |
|
| 19 |
Args:
|
| 20 |
drug_1: The name of the first drug.
|
| 21 |
drug_2: The name of the second drug.
|
| 22 |
"""
|
| 23 |
-
base_url = "https://
|
| 24 |
-
query = f
|
| 25 |
-
response = requests.get(f"{base_url}
|
| 26 |
|
| 27 |
if response.status_code == 200:
|
| 28 |
data = response.json()
|
| 29 |
-
if "
|
| 30 |
-
interactions = data["
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
else:
|
| 35 |
return f"❌ Error fetching interaction data: {response.status_code}"
|
| 36 |
|
|
|
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
| 16 |
def drug_interaction_checker(drug_1: str, drug_2: str) -> str:
|
| 17 |
+
"""Checks for potential interactions between two medications using the NLM Interaction API.
|
| 18 |
|
| 19 |
Args:
|
| 20 |
drug_1: The name of the first drug.
|
| 21 |
drug_2: The name of the second drug.
|
| 22 |
"""
|
| 23 |
+
base_url = "https://rxnav.nlm.nih.gov/REST/interaction/list.json"
|
| 24 |
+
query = f"?rxcuis={drug_1}+{drug_2}"
|
| 25 |
+
response = requests.get(f"{base_url}{query}")
|
| 26 |
|
| 27 |
if response.status_code == 200:
|
| 28 |
data = response.json()
|
| 29 |
+
if "fullInteractionTypeGroup" in data:
|
| 30 |
+
interactions = data["fullInteractionTypeGroup"][0]["fullInteractionType"]
|
| 31 |
+
if interactions:
|
| 32 |
+
description = interactions[0]["interactionPair"][0]["description"]
|
| 33 |
+
return f"⚠️ Drug Interaction Warning: {description}"
|
| 34 |
+
return "✅ No interaction data found for these drugs."
|
| 35 |
else:
|
| 36 |
return f"❌ Error fetching interaction data: {response.status_code}"
|
| 37 |
|