Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,51 @@ from Gradio_UI import GradioUI
|
|
| 8 |
|
| 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 |
"""
|
|
@@ -18,36 +63,58 @@ def my_custom_tool(arg1: str, arg2: int) -> str:
|
|
| 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 |
-
#
|
| 29 |
medical_terms = [
|
| 30 |
-
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
]
|
| 36 |
|
| 37 |
-
|
|
|
|
| 38 |
if not any(term in keyword for term in medical_terms):
|
| 39 |
-
return f"'{arg1}'
|
| 40 |
|
| 41 |
-
#
|
| 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 |
|
|
|
|
| 8 |
|
| 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 |
+
|
| 16 |
+
# Args:
|
| 17 |
+
# arg1: A keyword related to medical data (e.g., 'cancer', 'diabetes', 'CT scan', 'radiology', 'dermoscopy').
|
| 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", "breast cancer", "prostate cancer", "stomach", "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)}"
|
| 56 |
@tool
|
| 57 |
def my_custom_tool(arg1: str, arg2: int) -> str:
|
| 58 |
"""
|
|
|
|
| 63 |
arg2: The maximum number of datasets to retrieve.
|
| 64 |
|
| 65 |
Returns:
|
| 66 |
+
A list of dataset names matching the search query, or a message stating that no datasets were found.
|
|
|
|
| 67 |
"""
|
| 68 |
try:
|
| 69 |
keyword = arg1.strip().lower()
|
| 70 |
limit = int(arg2)
|
| 71 |
|
| 72 |
+
# Define a basic list of medically relevant terms
|
| 73 |
medical_terms = [
|
| 74 |
+
# Anatomy / Body Parts
|
| 75 |
+
"skin", "brain", "lung", "chest", "abdomen", "spine", "bone", "heart", "liver", "kidney",
|
| 76 |
+
"bladder", "stomach", "colon", "rectum", "esophagus", "pancreas", "breast", "ear", "eye",
|
| 77 |
+
"retina", "tooth", "tongue", "jaw", "neck", "wrist", "hand", "leg", "arm", "shoulder", "pelvis",
|
| 78 |
+
|
| 79 |
+
# Diseases / Conditions
|
| 80 |
+
"cancer", "tumor", "stroke", "diabetes", "pneumonia", "covid", "asthma", "eczema", "melanoma",
|
| 81 |
+
"hypertension", "alzheimer", "parkinson", "arthritis", "scoliosis", "epilepsy", "glaucoma",
|
| 82 |
+
"ulcer", "hepatitis", "leukemia", "lymphoma", "tuberculosis", "anemia", "obesity", "depression",
|
| 83 |
+
|
| 84 |
+
# Imaging Modalities
|
| 85 |
+
"mri", "ct", "xray", "x-ray", "ultrasound", "pet", "fmri", "mammo", "angiography", "radiography",
|
| 86 |
+
"echocardiogram", "spect", "dermoscopy", "colonoscopy", "endoscopy", "biopsy", "histopathology",
|
| 87 |
+
|
| 88 |
+
# Medical Specialties
|
| 89 |
+
"radiology", "pathology", "oncology", "cardiology", "neurology", "dermatology", "dentistry",
|
| 90 |
+
"ophthalmology", "urology", "orthopedics", "gastroenterology", "pulmonology", "nephrology",
|
| 91 |
+
|
| 92 |
+
# Symptoms / Signs
|
| 93 |
+
"lesion", "infection", "fever", "pain", "inflammation", "rash", "headache", "swelling",
|
| 94 |
+
"cough", "seizure", "dizziness", "vomiting", "diarrhea", "nausea", "fatigue", "itching",
|
| 95 |
+
|
| 96 |
+
# Common Specific Diseases
|
| 97 |
+
"breast cancer", "prostate cancer", "lung cancer", "skin cancer", "colon cancer",
|
| 98 |
+
"brain tumor", "liver cancer", "cervical cancer", "bladder cancer", "thyroid cancer"
|
| 99 |
]
|
| 100 |
|
| 101 |
+
|
| 102 |
+
# Check if keyword is in known medical terms
|
| 103 |
if not any(term in keyword for term in medical_terms):
|
| 104 |
+
return f"No medical datasets found for '{arg1}'."
|
| 105 |
|
| 106 |
+
# Fetch datasets from Hugging Face
|
| 107 |
response = requests.get(
|
| 108 |
f"https://huggingface.co/api/datasets?search={keyword}&limit={limit}"
|
| 109 |
)
|
| 110 |
response.raise_for_status()
|
| 111 |
datasets = response.json()
|
| 112 |
|
| 113 |
+
# Return message if no datasets found
|
| 114 |
if not datasets:
|
| 115 |
return f"No medical datasets found for '{arg1}'."
|
| 116 |
|
| 117 |
+
# Collect and return dataset names
|
| 118 |
results = [f"- {ds.get('id', 'Unknown')}" for ds in datasets[:limit]]
|
| 119 |
return f"Medical datasets related to '{arg1}':\n" + "\n".join(results)
|
| 120 |
|