File size: 1,815 Bytes
63135a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8fafff8
 
 
 
 
 
63135a7
8fafff8
 
 
 
63135a7
 
 
 
 
 
8fafff8
63135a7
 
 
 
8fafff8
63135a7
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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,
                )

def create_html_card(arxiv_link):
    paper_details = get_paperinfo_fromurls(arxiv_link)
    card_template.render(paper_details_iterator=paper_details)
    return card_template.rendered_html

demo = gr.Blocks()
with demo:
    with gr.Row():
        text = gr.inputs.Textbox()
    with gr.Row():
        button = gr.Button("Generate card !")
    with gr.Row():
        card = gr.HTML()

    button.click(
        fn=create_html_card,
        inputs=[text],
        outputs=[card]
    )

demo.launch()