SadiaK14 commited on
Commit
0979a61
·
verified ·
1 Parent(s): 15c7a33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -6
app.py CHANGED
@@ -255,21 +255,76 @@ def my_custom_tool(arg1: str, arg2: int) -> str:
255
  arg2: The maximum number of datasets to retrieve.
256
 
257
  Returns:
258
- A list of dataset names matching the search query, or a message stating that no datasets were found.
259
  """
260
  try:
261
  keyword = arg1.strip().lower()
262
  limit = int(arg2)
263
 
 
264
  medical_terms = [
265
- "skin", "brain", "lung", "chest", "abdomen", "spine", "bone", "heart", "liver",
266
- "radiology", "pathology", "oncology", "dermatology", "mri", "ct", "xray", "ultrasound",
267
- "cancer", "tumor", "melanoma", "eczema", "thyroid"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  ]
269
 
 
270
  if not any(term in keyword for term in medical_terms):
271
  return f"No medical datasets found for '{arg1}'. Please try another medical term."
272
 
 
273
  try:
274
  response = requests.get(
275
  f"https://huggingface.co/api/datasets?search={keyword}&limit={limit}",
@@ -278,13 +333,17 @@ def my_custom_tool(arg1: str, arg2: int) -> str:
278
  response.raise_for_status()
279
  datasets = response.json()
280
  except Exception:
 
281
  datasets = [{"id": f"example/{keyword}-dataset-{i+1}"} for i in range(limit)]
282
 
283
  if not datasets:
284
  return f"No datasets found for '{arg1}'."
285
 
286
- results = [f"- {ds.get('id', 'Unknown')}" for ds in datasets[:limit]]
287
- return f"Medical datasets related to '{arg1}':\n" + "\n".join(results)
 
 
 
288
 
289
  except Exception as e:
290
  return f"Error searching medical datasets for '{arg1}': {str(e)}"
 
255
  arg2: The maximum number of datasets to retrieve.
256
 
257
  Returns:
258
+ A numbered list (top N) of dataset names matching the search query.
259
  """
260
  try:
261
  keyword = arg1.strip().lower()
262
  limit = int(arg2)
263
 
264
+ # Define a comprehensive list of medically relevant terms
265
  medical_terms = [
266
+ # Anatomy / Body Parts
267
+ "skin", "brain", "lung", "chest", "abdomen", "spine", "bone", "heart", "liver", "kidney",
268
+ "bladder", "stomach", "colon", "rectum", "esophagus", "pancreas", "breast", "ear", "eye",
269
+ "retina", "tooth", "teeth", "tongue", "jaw", "neck", "wrist", "hand", "leg", "arm",
270
+ "shoulder", "pelvis",
271
+
272
+ # Diseases / Conditions
273
+ "cancer", "tumor", "stroke", "diabetes", "pneumonia", "covid", "asthma", "eczema",
274
+ "melanoma", "hypertension", "alzheimer", "parkinson", "arthritis", "scoliosis",
275
+ "epilepsy", "glaucoma", "ulcer", "hepatitis", "leukemia", "lymphoma", "tuberculosis",
276
+ "anemia", "obesity", "depression", "anxiety", "bipolar", "autism", "adhd", "ptsd",
277
+ "psychosis", "schizophrenia",
278
+
279
+ # Imaging Modalities
280
+ "mri", "ct", "xray", "x-ray", "ultrasound", "pet", "fmri", "mammo", "angiography",
281
+ "radiography", "echocardiogram", "spect", "dermoscopy", "colonoscopy", "endoscopy",
282
+ "biopsy", "histopathology",
283
+
284
+ # Medical Specialties
285
+ "radiology", "pathology", "oncology", "cardiology", "neurology", "dermatology",
286
+ "dentistry", "ophthalmology", "urology", "orthopedics", "gastroenterology",
287
+ "pulmonology", "nephrology", "psychiatry", "pediatrics", "geriatrics",
288
+ "infectious disease",
289
+
290
+ # Symptoms / Signs
291
+ "lesion", "infection", "fever", "pain", "inflammation", "rash", "headache", "swelling",
292
+ "cough", "seizure", "dizziness", "vomiting", "diarrhea", "nausea", "fatigue", "itching",
293
+
294
+ # Common Specific Diseases
295
+ "breast cancer", "prostate cancer", "lung cancer", "skin cancer", "colon cancer",
296
+ "brain tumor", "liver cancer", "cervical cancer", "bladder cancer", "thyroid cancer",
297
+
298
+ # Procedures / Interventions
299
+ "surgery", "chemotherapy", "radiation", "transplant", "dialysis", "intubation",
300
+ "stenting", "ventilation", "vaccination", "anesthesia", "rehabilitation", "prosthetics",
301
+ "orthotics",
302
+
303
+ # Lab Tests / Biomarkers
304
+ "blood test", "cbc", "glucose", "hemoglobin", "cholesterol", "biomarker", "urinalysis",
305
+ "pcr", "serology", "antibody", "antigen",
306
+
307
+ # Clinical Settings / Roles
308
+ "icu", "hospital", "emergency", "clinical notes", "nursing", "physician", "patient",
309
+ "medical record", "electronic health record", "ehr", "vitals",
310
+
311
+ # Age-based Terms
312
+ "pediatric", "neonatal", "infant", "child", "adolescent", "geriatrics", "elderly",
313
+
314
+ # Epidemiology / Public Health
315
+ "epidemiology", "prevalence", "incidence", "mortality", "public health", "health disparity",
316
+ "risk factor", "social determinant",
317
+
318
+ # Pharmacology / Medications
319
+ "drug", "medication", "pharmacology", "side effect", "adverse event", "dose", "tablet",
320
+ "vaccine", "clinical trial", "placebo"
321
  ]
322
 
323
+
324
  if not any(term in keyword for term in medical_terms):
325
  return f"No medical datasets found for '{arg1}'. Please try another medical term."
326
 
327
+ # Query Hugging Face API
328
  try:
329
  response = requests.get(
330
  f"https://huggingface.co/api/datasets?search={keyword}&limit={limit}",
 
333
  response.raise_for_status()
334
  datasets = response.json()
335
  except Exception:
336
+ # Offline fallback
337
  datasets = [{"id": f"example/{keyword}-dataset-{i+1}"} for i in range(limit)]
338
 
339
  if not datasets:
340
  return f"No datasets found for '{arg1}'."
341
 
342
+ # Format results neatly with numbered bullets
343
+ formatted = "\n".join(
344
+ [f"- Dataset {i+1}: {ds.get('id', 'Unknown')}" for i, ds in enumerate(datasets[:limit])]
345
+ )
346
+ return f"Medical datasets related to '{arg1}':\n{formatted}"
347
 
348
  except Exception as e:
349
  return f"Error searching medical datasets for '{arg1}': {str(e)}"