kmille50 commited on
Commit
4219351
·
verified ·
1 Parent(s): d88f5d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -16
app.py CHANGED
@@ -9,29 +9,52 @@ from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
  """A tool that does nothing yet
15
  Args:
16
  arg1: the first argument
17
  arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- @tool
22
- def get_current_time_in_timezone(timezone: str) -> str:
23
- """A tool that fetches the current local time in a specified timezone.
24
- Args:
25
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
26
- """
27
- try:
28
- # Create timezone object
29
- tz = pytz.timezone(timezone)
30
- # Get current time in that timezone
31
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
- return f"The current local time in {timezone} is: {local_time}"
33
- except Exception as e:
34
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
 
37
  final_answer = FinalAnswerTool()
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def pubmed_search_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
  #Keep this format for the description / args / args description but feel free to modify the tool
14
  """A tool that does nothing yet
15
  Args:
16
  arg1: the first argument
17
  arg2: the second argument
18
  """
19
+ base_url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi"
20
+ params = {
21
+ "db": "pubmed",
22
+ "term": query, # Terme de recherche (ex: "diabetes treatment")
23
+ "retmax": 5, # Nombre maximum de résultats
24
+ "retmode": "xml" # Format XML pour récupérer les résultats
25
+ }
26
+
27
+ response = requests.get(base_url, params=params)
28
+
29
+ if response.status_code != 200:
30
+ return "Erreur lors de la recherche sur PubMed."
31
 
32
+ # Parser la réponse XML pour extraire les IDs des articles
33
+ root = ElementTree.fromstring(response.content)
34
+ article_ids = [id_elem.text for id_elem in root.findall(".//Id")]
35
+
36
+ if not article_ids:
37
+ return "Aucun article trouvé pour cette requête."
38
+
39
+ # Construire les liens vers PubMed
40
+ pubmed_links = [f"https://pubmed.ncbi.nlm.nih.gov/{article_id}/" for article_id in article_ids]
41
+
42
+ return "\n".join(pubmed_links)
43
+
44
+ # @tool
45
+ # def get_current_time_in_timezone(timezone: str) -> str:
46
+ # """A tool that fetches the current local time in a specified timezone.
47
+ # Args:
48
+ # timezone: A string representing a valid timezone (e.g., 'America/New_York').
49
+ # """
50
+ # try:
51
+ # # Create timezone object
52
+ # tz = pytz.timezone(timezone)
53
+ # # Get current time in that timezone
54
+ # local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
55
+ # return f"The current local time in {timezone} is: {local_time}"
56
+ # except Exception as e:
57
+ # return f"Error fetching time for timezone '{timezone}': {str(e)}"
58
 
59
 
60
  final_answer = FinalAnswerTool()