Spaces:
Runtime error
Runtime error
import os | |
from jinja2 import Environment, FileSystemLoader, select_autoescape | |
from get_paperinfo_fromurls import get_paperinfo_fromurls | |
import gradio as gr | |
class CARDS_TEMPLATE(object): | |
def __init__(self, path_to_template, template_filename): | |
self.path_to_template = path_to_template | |
self.template_filename = template_filename | |
self.template = self._get_template() | |
self.rendered_html = None | |
def _get_template(self): | |
env = Environment( | |
autoescape=select_autoescape( | |
enabled_extensions=('html'), | |
default_for_string=True, | |
), | |
loader=FileSystemLoader(self.path_to_template) | |
) | |
return env.get_template(self.template_filename) | |
def render(self, paper_details_iterator): | |
self.rendered_html = self.template.render(paper_details=paper_details_iterator) | |
def save_html(self, output_dir=None, output_htmlfile=None): | |
with open(os.path.join(output_dir, output_htmlfile), "w") as f: | |
f.write(self.rendered_html) | |
# template_file = "htmlcard.html" | |
# template_path = "" | |
# card_template = CARDS_TEMPLATE( | |
# path_to_template = template_path, | |
# template_filename = template_file, | |
# ) | |
# paper_details = get_paperinfo_fromurls("icml.txt") | |
# card_template.render(paper_details_iterator=paper_details) | |
html = """<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<style> | |
@import url("https://fonts.googleapis.com/css?family=Merriweather|Open+Sans"); | |
.container { | |
display: flex; | |
justify-content: center; | |
padding: 80px; | |
} | |
ul { | |
list-style-type: none; | |
display: flex; | |
float: none; | |
justify-content: center; | |
align-items: center; | |
} | |
#urllinks li { | |
padding: 0px 30px 5px 5px; | |
} | |
.square { | |
width: 700px; | |
background: white; | |
border-radius: 4px; | |
box-shadow: 0px 20px 50px #d9dbdf; | |
} | |
.mask { | |
width: 700px; | |
height: 65px; | |
clip: rect(0px, 700px, 150px, 0px); | |
border-radius: 4px; | |
position: absolute; | |
background-color: #b31b1b; | |
display: flex; | |
} | |
.mask .left, | |
.mask .right { | |
flex: 1; | |
} | |
img { | |
position: absolute; | |
width: 60px; | |
padding: 20px 30px; | |
} | |
.h1 { | |
margin: auto; | |
text-align: left; | |
margin-top: 90px; | |
padding-left: 30px; | |
font-family: "Merriweather", serif; | |
font-size: 22px; | |
} | |
h2 { | |
color: white; | |
text-align: center; | |
font-size: 14px; | |
padding: 10px 0px; | |
font-family: "Open Sans", sans-serif; | |
font-weight: 400; | |
} | |
p { | |
text-align: justify; | |
padding-left: 30px; | |
padding-right: 30px; | |
font-family: "Open Sans", sans-serif; | |
font-size: 12px; | |
color: #949494; | |
line-height: 18px; | |
} | |
.auth { | |
text-align: justify; | |
padding-left: 0px; | |
padding-right: 20px; | |
font-family: "Open Sans", sans-serif; | |
font-size: 14px; | |
line-height: 18px; | |
} | |
.button { | |
background-color: #b31b1b; | |
color: white; | |
width: 150px; | |
padding: 10px 10px; | |
border-radius: 3px; | |
text-align: center; | |
text-decoration: none; | |
display: block; | |
margin-top: 20px; | |
margin-left: 20px; | |
margin-right: 20px; | |
font-size: 12px; | |
cursor: pointer; | |
font-family: "merriweather"; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="square"> | |
<div class="mask"> | |
<h2 class="left"> | |
<img src="file/arxiv-logo.svg" alt="arxiv logo"> | |
</h2> | |
<h2 class="right">http://arxiv.org/abs/2208.14178v1</h2> | |
</div> | |
<div class="h1">Observational Signatures of Galactic Turbulent Dynamos</div> | |
<ul id="links"> | |
<li><div class="auth">Yann Carteret</div></li> | |
<li><div class="auth">Abhijit B. Bendre</div></li> | |
<li><div class="auth">Jennifer Schober</div></li> | |
</ul> | |
<p>We analyse the observational signatures of galactic magnetic fields that are | |
self-consistently generated in magnetohydrodynamic simulations of the | |
interstellar medium through turbulence driven by supernova (SN) explosions and | |
differential rotation. In particular, we study the time evolution of the | |
Faraday rotation measure (RM), synchrotron radiation, and Stokes parameters by | |
characterising the typical structures formed in the plane of observation. We do | |
this by defining two distinct models for both thermal and cosmic ray (CR) | |
electron distributions. Our results indicate that the maps of RM have | |
structures which are sheared and rendered anisotropically by differential | |
rotation and that they depend on the choice of thermal electrons model as well | |
as the SN rate. Synchrotron maps are qualitatively similar to the maps of the | |
mean magnetic field along the line of sight and structures are only marginally | |
affected by the CR model. Stokes parameters and related quantities, such as the | |
degree of linear polarisation, are highly dependent on both frequency and | |
resolution of the observation.</p> | |
<!-- <ul id="urllinks"> | |
<li> | |
<a href="http://arxiv.org/pdf/2208.14178v1" target="_" class="button">Article</a> | |
</li> | |
<li> | |
<a href="http://arxiv.org/abs/2208.14178v1" target="_" class="button">Abstract</a> | |
</li> | |
</ul> --> | |
</div> | |
</div> | |
</body>""" | |
def text_analysis(text): | |
return html | |
demo = gr.Blocks() | |
with demo: | |
with gr.Row(): | |
text = gr.inputs.Textbox() | |
with gr.Row(): | |
button = gr.Button("Generate reviews !") | |
with gr.Row(): | |
card = gr.HTML() | |
button.click( | |
fn=text_analysis, | |
inputs=[text], | |
outputs=[card] | |
) | |
demo.launch() |