Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 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:
|
| 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}&
|
| 21 |
data = urllib.request.urlopen(url)
|
| 22 |
xml_string = data.read().decode('utf-8')
|
| 23 |
-
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
#
|
| 28 |
-
result_string =
|
|
|
|
|
|
|
|
|
|
| 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
|