Spaces:
Sleeping
Sleeping
Ahmet Zelka commited on
fixed request implementation
Browse files
app.py
CHANGED
|
@@ -27,53 +27,54 @@ def paper_finder(topics:list, max_paper:int)-> str: #it's import to specify the
|
|
| 27 |
|
| 28 |
try:
|
| 29 |
response = requests.get(url)
|
| 30 |
-
|
| 31 |
-
# parsing element tree as text
|
| 32 |
-
root = ET.from_string(response.text)
|
| 33 |
-
|
| 34 |
-
# extract paper information
|
| 35 |
-
papers = []
|
| 36 |
-
|
| 37 |
-
# arxiv returns responses in Atom 1.0 format "https://info.arxiv.org/help/api/user-manual.html#32-the-api-response"
|
| 38 |
-
namespace = {"atom": 'http://www.w3.org/2005/Atom'}
|
| 39 |
-
|
| 40 |
-
# list of the returned Atom results
|
| 41 |
-
for entry in root.findall('atom:entry', namespace):
|
| 42 |
-
title = entry.find('atom:title', namespace).text.strip()
|
| 43 |
-
summary = entry.find('atom:summary', namespace).text.strip()
|
| 44 |
-
published = entry.find('atom:published', namespace).text.strip()[:10]
|
| 45 |
-
link = entry.find('./atom:link[@title="pdf"]', namespace)
|
| 46 |
-
if link is not None:
|
| 47 |
-
pdf_url = link.get('href')
|
| 48 |
-
else:
|
| 49 |
-
pdf_url = "No PDF link available"
|
| 50 |
-
|
| 51 |
-
# Authors of the paper
|
| 52 |
-
authors = []
|
| 53 |
-
for author in entry.findall('atom:author/atom:name', namespace):
|
| 54 |
-
authors.append(author.text.strip())
|
| 55 |
-
|
| 56 |
-
# Adding paper
|
| 57 |
-
papers.append({
|
| 58 |
-
"title": title,
|
| 59 |
-
"authors": ", ".join(authors[:3]) + ("..." if len(authors) > 3 else ""),
|
| 60 |
-
"published": published,
|
| 61 |
-
"summary": summary[:150] + "..." if len(summary) > 150 else summary,
|
| 62 |
-
"pdf_url": pdf_url
|
| 63 |
-
})
|
| 64 |
-
|
| 65 |
-
for i, paper in enumerate(papers, 1):
|
| 66 |
-
topic_results += f"{i}. **{paper['title']}**\n"
|
| 67 |
-
topic_results += f" *Authors:* {paper['authors']}\n"
|
| 68 |
-
topic_results += f" *Published:* {paper['published']}\n"
|
| 69 |
-
topic_results += f" *Summary:* {paper['summary']}\n"
|
| 70 |
-
topic_results += f" *PDF:* {paper['pdf_url']}\n\n"
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
except Exception as e:
|
| 78 |
results.append(f"\n## Error searching for {topic}: {str(e)}\n")
|
| 79 |
|
|
|
|
| 27 |
|
| 28 |
try:
|
| 29 |
response = requests.get(url)
|
| 30 |
+
response.raise_for_status()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
# parsing element tree as text
|
| 33 |
+
root = ET.from_string(response.text)
|
| 34 |
+
|
| 35 |
+
# extract paper information
|
| 36 |
+
papers = []
|
| 37 |
+
|
| 38 |
+
# arxiv returns responses in Atom 1.0 format "https://info.arxiv.org/help/api/user-manual.html#32-the-api-response"
|
| 39 |
+
namespace = {"atom": 'http://www.w3.org/2005/Atom'}
|
| 40 |
+
|
| 41 |
+
# list of the returned Atom results
|
| 42 |
+
for entry in root.findall('atom:entry', namespace):
|
| 43 |
+
title = entry.find('atom:title', namespace).text.strip()
|
| 44 |
+
summary = entry.find('atom:summary', namespace).text.strip()
|
| 45 |
+
published = entry.find('atom:published', namespace).text.strip()[:10]
|
| 46 |
+
link = entry.find('./atom:link[@title="pdf"]', namespace)
|
| 47 |
+
if link is not None:
|
| 48 |
+
pdf_url = link.get('href')
|
| 49 |
+
else:
|
| 50 |
+
pdf_url = "No PDF link available"
|
| 51 |
+
|
| 52 |
+
# Authors of the paper
|
| 53 |
+
authors = []
|
| 54 |
+
for author in entry.findall('atom:author/atom:name', namespace):
|
| 55 |
+
authors.append(author.text.strip())
|
| 56 |
+
|
| 57 |
+
# Adding paper
|
| 58 |
+
papers.append({
|
| 59 |
+
"title": title,
|
| 60 |
+
"authors": ", ".join(authors[:3]) + ("..." if len(authors) > 3 else ""),
|
| 61 |
+
"published": published,
|
| 62 |
+
"summary": summary[:150] + "..." if len(summary) > 150 else summary,
|
| 63 |
+
"pdf_url": pdf_url
|
| 64 |
+
})
|
| 65 |
+
|
| 66 |
+
# Format the results for this topic
|
| 67 |
+
topic_results = f"\n## Latest papers on {topic} ({len(papers)})\n\n"
|
| 68 |
+
|
| 69 |
+
for i, paper in enumerate(papers, 1):
|
| 70 |
+
topic_results += f"{i}. **{paper['title']}**\n"
|
| 71 |
+
topic_results += f" *Authors:* {paper['authors']}\n"
|
| 72 |
+
topic_results += f" *Published:* {paper['published']}\n"
|
| 73 |
+
topic_results += f" *Summary:* {paper['summary']}\n"
|
| 74 |
+
topic_results += f" *PDF:* {paper['pdf_url']}\n\n"
|
| 75 |
+
|
| 76 |
+
results.append(topic_results)
|
| 77 |
+
|
| 78 |
except Exception as e:
|
| 79 |
results.append(f"\n## Error searching for {topic}: {str(e)}\n")
|
| 80 |
|