broadfield commited on
Commit
867cecb
·
verified ·
1 Parent(s): 590e222

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -5
app.py CHANGED
@@ -44,9 +44,9 @@ function closefn(inn) {
44
  }
45
  </script>
46
  """
47
- def search(q,rn):
48
- api="http://export.arxiv.org/api/query?search_query=SQ&start=0&max_results=MR"
49
- r=requests.get(api.replace("SQ",q).replace("MR",str(rn)))
50
  cont=xmltodict.parse(r.content)['feed']['entry']
51
  html=""
52
  for i,c in enumerate(cont):
@@ -60,13 +60,38 @@ def search(q,rn):
60
  <div id=close{i} class='x_btn' onclick='closefn({i})'>X</div>
61
  <iframe src="https://docs.google.com/viewer?url={c['id'].replace('/abs/','/pdf/')}&embedded=true" frameborder="0" height="1200px" width="100%"></iframe></div>"""
62
  return(json.dumps(cont,indent=4)),html
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  with gr.Blocks(css=style,head=head) as b:
64
  with gr.Group():
65
  with gr.Row():
66
  query=gr.Textbox(label="Query")
67
- num=gr.Number(label="Count",step=1,value=10)
68
  sub=gr.Button()
 
 
 
 
69
  html_out=gr.HTML()
70
  json_out=gr.JSON()
71
- sub.click(search,[query,num],[json_out,html_out])
 
 
 
 
 
 
72
  b.launch()
 
44
  }
45
  </script>
46
  """
47
+ def search(q,rn,st):
48
+ api="http://export.arxiv.org/api/query?search_query=SQ&start=ST&max_results=MR"
49
+ r=requests.get(api.replace("SQ",q).replace("ST",str(st)).replace("MR",str(rn)))
50
  cont=xmltodict.parse(r.content)['feed']['entry']
51
  html=""
52
  for i,c in enumerate(cont):
 
60
  <div id=close{i} class='x_btn' onclick='closefn({i})'>X</div>
61
  <iframe src="https://docs.google.com/viewer?url={c['id'].replace('/abs/','/pdf/')}&embedded=true" frameborder="0" height="1200px" width="100%"></iframe></div>"""
62
  return(json.dumps(cont,indent=4)),html
63
+ def next_show(cur):
64
+ new=int(cur)+10
65
+ html_out=f"<div>Showing {cur} through {new{</div>"
66
+ return gr.update(visible=True),html_out,new
67
+
68
+ def prev_show(cur):
69
+ if int(cur)-10 <=0:
70
+ new=0
71
+ out_gr=gr.update(visible=False)
72
+ else:
73
+ new=int(cur)-10
74
+ out_gr=gr.update(visible=True)
75
+ html_out=f"<div>Showing {new} through {cur{</div>"
76
+ return out_gr,html_out,new
77
+
78
  with gr.Blocks(css=style,head=head) as b:
79
  with gr.Group():
80
  with gr.Row():
81
  query=gr.Textbox(label="Query")
82
+ num=gr.Number(label="Count",step=1,value=10,interactive=False)
83
  sub=gr.Button()
84
+ with gr.Row():
85
+ prev_btn=gr.Button("Previous",visible=False)
86
+ show_html=gr.HTML()
87
+ next_btn=gr.Button("Next")
88
  html_out=gr.HTML()
89
  json_out=gr.JSON()
90
+
91
+ hid_start=gr.Number(step=1,value=0,visible=True)
92
+
93
+ next_btn.click(next_show,[hid_start],[prev_btn,show_html,hid_start]).then(search,[query,num,start],[json_out,html_out])
94
+ prev_btn.click(next_show,[hid_start],[prev_btn,show_html,hid_start]).then(search,[query,num,start],[json_out,html_out])
95
+
96
+ sub.click(search,[query,num,start],[json_out,html_out])
97
  b.launch()