pdx97 commited on
Commit
34d5e78
·
verified ·
1 Parent(s): 126e17b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -3,17 +3,21 @@ import yaml
3
  import feedparser
4
  import gradio as gr
5
 
6
- @tool
 
7
  def fetch_latest_arxiv_papers(keywords: list, num_results: int = 1) -> list:
8
- """Fetches the latest research papers from arXiv based on provided keywords.
9
- Args:
10
- keywords: A list of keywords to search for relevant papers.
11
- num_results: The number of papers to fetch (default is 5).
12
- """
13
  try:
14
  print(f"DEBUG: Searching arXiv papers with keywords: {keywords}") # Debug input
15
- query = "+".join(keywords)
16
- url = f"http://export.arxiv.org/api/query?search_query=all:{query}&start=0&max_results={num_results}&sortBy=submittedDate&sortOrder=descending"
 
 
 
 
 
 
 
17
  feed = feedparser.parse(url)
18
 
19
  papers = []
@@ -28,6 +32,10 @@ def fetch_latest_arxiv_papers(keywords: list, num_results: int = 1) -> list:
28
 
29
  return papers
30
 
 
 
 
 
31
  except Exception as e:
32
  print(f"ERROR: {str(e)}") # Debug errors
33
  return [f"Error fetching research papers: {str(e)}"]
 
3
  import feedparser
4
  import gradio as gr
5
 
6
+ import urllib.parse # Import URL encoder
7
+
8
  def fetch_latest_arxiv_papers(keywords: list, num_results: int = 1) -> list:
9
+ """Fetches the latest research papers from arXiv based on provided keywords."""
 
 
 
 
10
  try:
11
  print(f"DEBUG: Searching arXiv papers with keywords: {keywords}") # Debug input
12
+
13
+ # Properly format query with +AND+ for multiple keywords
14
+ query = "+AND+".join([f"all:{kw}" for kw in keywords])
15
+ query_encoded = urllib.parse.quote(query) # Encode spaces and special characters
16
+
17
+ url = f"http://export.arxiv.org/api/query?search_query={query_encoded}&start=0&max_results={num_results}&sortBy=submittedDate&sortOrder=descending"
18
+
19
+ print(f"DEBUG: Query URL - {url}") # Debug URL
20
+
21
  feed = feedparser.parse(url)
22
 
23
  papers = []
 
32
 
33
  return papers
34
 
35
+ except Exception as e:
36
+ print(f"ERROR: {str(e)}") # Debug errors
37
+ return [f"Error fetching research papers: {str(e)}"]]
38
+
39
  except Exception as e:
40
  print(f"ERROR: {str(e)}") # Debug errors
41
  return [f"Error fetching research papers: {str(e)}"]