Spaces:
Runtime error
Runtime error
EliottZemour
commited on
Commit
β’
63135a7
1
Parent(s):
40fec15
test html env
Browse files- README.md +2 -2
- app.py +219 -0
- arxiv_util.py +54 -0
- get_paperinfo_fromurls.py +22 -0
- htmlcard.html +40 -0
- icml.txt +1 -0
- requirements.txt +4 -0
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
emoji: π
|
4 |
colorFrom: red
|
5 |
colorTo: yellow
|
@@ -9,4 +9,4 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
|
|
|
1 |
---
|
2 |
+
title: arXiv cards
|
3 |
emoji: π
|
4 |
colorFrom: red
|
5 |
colorTo: yellow
|
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
arXiv card generator for easily sharing scientific papers on websites and presentations
|
app.py
ADDED
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
3 |
+
from get_paperinfo_fromurls import get_paperinfo_fromurls
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
class CARDS_TEMPLATE(object):
|
7 |
+
def __init__(self, path_to_template, template_filename):
|
8 |
+
self.path_to_template = path_to_template
|
9 |
+
self.template_filename = template_filename
|
10 |
+
self.template = self._get_template()
|
11 |
+
self.rendered_html = None
|
12 |
+
|
13 |
+
def _get_template(self):
|
14 |
+
env = Environment(
|
15 |
+
autoescape=select_autoescape(
|
16 |
+
enabled_extensions=('html'),
|
17 |
+
default_for_string=True,
|
18 |
+
),
|
19 |
+
loader=FileSystemLoader(self.path_to_template)
|
20 |
+
)
|
21 |
+
return env.get_template(self.template_filename)
|
22 |
+
|
23 |
+
def render(self, paper_details_iterator):
|
24 |
+
self.rendered_html = self.template.render(paper_details=paper_details_iterator)
|
25 |
+
|
26 |
+
def save_html(self, output_dir=None, output_htmlfile=None):
|
27 |
+
with open(os.path.join(output_dir, output_htmlfile), "w") as f:
|
28 |
+
f.write(self.rendered_html)
|
29 |
+
|
30 |
+
# template_file = "htmlcard.html"
|
31 |
+
# template_path = ""
|
32 |
+
# card_template = CARDS_TEMPLATE(
|
33 |
+
# path_to_template = template_path,
|
34 |
+
# template_filename = template_file,
|
35 |
+
# )
|
36 |
+
|
37 |
+
|
38 |
+
# paper_details = get_paperinfo_fromurls("icml.txt")
|
39 |
+
# card_template.render(paper_details_iterator=paper_details)
|
40 |
+
|
41 |
+
html = """<head>
|
42 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
43 |
+
|
44 |
+
<style>
|
45 |
+
@import url("https://fonts.googleapis.com/css?family=Merriweather|Open+Sans");
|
46 |
+
|
47 |
+
.container {
|
48 |
+
display: flex;
|
49 |
+
justify-content: center;
|
50 |
+
padding: 80px;
|
51 |
+
}
|
52 |
+
|
53 |
+
ul {
|
54 |
+
list-style-type: none;
|
55 |
+
display: flex;
|
56 |
+
float: none;
|
57 |
+
justify-content: center;
|
58 |
+
align-items: center;
|
59 |
+
}
|
60 |
+
|
61 |
+
#urllinks li {
|
62 |
+
padding: 0px 30px 5px 5px;
|
63 |
+
}
|
64 |
+
|
65 |
+
.square {
|
66 |
+
width: 700px;
|
67 |
+
background: white;
|
68 |
+
border-radius: 4px;
|
69 |
+
box-shadow: 0px 20px 50px #d9dbdf;
|
70 |
+
}
|
71 |
+
|
72 |
+
.mask {
|
73 |
+
width: 700px;
|
74 |
+
height: 65px;
|
75 |
+
clip: rect(0px, 700px, 150px, 0px);
|
76 |
+
border-radius: 4px;
|
77 |
+
position: absolute;
|
78 |
+
background-color: #b31b1b;
|
79 |
+
display: flex;
|
80 |
+
}
|
81 |
+
|
82 |
+
.mask .left,
|
83 |
+
.mask .right {
|
84 |
+
flex: 1;
|
85 |
+
}
|
86 |
+
|
87 |
+
img {
|
88 |
+
position: absolute;
|
89 |
+
width: 60px;
|
90 |
+
padding: 20px 30px;
|
91 |
+
}
|
92 |
+
|
93 |
+
.h1 {
|
94 |
+
margin: auto;
|
95 |
+
text-align: left;
|
96 |
+
margin-top: 90px;
|
97 |
+
padding-left: 30px;
|
98 |
+
font-family: "Merriweather", serif;
|
99 |
+
font-size: 22px;
|
100 |
+
}
|
101 |
+
|
102 |
+
h2 {
|
103 |
+
color: white;
|
104 |
+
text-align: center;
|
105 |
+
font-size: 14px;
|
106 |
+
padding: 10px 0px;
|
107 |
+
font-family: "Open Sans", sans-serif;
|
108 |
+
font-weight: 400;
|
109 |
+
}
|
110 |
+
|
111 |
+
p {
|
112 |
+
text-align: justify;
|
113 |
+
padding-left: 30px;
|
114 |
+
padding-right: 30px;
|
115 |
+
font-family: "Open Sans", sans-serif;
|
116 |
+
font-size: 12px;
|
117 |
+
color: #949494;
|
118 |
+
line-height: 18px;
|
119 |
+
}
|
120 |
+
|
121 |
+
.auth {
|
122 |
+
text-align: justify;
|
123 |
+
padding-left: 0px;
|
124 |
+
padding-right: 20px;
|
125 |
+
font-family: "Open Sans", sans-serif;
|
126 |
+
font-size: 14px;
|
127 |
+
line-height: 18px;
|
128 |
+
}
|
129 |
+
|
130 |
+
.button {
|
131 |
+
background-color: #b31b1b;
|
132 |
+
color: white;
|
133 |
+
width: 150px;
|
134 |
+
padding: 10px 10px;
|
135 |
+
border-radius: 3px;
|
136 |
+
text-align: center;
|
137 |
+
text-decoration: none;
|
138 |
+
display: block;
|
139 |
+
margin-top: 20px;
|
140 |
+
margin-left: 20px;
|
141 |
+
margin-right: 20px;
|
142 |
+
font-size: 12px;
|
143 |
+
cursor: pointer;
|
144 |
+
font-family: "merriweather";
|
145 |
+
}
|
146 |
+
|
147 |
+
</style>
|
148 |
+
|
149 |
+
|
150 |
+
</head>
|
151 |
+
|
152 |
+
<body>
|
153 |
+
|
154 |
+
<div class="container">
|
155 |
+
<div class="square">
|
156 |
+
<div class="mask">
|
157 |
+
<h2 class="left">
|
158 |
+
<img src="https://static.arxiv.org/static/browse/0.3.4/images/arxiv-logo-one-color-white.svg" alt="arxiv logo">
|
159 |
+
</h2>
|
160 |
+
<h2 class="right">http://arxiv.org/abs/2208.14178v1</h2>
|
161 |
+
</div>
|
162 |
+
<div class="h1">Observational Signatures of Galactic Turbulent Dynamos</div>
|
163 |
+
<ul id="links">
|
164 |
+
|
165 |
+
<li><div class="auth">Yann Carteret</div></li>
|
166 |
+
|
167 |
+
<li><div class="auth">Abhijit B. Bendre</div></li>
|
168 |
+
|
169 |
+
<li><div class="auth">Jennifer Schober</div></li>
|
170 |
+
|
171 |
+
</ul>
|
172 |
+
<p>We analyse the observational signatures of galactic magnetic fields that are
|
173 |
+
self-consistently generated in magnetohydrodynamic simulations of the
|
174 |
+
interstellar medium through turbulence driven by supernova (SN) explosions and
|
175 |
+
differential rotation. In particular, we study the time evolution of the
|
176 |
+
Faraday rotation measure (RM), synchrotron radiation, and Stokes parameters by
|
177 |
+
characterising the typical structures formed in the plane of observation. We do
|
178 |
+
this by defining two distinct models for both thermal and cosmic ray (CR)
|
179 |
+
electron distributions. Our results indicate that the maps of RM have
|
180 |
+
structures which are sheared and rendered anisotropically by differential
|
181 |
+
rotation and that they depend on the choice of thermal electrons model as well
|
182 |
+
as the SN rate. Synchrotron maps are qualitatively similar to the maps of the
|
183 |
+
mean magnetic field along the line of sight and structures are only marginally
|
184 |
+
affected by the CR model. Stokes parameters and related quantities, such as the
|
185 |
+
degree of linear polarisation, are highly dependent on both frequency and
|
186 |
+
resolution of the observation.</p>
|
187 |
+
|
188 |
+
<!-- <ul id="urllinks">
|
189 |
+
<li>
|
190 |
+
<a href="http://arxiv.org/pdf/2208.14178v1" target="_" class="button">Article</a>
|
191 |
+
</li>
|
192 |
+
<li>
|
193 |
+
<a href="http://arxiv.org/abs/2208.14178v1" target="_" class="button">Abstract</a>
|
194 |
+
</li>
|
195 |
+
</ul> -->
|
196 |
+
</div>
|
197 |
+
</div>
|
198 |
+
|
199 |
+
</body>"""
|
200 |
+
|
201 |
+
def text_analysis(text):
|
202 |
+
return html
|
203 |
+
|
204 |
+
demo = gr.Blocks()
|
205 |
+
with demo:
|
206 |
+
with gr.Row():
|
207 |
+
text = gr.inputs.Textbox()
|
208 |
+
with gr.Row():
|
209 |
+
button = gr.Button("Generate reviews !")
|
210 |
+
with gr.Row():
|
211 |
+
card = gr.HTML()
|
212 |
+
|
213 |
+
button.click(
|
214 |
+
fn=text_analysis,
|
215 |
+
inputs=[text],
|
216 |
+
outputs=[card]
|
217 |
+
)
|
218 |
+
|
219 |
+
demo.launch()
|
arxiv_util.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from collections import namedtuple # later use py3.7 dataclasses
|
2 |
+
import urllib
|
3 |
+
import feedparser
|
4 |
+
import pdb
|
5 |
+
|
6 |
+
ArxivPaper = namedtuple("ArxivPaper", ["title", "authors", "abstract", "linktopdf", "linktoabs"])
|
7 |
+
|
8 |
+
def arxiv_url_sanitizer(url):
|
9 |
+
"""
|
10 |
+
as of now, just converts
|
11 |
+
arxiv.org/pdf/ to arxiv.org/abs
|
12 |
+
"""
|
13 |
+
# if its an arxiv pdf url then
|
14 |
+
if url.find("pdf") != -1:
|
15 |
+
url = url.replace("/pdf","/abs")
|
16 |
+
url = url.replace(".pdf","")
|
17 |
+
return url
|
18 |
+
|
19 |
+
def get_paper_info(url):
|
20 |
+
"""
|
21 |
+
Given an arxiv url returns
|
22 |
+
a ArxivPaper object with fields
|
23 |
+
title : str
|
24 |
+
authors : str
|
25 |
+
abstract : str
|
26 |
+
linktopdf : str
|
27 |
+
linktoabs : str
|
28 |
+
"""
|
29 |
+
arxiv_id = url.split("/")[-1]
|
30 |
+
arxiv_searchurl = "http://export.arxiv.org/api/query?id_list={}".format(arxiv_id)
|
31 |
+
|
32 |
+
try:
|
33 |
+
atom_feed = urllib.request.urlopen(arxiv_searchurl)
|
34 |
+
except urllib.error.HTTPError as e:
|
35 |
+
# print("Couldn't retrieve : {}".format(arxiv_searchurl))
|
36 |
+
raise RuntimeError("Trouble fetching ArXiv Id : {}".format(arxiv_id))
|
37 |
+
|
38 |
+
parsed_feed = feedparser.parse(atom_feed)
|
39 |
+
paper = parsed_feed["entries"][0]
|
40 |
+
|
41 |
+
title = paper["title"]
|
42 |
+
authors = paper["authors"]
|
43 |
+
abstract = paper["summary"]
|
44 |
+
linktopdf = None
|
45 |
+
linktoabs = None
|
46 |
+
for link_dict in paper["links"]:
|
47 |
+
if link_dict["type"].find("html") != -1:
|
48 |
+
linktoabs = link_dict["href"]
|
49 |
+
|
50 |
+
elif link_dict["type"].find("pdf")!= -1:
|
51 |
+
linktopdf = link_dict["href"]
|
52 |
+
|
53 |
+
# comment = paper["arxiv_comment"] # Not there in all arxiv pages.
|
54 |
+
return ArxivPaper(title, authors, abstract, linktopdf, linktoabs)
|
get_paperinfo_fromurls.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from arxiv_util import arxiv_url_sanitizer
|
2 |
+
from arxiv_util import get_paper_info
|
3 |
+
|
4 |
+
def get_paperinfo_fromurls(urls_filepath):
|
5 |
+
"""
|
6 |
+
Returns a dictionary of url entered by user
|
7 |
+
and corresponding paper info from arxiv.
|
8 |
+
"""
|
9 |
+
|
10 |
+
url_paperinfo = {}
|
11 |
+
with open(urls_filepath) as f:
|
12 |
+
for original_url in f.readlines():
|
13 |
+
url = arxiv_url_sanitizer(original_url.strip())
|
14 |
+
# print("Sanitized url = {}".format(url))
|
15 |
+
try:
|
16 |
+
paper_info = get_paper_info(url)
|
17 |
+
except RuntimeError as e:
|
18 |
+
print("[SKIP] Error processing : {}, message : {}".format(url, e))
|
19 |
+
pass
|
20 |
+
url_paperinfo[original_url] = paper_info
|
21 |
+
|
22 |
+
return url_paperinfo
|
htmlcard.html
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
5 |
+
<link href="csscard.css" rel="stylesheet" type="text/css"/>
|
6 |
+
|
7 |
+
</head>
|
8 |
+
|
9 |
+
<body>
|
10 |
+
{% for url, paper in paper_details.items() %}
|
11 |
+
<div class="container">
|
12 |
+
<div class="square">
|
13 |
+
<div class="mask">
|
14 |
+
<div class="left">
|
15 |
+
<img src="https://static.arxiv.org/static/browse/0.3.4/images/arxiv-logo-one-color-white.svg" alt="arxiv logo">
|
16 |
+
</div>
|
17 |
+
<h2 class="right">{{ paper.linktoabs}}</h2>
|
18 |
+
</div>
|
19 |
+
<div class="h1">{{ paper.title }}</div>
|
20 |
+
<ul id="links">
|
21 |
+
{% for author in paper.authors%}
|
22 |
+
<li><div class="auth">{{ author["name"] }}</div></li>
|
23 |
+
{% endfor %}
|
24 |
+
</ul>
|
25 |
+
<p>{{ paper.abstract }}</p>
|
26 |
+
|
27 |
+
<!-- <ul id="urllinks">
|
28 |
+
<li>
|
29 |
+
<a href="{{ paper.linktopdf}}" target="_" class="button">Article</a>
|
30 |
+
</li>
|
31 |
+
<li>
|
32 |
+
<a href="{{ paper.linktoabs}}" target="_" class="button">Abstract</a>
|
33 |
+
</li>
|
34 |
+
</ul> -->
|
35 |
+
</div>
|
36 |
+
</div>
|
37 |
+
{% endfor %}
|
38 |
+
</body>
|
39 |
+
|
40 |
+
</html>
|
icml.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
https://arxiv.org/abs/2208.14178
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
urllib
|
2 |
+
feedparser
|
3 |
+
pdb
|
4 |
+
jinja2
|