SadiaK14 commited on
Commit
d6d0dda
·
verified ·
1 Parent(s): 4e7a14f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -60
app.py CHANGED
@@ -116,71 +116,26 @@ def my_custom_tool(arg1: str, arg2: int) -> str:
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}",
@@ -188,15 +143,14 @@ def my_custom_tool(arg1: str, arg2: int) -> str:
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
 
@@ -206,6 +160,7 @@ def my_custom_tool(arg1: str, arg2: int) -> str:
206
 
207
 
208
 
 
209
  @tool
210
  def get_current_time_in_timezone(timezone: str) -> str:
211
  """
@@ -250,15 +205,30 @@ model = InferenceClientModel(
250
  with open("prompts.yaml", 'r') as stream:
251
  prompt_templates = yaml.safe_load(stream)
252
 
253
- # Create the agent
 
 
 
 
 
 
 
 
 
 
 
254
  agent = CodeAgent(
255
  model=model,
256
  tools=[final_answer, get_current_time_in_timezone, my_custom_tool],
257
  max_steps=6,
258
- verbosity_level=2,
259
  planning_interval=None,
260
- name=None,
261
- description=None,
 
 
 
 
262
  prompt_templates=prompt_templates
263
  )
264
 
 
116
 
117
  Returns:
118
  A list of dataset names matching the search query, or a message stating that no datasets were found.
 
119
  """
120
  try:
121
  keyword = arg1.strip().lower()
122
  limit = int(arg2)
123
 
124
+ # Define a list of medical terms
125
  medical_terms = [
 
126
  "skin", "brain", "lung", "chest", "abdomen", "spine", "bone", "heart", "liver", "kidney",
127
+ "bladder", "stomach", "colon", "rectum", "esophagus", "pancreas", "breast", "ear", "eye",
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  "radiology", "pathology", "oncology", "cardiology", "neurology", "dermatology", "dentistry",
129
  "ophthalmology", "urology", "orthopedics", "gastroenterology", "pulmonology", "nephrology",
130
  "psychiatry", "pediatrics", "geriatrics", "infectious disease",
131
+ "mri", "ct", "xray", "x-ray", "ultrasound", "pet", "fmri", "mammo", "angiography", "radiography",
132
+ "cancer", "tumor", "stroke", "diabetes", "melanoma", "eczema", "asthma", "thyroid"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  ]
134
 
 
135
  if not any(term in keyword for term in medical_terms):
136
+ return f"No medical datasets found for '{arg1}'. Please try another medical term."
137
 
138
+ # Try online query to Hugging Face
139
  try:
140
  response = requests.get(
141
  f"https://huggingface.co/api/datasets?search={keyword}&limit={limit}",
 
143
  )
144
  response.raise_for_status()
145
  datasets = response.json()
146
+ except Exception:
147
+ # Network-restricted fallback
148
  datasets = [{"id": f"example/{keyword}-dataset-{i+1}"} for i in range(limit)]
149
 
150
+ # Return formatted list
151
  if not datasets:
152
+ return f"No datasets found for '{arg1}'."
153
 
 
154
  results = [f"- {ds.get('id', 'Unknown')}" for ds in datasets[:limit]]
155
  return f"Medical datasets related to '{arg1}':\n" + "\n".join(results)
156
 
 
160
 
161
 
162
 
163
+
164
  @tool
165
  def get_current_time_in_timezone(timezone: str) -> str:
166
  """
 
205
  with open("prompts.yaml", 'r') as stream:
206
  prompt_templates = yaml.safe_load(stream)
207
 
208
+ # # Create the agent
209
+ # agent = CodeAgent(
210
+ # model=model,
211
+ # tools=[final_answer, get_current_time_in_timezone, my_custom_tool],
212
+ # max_steps=6,
213
+ # verbosity_level=2,
214
+ # planning_interval=None,
215
+ # name=None,
216
+ # description=None,
217
+ # prompt_templates=prompt_templates
218
+ # )
219
+
220
  agent = CodeAgent(
221
  model=model,
222
  tools=[final_answer, get_current_time_in_timezone, my_custom_tool],
223
  max_steps=6,
224
+ verbosity_level=1,
225
  planning_interval=None,
226
+ name="MedDataSearchAgent",
227
+ description=(
228
+ "An intelligent agent that searches Hugging Face datasets related to "
229
+ "medical conditions, body parts, and imaging modalities. "
230
+ "Use 'my_custom_tool' whenever the user requests medical data or datasets."
231
+ ),
232
  prompt_templates=prompt_templates
233
  )
234