AryanCodesDS commited on
Commit
4518c75
·
verified ·
1 Parent(s): d08b7fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -5,27 +5,29 @@ import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  import urllib, urllib.request
8
- import xml.etree.ElementTree as ET
9
  from Gradio_UI import GradioUI
 
10
 
11
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
  @tool
13
- def my_arxiv_tool(keyword:str, n:int)-> str: #it's import to specify the return type
14
- #Keep this format for the description / args / args description but feel free to modify the tool
15
  """A tool that returns "n" research paper links for given keyword on arXiv.
16
  Args:
17
- keyword:a keyword related to research paper.
18
  n: number of research papers.
19
  """
20
- url = f'http://export.arxiv.org/api/query?search_query=all:{keyword}&year=2002&start=0&max_results={n}'
21
  data = urllib.request.urlopen(url)
22
  xml_string = data.read().decode('utf-8')
23
-
24
- # Parse the XML string
25
- root = ET.fromstring(xml_string)
26
-
27
- # Convert the XML to a string
28
- result_string = ET.tostring(root, encoding='unicode', method='xml')
 
 
 
29
  return result_string
30
 
31
  @tool
 
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
  import urllib, urllib.request
8
+
9
  from Gradio_UI import GradioUI
10
+ import re
11
 
 
12
  @tool
13
+ def my_arxiv_tool(keyword: str, n: int) -> str:
 
14
  """A tool that returns "n" research paper links for given keyword on arXiv.
15
  Args:
16
+ keyword: a keyword related to research paper.
17
  n: number of research papers.
18
  """
19
+ url = f'http://export.arxiv.org/api/query?search_query=all:{keyword}&start=0&max_results={n}'
20
  data = urllib.request.urlopen(url)
21
  xml_string = data.read().decode('utf-8')
22
+
23
+ # Extract links using regular expressions
24
+ links = re.findall(r'<id>(http://arxiv\.org/abs/.*?)</id>', xml_string)
25
+
26
+ # Format the result as a string
27
+ result_string = f"Research paper links for keyword '{keyword}':\n\n"
28
+ for i, link in enumerate(links, 1):
29
+ result_string += f"{i}. {link}\n"
30
+
31
  return result_string
32
 
33
  @tool