File size: 3,064 Bytes
a235177
1748047
a235177
75642d2
10ac278
 
 
 
 
341551d
10ac278
 
 
341551d
10ac278
 
 
 
1ab460b
 
 
 
 
 
 
 
 
310b87d
b862fa4
310b87d
10ac278
b089d6a
6bf8b90
b089d6a
c786d64
 
310b87d
e01ef92
4da7dd9
8e92529
 
 
 
 
b089d6a
590e222
867cecb
 
 
a235177
 
 
 
8e92529
 
 
 
 
 
 
 
a235177
867cecb
 
b6e2f14
867cecb
 
 
 
 
 
 
 
 
b6e2f14
867cecb
 
b089d6a
98aa43b
a235177
 
867cecb
a235177
867cecb
 
 
 
7c2f2b2
49cee1b
867cecb
 
 
3e7c0f4
 
867cecb
 
a235177
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import gradio as gr
import xmltodict
import requests
import json
style="""
.title_div{
    font-size: x-large;
    font-weight: 700;
    margin-bottom: 10px;
    color: white;
}
.card_div{
    background: #050523;
    color: white;
    margin: 10px;
    padding: 15px;
    border-radius: 5px;
}
.x_btn{
    font-size: xx-large;
    font-weight: 900;
    background: chocolate;
    width: fit-content;
    padding: 0 10px;
    border-radius: 10px 10px 0 0;
    float: right;
}
.frame_class{
    display:none;
}
"""

head = """
<script>
function run(inn) {
    console.log(inn);
    var frame_on = document.getElementById("frame" + String(inn));
    frame_on.style.display = 'block';
}
function closefn(inn) {
    console.log(inn);
    var frame_off = document.getElementById("frame" + String(inn));
    frame_off.style.display = 'none';
}
</script>
"""
def search(q,rn,st):
    api="http://export.arxiv.org/api/query?search_query=SQ&start=ST&max_results=MR"
    r=requests.get(api.replace("SQ",q).replace("ST",str(st)).replace("MR",str(rn)))
    cont=xmltodict.parse(r.content)['feed']['entry']
    html=""
    for i,c in enumerate(cont):
        pdflink=c['id'].replace('/abs/','/pdf/')
        html+=f"""<div class='card_div' id='id{i}' onclick="run({i})">
                   <div class='title_div'>{c['title']}</div>
                    <div style='color:white;'>{c['summary']}</div>
                    <div><a href='{pdflink}' target='_blank'>{pdflink}</a></div>
                   </div>
        <div id=frame{i} class='frame_class'>
        <div id=close{i} class='x_btn' onclick='closefn({i})'>X</div>
        <iframe src="https://docs.google.com/viewer?url={c['id'].replace('/abs/','/pdf/')}&embedded=true" frameborder="0" height="1200px" width="100%"></iframe></div>"""
    return(json.dumps(cont,indent=4)),html
def next_show(cur):
    new=int(cur)+10
    html_out=f"<div>Showing {cur} through {new}</div>"
    return gr.update(visible=True),html_out,new
    
def prev_show(cur):
    if int(cur)-10 <=0:
        new=0
        out_gr=gr.update(visible=False)
    else:
        new=int(cur)-10
        out_gr=gr.update(visible=True)
    html_out=f"<div>Showing {new} through {cur}</div>"
    return out_gr,html_out,new
    
with gr.Blocks(css=style,head=head) as b:
    with gr.Group():
        with gr.Row():
            query=gr.Textbox(label="Query")
            num=gr.Number(label="Count",step=1,value=10,interactive=False)
            sub=gr.Button()
        with gr.Row():
            prev_btn=gr.Button("Previous",visible=False)
            show_html=gr.HTML()
            next_btn=gr.Button("Next")
    html_out=gr.HTML()
    json_out=gr.JSON()
            
    hid_start=gr.Number(step=1,value=0,visible=True)    
    
    next_btn.click(next_show,[hid_start],[prev_btn,show_html,hid_start]).then(search,[query,num,hid_start],[json_out,html_out])
    prev_btn.click(next_show,[hid_start],[prev_btn,show_html,hid_start]).then(search,[query,num,hid_start],[json_out,html_out])

    sub.click(search,[query,num,start],[json_out,html_out])
b.launch()