Spaces:
Runtime error
Runtime error
added search progress indication
Browse files
app.py
CHANGED
@@ -27,20 +27,21 @@ def get_similar_paper(
|
|
27 |
abstract_text_input,
|
28 |
author_id_input,
|
29 |
results={}, # this state variable will be updated and returned
|
30 |
-
#progress=gr.Progress()
|
31 |
):
|
|
|
|
|
32 |
num_papers_show = 10 # number of top papers to show from the reviewer
|
33 |
print('retrieving similar papers...')
|
34 |
start = time.time()
|
35 |
input_sentences = sent_tokenize(abstract_text_input)
|
36 |
|
37 |
# Get author papers from id
|
38 |
-
|
39 |
name, papers = get_text_from_author_id(author_id_input)
|
40 |
|
41 |
# Compute Doc-level affinity scores for the Papers
|
42 |
# print('computing document scores...')
|
43 |
-
|
44 |
# TODO detect duplicate papers?
|
45 |
titles, abstracts, paper_urls, doc_scores = compute_document_score(
|
46 |
doc_model,
|
@@ -65,9 +66,10 @@ def get_similar_paper(
|
|
65 |
|
66 |
display_title = ['[ %0.3f ] %s'%(s, t) for t, s in zip(titles, doc_scores)]
|
67 |
end = time.time()
|
68 |
-
|
|
|
69 |
|
70 |
-
|
71 |
print('obtaining highlights..')
|
72 |
start = time.time()
|
73 |
input_sentences = sent_tokenize(abstract_text_input)
|
@@ -101,7 +103,8 @@ def get_similar_paper(
|
|
101 |
}
|
102 |
|
103 |
end = time.time()
|
104 |
-
|
|
|
105 |
|
106 |
## Set up output elements
|
107 |
|
@@ -137,6 +140,9 @@ def get_similar_paper(
|
|
137 |
assert(len(out) == (top_num_info_show * 5 + 2) * top_papers_show + 3)
|
138 |
|
139 |
out += [gr.update(visible=True), gr.update(visible=True)] # demarcation line between results
|
|
|
|
|
|
|
140 |
|
141 |
# add the search results to pass on to the Gradio State varaible
|
142 |
out += [results]
|
@@ -144,6 +150,7 @@ def get_similar_paper(
|
|
144 |
return tuple(out)
|
145 |
|
146 |
def show_more():
|
|
|
147 |
return (
|
148 |
gr.update(visible=True), # set of papers
|
149 |
gr.update(visible=True), # submission sentences
|
@@ -151,6 +158,10 @@ def show_more():
|
|
151 |
gr.update(visible=True), # abstract row
|
152 |
)
|
153 |
|
|
|
|
|
|
|
|
|
154 |
def update_name(author_id_input):
|
155 |
# update the name of the author based on the id input
|
156 |
name, _ = get_text_from_author_id(author_id_input)
|
@@ -233,7 +244,8 @@ Below we describe how to use the tool. Also feel free to check out the [video]()
|
|
233 |
|
234 |
# TODO indicate the progress when pressed
|
235 |
with gr.Row():
|
236 |
-
search_status = gr.
|
|
|
237 |
|
238 |
### OVERVIEW
|
239 |
# Paper title, score, and top-ranking sentence pairs -- two sentence pairs per paper, three papers
|
@@ -360,8 +372,15 @@ Below we describe how to use the tool. Also feel free to check out the [video]()
|
|
360 |
with gr.Column(scale=3): # highlighted text from paper
|
361 |
highlight = gr.components.Interpretation(paper_abstract)
|
362 |
|
|
|
363 |
### EVENT LISTENERS
|
364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
# retrieve similar papers and show top results
|
366 |
compute_btn.click(
|
367 |
fn=get_similar_paper,
|
@@ -412,6 +431,7 @@ Below we describe how to use the tool. Also feel free to check out the [video]()
|
|
412 |
see_more_rel_btn,
|
413 |
demarc1,
|
414 |
demarc2,
|
|
|
415 |
info,
|
416 |
]
|
417 |
)
|
|
|
27 |
abstract_text_input,
|
28 |
author_id_input,
|
29 |
results={}, # this state variable will be updated and returned
|
|
|
30 |
):
|
31 |
+
progress = gr.Progress()
|
32 |
+
|
33 |
num_papers_show = 10 # number of top papers to show from the reviewer
|
34 |
print('retrieving similar papers...')
|
35 |
start = time.time()
|
36 |
input_sentences = sent_tokenize(abstract_text_input)
|
37 |
|
38 |
# Get author papers from id
|
39 |
+
progress(0.1, desc="Retrieving reviewer papers ...")
|
40 |
name, papers = get_text_from_author_id(author_id_input)
|
41 |
|
42 |
# Compute Doc-level affinity scores for the Papers
|
43 |
# print('computing document scores...')
|
44 |
+
progress(0.5, desc="Computing document scores...")
|
45 |
# TODO detect duplicate papers?
|
46 |
titles, abstracts, paper_urls, doc_scores = compute_document_score(
|
47 |
doc_model,
|
|
|
66 |
|
67 |
display_title = ['[ %0.3f ] %s'%(s, t) for t, s in zip(titles, doc_scores)]
|
68 |
end = time.time()
|
69 |
+
retrieval_time = end - start
|
70 |
+
print('paper retrieval complete in [%0.2f] seconds'%(retrieval_time))
|
71 |
|
72 |
+
progress(0.4, desc="Obtaining relevant information from the papers...")
|
73 |
print('obtaining highlights..')
|
74 |
start = time.time()
|
75 |
input_sentences = sent_tokenize(abstract_text_input)
|
|
|
103 |
}
|
104 |
|
105 |
end = time.time()
|
106 |
+
highlight_time = end - start
|
107 |
+
print('done in [%0.2f] seconds'%(highlight_time))
|
108 |
|
109 |
## Set up output elements
|
110 |
|
|
|
140 |
assert(len(out) == (top_num_info_show * 5 + 2) * top_papers_show + 3)
|
141 |
|
142 |
out += [gr.update(visible=True), gr.update(visible=True)] # demarcation line between results
|
143 |
+
|
144 |
+
# progress status
|
145 |
+
out += [gr.update(value='Done (in %0.1f seconds)'%(retrieval_time+highlight_time), visible=True)]
|
146 |
|
147 |
# add the search results to pass on to the Gradio State varaible
|
148 |
out += [results]
|
|
|
150 |
return tuple(out)
|
151 |
|
152 |
def show_more():
|
153 |
+
# show the interactive part of the app
|
154 |
return (
|
155 |
gr.update(visible=True), # set of papers
|
156 |
gr.update(visible=True), # submission sentences
|
|
|
158 |
gr.update(visible=True), # abstract row
|
159 |
)
|
160 |
|
161 |
+
def show_status():
|
162 |
+
# show search status field when search button is clicked
|
163 |
+
return gr.update(visible=True)
|
164 |
+
|
165 |
def update_name(author_id_input):
|
166 |
# update the name of the author based on the id input
|
167 |
name, _ = get_text_from_author_id(author_id_input)
|
|
|
244 |
|
245 |
# TODO indicate the progress when pressed
|
246 |
with gr.Row():
|
247 |
+
#search_status = gr.Label(label="Search Status", visible=True)
|
248 |
+
search_status = gr.Textbox(label='Search Status', interactive=False, visible=False)
|
249 |
|
250 |
### OVERVIEW
|
251 |
# Paper title, score, and top-ranking sentence pairs -- two sentence pairs per paper, three papers
|
|
|
372 |
with gr.Column(scale=3): # highlighted text from paper
|
373 |
highlight = gr.components.Interpretation(paper_abstract)
|
374 |
|
375 |
+
|
376 |
### EVENT LISTENERS
|
377 |
|
378 |
+
compute_btn.click(
|
379 |
+
fn=show_status,
|
380 |
+
inputs=[],
|
381 |
+
outputs=search_status
|
382 |
+
)
|
383 |
+
|
384 |
# retrieve similar papers and show top results
|
385 |
compute_btn.click(
|
386 |
fn=get_similar_paper,
|
|
|
431 |
see_more_rel_btn,
|
432 |
demarc1,
|
433 |
demarc2,
|
434 |
+
search_status,
|
435 |
info,
|
436 |
]
|
437 |
)
|