SadiaK14 commited on
Commit
b989274
·
verified ·
1 Parent(s): d63d7cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -7,36 +7,44 @@ from tools.final_answer import FinalAnswerTool
7
  from Gradio_UI import GradioUI
8
 
9
  # Custom Tool to fetch datasets related to body parts or imaging types
 
10
  @tool
11
- def my_custom_tool(arg1: str, arg2: int) -> str:
12
  """
13
- Fetch datasets related to a medical keyword such as body parts (e.g., skin, brain) or imaging modalities (e.g., MRI, CT).
14
 
15
  Args:
16
- arg1: A medical keyword such as 'skin', 'brain', 'XRay', or 'ultrasound'.
17
- arg2: The maximum number of datasets to return.
18
 
19
  Returns:
20
- A formatted list of dataset names matching the keyword from Hugging Face.
 
21
  """
22
  try:
23
- query = arg1.lower()
24
  limit = int(arg2)
25
 
26
  response = requests.get(
27
- f"https://huggingface.co/api/datasets?search={query}&limit={limit}"
28
  )
29
  response.raise_for_status()
30
  datasets = response.json()
31
 
32
- if not datasets:
33
- return f"No datasets found for '{arg1}'."
 
 
 
 
 
 
 
34
 
35
- results = [f"- {ds.get('id', 'Unknown')}" for ds in datasets[:limit]]
36
- return f"Datasets related to '{arg1}':\n" + "\n".join(results)
37
 
38
  except Exception as e:
39
- return f"Error fetching datasets for '{arg1}': {str(e)}"
40
 
41
  @tool
42
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -76,7 +84,7 @@ with open("prompts.yaml", 'r') as stream:
76
  # Create the agent
77
  agent = CodeAgent(
78
  model=model,
79
- tools=[final_answer, get_current_time_in_timezone, my_custom_tool], # add your tools here
80
  max_steps=6,
81
  verbosity_level=1,
82
  grammar=None,
 
7
  from Gradio_UI import GradioUI
8
 
9
  # Custom Tool to fetch datasets related to body parts or imaging types
10
+
11
  @tool
12
+ def medsearch_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 formatted list of dataset names and summaries matching the search query,
22
+ or a message stating that no datasets were found.
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 or len(datasets) == 0:
35
+ return f"No medical datasets found for '{keyword}'."
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
+ return f"Medical datasets related to '{keyword}':\n" + "\n\n".join(results)
 
45
 
46
  except Exception as e:
47
+ return f"Error searching medical datasets for '{arg1}': {str(e)}"
48
 
49
  @tool
50
  def get_current_time_in_timezone(timezone: str) -> str:
 
84
  # Create the agent
85
  agent = CodeAgent(
86
  model=model,
87
+ tools=[final_answer, get_current_time_in_timezone, medsearch_tool], # add your tools here
88
  max_steps=6,
89
  verbosity_level=1,
90
  grammar=None,