SadiaK14 commited on
Commit
c8ba630
·
verified ·
1 Parent(s): ef1250e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -22
app.py CHANGED
@@ -105,33 +105,105 @@ from Gradio_UI import GradioUI
105
  # except Exception as e:
106
  # return f"Error searching medical datasets for '{arg1}': {str(e)}"
107
 
108
-
109
  @tool
110
  def my_custom_tool(arg1: str, arg2: int) -> str:
111
- keyword = arg1.strip().lower()
112
- limit = int(arg2)
113
-
114
- medical_terms = ["skin", "brain", "lung", "breast", "cancer", "tumor", "xray", "ct", "mri", "ultrasound", "radiology"]
115
 
116
- if not any(term in keyword for term in medical_terms):
117
- return f"No medical datasets found for '{arg1}'."
 
118
 
119
- # ✅ safe API call with fallback
 
 
 
120
  try:
121
- response = requests.get(
122
- f"https://huggingface.co/api/datasets?search={keyword}&limit={limit}",
123
- timeout=10
124
- )
125
- response.raise_for_status()
126
- datasets = response.json()
127
- except requests.exceptions.RequestException:
128
- datasets = [{"id": f"example/{keyword}-dataset-{i+1}"} for i in range(limit)]
129
-
130
- if not datasets:
131
- return f"No datasets found for '{arg1}'."
132
-
133
- results = [f"- {ds.get('id', 'Unknown')}" for ds in datasets[:limit]]
134
- return f"Medical datasets related to '{arg1}':\n" + "\n".join(results)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
 
137
  @tool
 
105
  # except Exception as e:
106
  # return f"Error searching medical datasets for '{arg1}': {str(e)}"
107
 
 
108
  @tool
109
  def my_custom_tool(arg1: str, arg2: int) -> str:
110
+ """
111
+ Search and retrieve publicly available medical datasets from Hugging Face based on any medical-related keyword.
 
 
112
 
113
+ Args:
114
+ arg1: A keyword related to medical data (e.g., 'cancer', 'diabetes', 'CT scan', 'radiology', 'dermoscopy').
115
+ arg2: The maximum number of datasets to retrieve.
116
 
117
+ Returns:
118
+ A list of dataset names matching the search query, or a message stating that no datasets were found.
119
+ If network access is restricted, simulated dataset results are returned instead.
120
+ """
121
  try:
122
+ keyword = arg1.strip().lower()
123
+ limit = int(arg2)
124
+
125
+ # Define a basic list of medically relevant terms
126
+ medical_terms = [
127
+ # Anatomy / Body Parts
128
+ "skin", "brain", "lung", "chest", "abdomen", "spine", "bone", "heart", "liver", "kidney",
129
+ "bladder", "stomach", "colon", "rectum", "esophagus", "pancreas", "breast", "ear", "eye",
130
+ "retina", "tooth", "teeth", "tongue", "jaw", "neck", "wrist", "hand", "leg", "arm", "shoulder", "pelvis",
131
+
132
+ # Diseases / Conditions
133
+ "cancer", "tumor", "stroke", "diabetes", "pneumonia", "covid", "asthma", "eczema", "melanoma",
134
+ "hypertension", "alzheimer", "parkinson", "arthritis", "scoliosis", "epilepsy", "glaucoma",
135
+ "ulcer", "hepatitis", "leukemia", "lymphoma", "tuberculosis", "anemia", "obesity", "depression",
136
+ "anxiety", "bipolar", "autism", "adhd", "ptsd", "psychosis", "schizophrenia",
137
+
138
+ # Imaging Modalities
139
+ "mri", "ct", "xray", "x-ray", "ultrasound", "pet", "fmri", "mammo", "angiography", "radiography",
140
+ "echocardiogram", "spect", "dermoscopy", "colonoscopy", "endoscopy", "biopsy", "histopathology",
141
+
142
+ # Medical Specialties
143
+ "radiology", "pathology", "oncology", "cardiology", "neurology", "dermatology", "dentistry",
144
+ "ophthalmology", "urology", "orthopedics", "gastroenterology", "pulmonology", "nephrology",
145
+ "psychiatry", "pediatrics", "geriatrics", "infectious disease",
146
+
147
+ # Symptoms / Signs
148
+ "lesion", "infection", "fever", "pain", "inflammation", "rash", "headache", "swelling",
149
+ "cough", "seizure", "dizziness", "vomiting", "diarrhea", "nausea", "fatigue", "itching",
150
+
151
+ # Common Specific Diseases
152
+ "breast cancer", "prostate cancer", "lung cancer", "skin cancer", "colon cancer",
153
+ "brain tumor", "liver cancer", "cervical cancer", "bladder cancer", "thyroid cancer",
154
+
155
+ # Procedures / Interventions
156
+ "surgery", "chemotherapy", "radiation", "transplant", "dialysis", "intubation", "stenting",
157
+ "ventilation", "vaccination", "anesthesia", "rehabilitation", "prosthetics", "orthotics",
158
+
159
+ # Lab Tests / Biomarkers
160
+ "blood test", "cbc", "glucose", "hemoglobin", "cholesterol", "biomarker", "urinalysis",
161
+ "pcr", "serology", "antibody", "antigen",
162
+
163
+ # Clinical Settings / Roles
164
+ "icu", "hospital", "emergency", "clinical notes", "nursing", "physician", "patient",
165
+ "medical record", "electronic health record", "ehr", "vitals",
166
+
167
+ # Age-based Terms
168
+ "pediatric", "neonatal", "infant", "child", "adolescent", "geriatrics", "elderly",
169
+
170
+ # Epidemiology / Public Health
171
+ "epidemiology", "prevalence", "incidence", "mortality", "public health", "health disparity",
172
+ "risk factor", "social determinant",
173
+
174
+ # Pharmacology / Medications
175
+ "drug", "medication", "pharmacology", "side effect", "adverse event", "dose", "tablet",
176
+ "vaccine", "clinical trial", "placebo"
177
+ ]
178
+
179
+ # Check if keyword is in known medical terms
180
+ if not any(term in keyword for term in medical_terms):
181
+ return f"No medical datasets found for '{arg1}'."
182
+
183
+ # Try fetching datasets from Hugging Face, fallback to mock data if blocked
184
+ try:
185
+ response = requests.get(
186
+ f"https://huggingface.co/api/datasets?search={keyword}&limit={limit}",
187
+ timeout=10
188
+ )
189
+ response.raise_for_status()
190
+ datasets = response.json()
191
+ except requests.exceptions.RequestException:
192
+ # Simulate results if network access is blocked
193
+ datasets = [{"id": f"example/{keyword}-dataset-{i+1}"} for i in range(limit)]
194
+
195
+ # Return message if no datasets found
196
+ if not datasets:
197
+ return f"No medical datasets found for '{arg1}'."
198
+
199
+ # Collect and return dataset names
200
+ results = [f"- {ds.get('id', 'Unknown')}" for ds in datasets[:limit]]
201
+ return f"Medical datasets related to '{arg1}':\n" + "\n".join(results)
202
+
203
+ except Exception as e:
204
+ return f"Error searching medical datasets for '{arg1}': {str(e)}"
205
+
206
+
207
 
208
 
209
  @tool