Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ from pyserini.search.lucene import LuceneSearcher
|
|
| 4 |
|
| 5 |
searcher = LuceneSearcher("index")
|
| 6 |
ds = load_from_disk("data")
|
| 7 |
-
PAGINATION_VISIBLE = True
|
| 8 |
NUM_PAGES = 10 # STATIC. THIS CAN'T CHANGE BECAUSE GRADIO CAN'T DYNAMICALLY CREATE COMPONENTS.
|
| 9 |
RESULTS_PER_PAGE = 5
|
| 10 |
|
|
@@ -25,8 +24,7 @@ def page_0(query):
|
|
| 25 |
ix = [int(hit.docid) for hit in hits]
|
| 26 |
results = ds.select(ix).shard(num_shards=NUM_PAGES, index=0, contiguous=True) # no need to shard. split ix in batches instead. (would make sense if results was cacheable)
|
| 27 |
results = format_results(results)
|
| 28 |
-
return results, [ix]
|
| 29 |
-
|
| 30 |
def page_i(i, ix):
|
| 31 |
ix = ix[0]
|
| 32 |
results = ds.select(ix).shard(num_shards=NUM_PAGES, index=i, contiguous=True)
|
|
@@ -54,23 +52,23 @@ with gr.Blocks(css="#b {min-width:15px;background:transparent;border:white;box-s
|
|
| 54 |
pass
|
| 55 |
with gr.Column(scale=13):
|
| 56 |
c = gr.HTML(label="Results")
|
| 57 |
-
with gr.Row():
|
| 58 |
# left = gr.Button(value="◀", elem_id="b", visible=False).style(full_width=True)
|
| 59 |
-
page_1 = gr.Button(value="1", elem_id="b"
|
| 60 |
-
page_2 = gr.Button(value="2", elem_id="b"
|
| 61 |
-
page_3 = gr.Button(value="3", elem_id="b"
|
| 62 |
-
page_4 = gr.Button(value="4", elem_id="b"
|
| 63 |
-
page_5 = gr.Button(value="5", elem_id="b"
|
| 64 |
-
page_6 = gr.Button(value="6", elem_id="b"
|
| 65 |
-
page_7 = gr.Button(value="7", elem_id="b"
|
| 66 |
-
page_8 = gr.Button(value="8", elem_id="b"
|
| 67 |
-
page_9 = gr.Button(value="9", elem_id="b"
|
| 68 |
-
page_10 = gr.Button(value="10", elem_id="b"
|
| 69 |
# right = gr.Button(value="▶", elem_id="b", visible=False).style(full_width=True)
|
| 70 |
with gr.Column(scale=1):
|
| 71 |
pass
|
| 72 |
-
query.submit(fn=page_0, inputs=[query], outputs=[c, result_list])
|
| 73 |
-
submit_btn.click(page_0, inputs=[query], outputs=[c, result_list])
|
| 74 |
with gr.Box(visible=False):
|
| 75 |
nums = [gr.Number(i, visible=False, precision=0) for i in range(NUM_PAGES)]
|
| 76 |
page_1.click(fn=page_i, inputs=[nums[0], result_list], outputs=[c, result_list])
|
|
|
|
| 4 |
|
| 5 |
searcher = LuceneSearcher("index")
|
| 6 |
ds = load_from_disk("data")
|
|
|
|
| 7 |
NUM_PAGES = 10 # STATIC. THIS CAN'T CHANGE BECAUSE GRADIO CAN'T DYNAMICALLY CREATE COMPONENTS.
|
| 8 |
RESULTS_PER_PAGE = 5
|
| 9 |
|
|
|
|
| 24 |
ix = [int(hit.docid) for hit in hits]
|
| 25 |
results = ds.select(ix).shard(num_shards=NUM_PAGES, index=0, contiguous=True) # no need to shard. split ix in batches instead. (would make sense if results was cacheable)
|
| 26 |
results = format_results(results)
|
| 27 |
+
return results, [ix], gr.update(visible=True)
|
|
|
|
| 28 |
def page_i(i, ix):
|
| 29 |
ix = ix[0]
|
| 30 |
results = ds.select(ix).shard(num_shards=NUM_PAGES, index=i, contiguous=True)
|
|
|
|
| 52 |
pass
|
| 53 |
with gr.Column(scale=13):
|
| 54 |
c = gr.HTML(label="Results")
|
| 55 |
+
with gr.Row(visible=False) as pagination:
|
| 56 |
# left = gr.Button(value="◀", elem_id="b", visible=False).style(full_width=True)
|
| 57 |
+
page_1 = gr.Button(value="1", elem_id="b").style(full_width=True)
|
| 58 |
+
page_2 = gr.Button(value="2", elem_id="b").style(full_width=True)
|
| 59 |
+
page_3 = gr.Button(value="3", elem_id="b").style(full_width=True)
|
| 60 |
+
page_4 = gr.Button(value="4", elem_id="b").style(full_width=True)
|
| 61 |
+
page_5 = gr.Button(value="5", elem_id="b").style(full_width=True)
|
| 62 |
+
page_6 = gr.Button(value="6", elem_id="b").style(full_width=True)
|
| 63 |
+
page_7 = gr.Button(value="7", elem_id="b").style(full_width=True)
|
| 64 |
+
page_8 = gr.Button(value="8", elem_id="b").style(full_width=True)
|
| 65 |
+
page_9 = gr.Button(value="9", elem_id="b").style(full_width=True)
|
| 66 |
+
page_10 = gr.Button(value="10", elem_id="b").style(full_width=True)
|
| 67 |
# right = gr.Button(value="▶", elem_id="b", visible=False).style(full_width=True)
|
| 68 |
with gr.Column(scale=1):
|
| 69 |
pass
|
| 70 |
+
query.submit(fn=page_0, inputs=[query], outputs=[c, result_list, pagination])
|
| 71 |
+
submit_btn.click(page_0, inputs=[query], outputs=[c, result_list, pagination])
|
| 72 |
with gr.Box(visible=False):
|
| 73 |
nums = [gr.Number(i, visible=False, precision=0) for i in range(NUM_PAGES)]
|
| 74 |
page_1.click(fn=page_i, inputs=[nums[0], result_list], outputs=[c, result_list])
|