Spaces:
Running
Running
Updated app.py tool
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ from Gradio_UI import GradioUI
|
|
| 9 |
# Custom Tool to fetch datasets related to body parts or imaging types
|
| 10 |
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
"""
|
| 14 |
Search and retrieve publicly available medical datasets from Hugging Face based on any medical-related keyword.
|
| 15 |
|
|
@@ -18,30 +18,38 @@ def medsearch_tool(arg1: str, arg2: int) -> str:
|
|
| 18 |
arg2: The maximum number of datasets to retrieve.
|
| 19 |
|
| 20 |
Returns:
|
| 21 |
-
A
|
| 22 |
-
or
|
| 23 |
"""
|
| 24 |
try:
|
| 25 |
-
keyword = arg1.strip()
|
| 26 |
limit = int(arg2)
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
response = requests.get(
|
| 29 |
f"https://huggingface.co/api/datasets?search={keyword}&limit={limit}"
|
| 30 |
)
|
| 31 |
response.raise_for_status()
|
| 32 |
datasets = response.json()
|
| 33 |
|
| 34 |
-
if not datasets
|
| 35 |
-
return f"No medical datasets found for '{
|
| 36 |
-
|
| 37 |
-
results = []
|
| 38 |
-
for ds in datasets[:limit]:
|
| 39 |
-
dataset_id = ds.get('id', 'Unknown')
|
| 40 |
-
card_data = ds.get('cardData', {})
|
| 41 |
-
description = card_data.get('summary', '').strip() or "No description available."
|
| 42 |
-
results.append(f"- {dataset_id}: {description}")
|
| 43 |
|
| 44 |
-
|
|
|
|
| 45 |
|
| 46 |
except Exception as e:
|
| 47 |
return f"Error searching medical datasets for '{arg1}': {str(e)}"
|
|
@@ -84,7 +92,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 84 |
# Create the agent
|
| 85 |
agent = CodeAgent(
|
| 86 |
model=model,
|
| 87 |
-
tools=[final_answer, get_current_time_in_timezone,
|
| 88 |
max_steps=6,
|
| 89 |
verbosity_level=1,
|
| 90 |
grammar=None,
|
|
|
|
| 9 |
# Custom Tool to fetch datasets related to body parts or imaging types
|
| 10 |
|
| 11 |
@tool
|
| 12 |
+
def my_custom_tool(arg1: str, arg2: int) -> str:
|
| 13 |
"""
|
| 14 |
Search and retrieve publicly available medical datasets from Hugging Face based on any medical-related keyword.
|
| 15 |
|
|
|
|
| 18 |
arg2: The maximum number of datasets to retrieve.
|
| 19 |
|
| 20 |
Returns:
|
| 21 |
+
A list of dataset names matching the search query, or a message stating that no datasets were found
|
| 22 |
+
or that the keyword is not medically relevant.
|
| 23 |
"""
|
| 24 |
try:
|
| 25 |
+
keyword = arg1.strip().lower()
|
| 26 |
limit = int(arg2)
|
| 27 |
|
| 28 |
+
# ✅ Define a basic list of medically relevant terms
|
| 29 |
+
medical_terms = [
|
| 30 |
+
"skin", "brain", "cancer", "tumor", "mri", "ct", "xray", "ultrasound",
|
| 31 |
+
"diabetes", "pneumonia", "covid", "lesion", "radiology", "pathology",
|
| 32 |
+
"lung", "chest", "abdomen", "spine", "bone", "stroke", "eczema", "melanoma",
|
| 33 |
+
"eye", "retina", "dermoscopy", "cardiology", "infection", "biopsy", "tooth",
|
| 34 |
+
"toothache", "dental", "ear", "wrist", "hand", "leg", "arm", "heart"
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
# ✅ Check if the keyword looks medically relevant
|
| 38 |
+
if not any(term in keyword for term in medical_terms):
|
| 39 |
+
return f"'{arg1}' does not appear to be a medical term."
|
| 40 |
+
|
| 41 |
+
# ✅ Proceed to fetch datasets
|
| 42 |
response = requests.get(
|
| 43 |
f"https://huggingface.co/api/datasets?search={keyword}&limit={limit}"
|
| 44 |
)
|
| 45 |
response.raise_for_status()
|
| 46 |
datasets = response.json()
|
| 47 |
|
| 48 |
+
if not datasets:
|
| 49 |
+
return f"No medical datasets found for '{arg1}'."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
results = [f"- {ds.get('id', 'Unknown')}" for ds in datasets[:limit]]
|
| 52 |
+
return f"Medical datasets related to '{arg1}':\n" + "\n".join(results)
|
| 53 |
|
| 54 |
except Exception as e:
|
| 55 |
return f"Error searching medical datasets for '{arg1}': {str(e)}"
|
|
|
|
| 92 |
# Create the agent
|
| 93 |
agent = CodeAgent(
|
| 94 |
model=model,
|
| 95 |
+
tools=[final_answer, get_current_time_in_timezone, my_custom_tool], # add your tools here
|
| 96 |
max_steps=6,
|
| 97 |
verbosity_level=1,
|
| 98 |
grammar=None,
|