Spaces:
Sleeping
Sleeping
Commit
·
394e826
1
Parent(s):
e022303
Upload random_arxiv.py
Browse files- random_arxiv.py +46 -0
random_arxiv.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import streamlit.components.v1 as components
|
| 3 |
+
import requests
|
| 4 |
+
import random
|
| 5 |
+
from bs4 import BeautifulSoup
|
| 6 |
+
|
| 7 |
+
def display_paper(link, title, pdf_link):
|
| 8 |
+
st.title(f"Random Arxiv Paper: A randomly selected paper from Arxiv's newest published papers - {title}")
|
| 9 |
+
st.markdown(f"[Link to Paper]({link})")
|
| 10 |
+
iframe_tag = f'<iframe src="{pdf_link}" width="1100" height="1000" scrolling="yes" seamless></iframe>'
|
| 11 |
+
st.markdown(iframe_tag, unsafe_allow_html=True)
|
| 12 |
+
|
| 13 |
+
def main():
|
| 14 |
+
with st.spinner("Wait for it..."):
|
| 15 |
+
url = "https://arxiv.org/list/cs/new"
|
| 16 |
+
|
| 17 |
+
response = requests.get(url)
|
| 18 |
+
|
| 19 |
+
soup = BeautifulSoup(response.content, "html.parser")
|
| 20 |
+
|
| 21 |
+
identifier_spans = soup.find_all("span", class_="list-identifier")
|
| 22 |
+
|
| 23 |
+
links = []
|
| 24 |
+
pdfs = []
|
| 25 |
+
for span in identifier_spans:
|
| 26 |
+
link = span.find("a")["href"]
|
| 27 |
+
try:
|
| 28 |
+
pdf_link = span.find("a", title="Download PDF")["href"]
|
| 29 |
+
if link.startswith("/abs/"):
|
| 30 |
+
links.append("https://arxiv.org" + link)
|
| 31 |
+
if pdf_link.startswith("/pdf/"):
|
| 32 |
+
pdfs.append("https://arxiv.org" + pdf_link + ".pdf")
|
| 33 |
+
except:
|
| 34 |
+
continue
|
| 35 |
+
|
| 36 |
+
s = soup.find_all("div", class_="list-title mathjax")
|
| 37 |
+
titles = [t.text for t in s]
|
| 38 |
+
|
| 39 |
+
papers = list(zip(links, titles, pdfs))
|
| 40 |
+
random_paper = random.choice(papers)
|
| 41 |
+
paper_link, paper_title, paper_pdf = random_paper
|
| 42 |
+
|
| 43 |
+
display_paper(paper_link, paper_title, paper_pdf)
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
main()
|