Spaces:
Running on Zero
Running on Zero
Upload community_contributions/Ayesha/scanner_agent.py with huggingface_hub
Browse files
community_contributions/Ayesha/scanner_agent.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import xml.etree.ElementTree as ET
|
| 3 |
+
from dataclasses import dataclass
|
| 4 |
+
from typing import List
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
ARXIV_API = "http://export.arxiv.org/api/query?search_query=cat:cs.AI&start=0&max_results=20"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
@dataclass
|
| 11 |
+
class Paper:
|
| 12 |
+
title: str
|
| 13 |
+
summary: str
|
| 14 |
+
url: str
|
| 15 |
+
def describe(self):
|
| 16 |
+
return f"""
|
| 17 |
+
Title: {self.title}
|
| 18 |
+
|
| 19 |
+
Summary: {self.summary}
|
| 20 |
+
|
| 21 |
+
URL: {self.url}
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def fetch_papers() -> List[Paper]:
|
| 26 |
+
r = requests.get(ARXIV_API)
|
| 27 |
+
|
| 28 |
+
root = ET.fromstring(r.text)
|
| 29 |
+
|
| 30 |
+
papers = []
|
| 31 |
+
|
| 32 |
+
for entry in root:
|
| 33 |
+
|
| 34 |
+
if entry.tag.endswith("entry"):
|
| 35 |
+
|
| 36 |
+
title = ""
|
| 37 |
+
summary = ""
|
| 38 |
+
link = ""
|
| 39 |
+
|
| 40 |
+
for child in entry:
|
| 41 |
+
|
| 42 |
+
if child.tag.endswith("title"):
|
| 43 |
+
title = child.text or ""
|
| 44 |
+
|
| 45 |
+
elif child.tag.endswith("summary"):
|
| 46 |
+
summary = child.text or ""
|
| 47 |
+
|
| 48 |
+
elif child.tag.endswith("id"):
|
| 49 |
+
link = child.text or ""
|
| 50 |
+
|
| 51 |
+
papers.append(
|
| 52 |
+
Paper(
|
| 53 |
+
title=title.strip(),
|
| 54 |
+
summary=summary.strip(),
|
| 55 |
+
url=link.strip(),
|
| 56 |
+
)
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
# print("Fetched papers:", len(papers))
|
| 60 |
+
# print("Entry tag:", entry.tag)
|
| 61 |
+
|
| 62 |
+
return papers
|