Spaces:
Runtime error
Runtime error
using state variables to store intermediary search results.
Browse files
app.py
CHANGED
|
@@ -27,8 +27,9 @@ def get_similar_paper(
|
|
| 27 |
abstract_text_input,
|
| 28 |
pdf_file_input,
|
| 29 |
author_id_input,
|
| 30 |
-
|
| 31 |
):
|
|
|
|
| 32 |
print('retrieving similar papers...')
|
| 33 |
start = time.time()
|
| 34 |
input_sentences = sent_tokenize(abstract_text_input)
|
|
@@ -53,7 +54,7 @@ def get_similar_paper(
|
|
| 53 |
batch=50
|
| 54 |
)
|
| 55 |
|
| 56 |
-
|
| 57 |
'titles': titles,
|
| 58 |
'abstracts': abstracts,
|
| 59 |
'doc_scores': doc_scores
|
|
@@ -91,7 +92,7 @@ def get_similar_paper(
|
|
| 91 |
"interpretation": list(zip(info['all_words'], info[i]['scores']))
|
| 92 |
}
|
| 93 |
|
| 94 |
-
|
| 95 |
'title': tt,
|
| 96 |
'abstract': ab,
|
| 97 |
'doc_score': ds,
|
|
@@ -100,11 +101,11 @@ def get_similar_paper(
|
|
| 100 |
'top_pairs': top_pairs_info
|
| 101 |
}
|
| 102 |
|
| 103 |
-
# TODO better ways of saving intermediate results? user identifiers per session?
|
| 104 |
-
pickle.dump(tmp, open('info.pkl', 'wb'))
|
| 105 |
end = time.time()
|
| 106 |
print('done in [%0.2f] seconds'%(end - start))
|
| 107 |
|
|
|
|
|
|
|
| 108 |
# set up elements to show
|
| 109 |
out = [
|
| 110 |
gr.update(choices=display_title, interactive=True, visible=False), # set of papers (radio)
|
|
@@ -120,7 +121,7 @@ def get_similar_paper(
|
|
| 120 |
gr.update(value=titles[i], visible=True),
|
| 121 |
gr.update(value=doc_scores[i], visible=True)
|
| 122 |
]
|
| 123 |
-
tp =
|
| 124 |
for j in range(top_num_info_show):
|
| 125 |
out_tmp += [
|
| 126 |
gr.update(value=tp[j]['score'], visible=True),
|
|
@@ -135,6 +136,9 @@ def get_similar_paper(
|
|
| 135 |
out = out + summary_out + [gr.update(visible=True)] # show more button
|
| 136 |
assert(len(out) == (top_num_info_show * 5 + 2) * top_papers_show + 3)
|
| 137 |
|
|
|
|
|
|
|
|
|
|
| 138 |
return tuple(out)
|
| 139 |
|
| 140 |
def show_more():
|
|
@@ -151,13 +155,11 @@ def update_name(author_id_input):
|
|
| 151 |
|
| 152 |
return gr.update(value=name)
|
| 153 |
|
| 154 |
-
def change_output_highlight(selected_papers_radio, source_sent_choice):
|
| 155 |
# change the output highlight based on the sentence selected from the submission
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
source_sents = tmp[selected_papers_radio]['source_sentences']
|
| 160 |
-
highlights = tmp[selected_papers_radio]['highlight']
|
| 161 |
for i, s in enumerate(source_sents):
|
| 162 |
#print('changing highlight')
|
| 163 |
if source_sent_choice == s:
|
|
@@ -165,21 +167,19 @@ def change_output_highlight(selected_papers_radio, source_sent_choice):
|
|
| 165 |
else:
|
| 166 |
return
|
| 167 |
|
| 168 |
-
def change_paper(selected_papers_radio):
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
abstract = tmp[selected_papers_radio]['abstract']
|
| 175 |
-
aff_score = tmp[selected_papers_radio]['doc_score']
|
| 176 |
-
highlights = tmp[selected_papers_radio]['highlight']
|
| 177 |
return title, abstract, aff_score, highlights['0']
|
| 178 |
|
| 179 |
else:
|
| 180 |
return
|
| 181 |
|
| 182 |
with gr.Blocks() as demo:
|
|
|
|
| 183 |
|
| 184 |
# Text description about the app and disclaimer
|
| 185 |
### TEXT Description
|
|
@@ -228,7 +228,6 @@ Below we describe how to use the tool. Also feel free to check out the [video]()
|
|
| 228 |
with gr.Row():
|
| 229 |
compute_btn = gr.Button('What Makes This a Good Match?')
|
| 230 |
|
| 231 |
-
|
| 232 |
### OVERVIEW
|
| 233 |
# Paper title, score, and top-ranking sentence pairs -- two sentence pairs per paper, three papers
|
| 234 |
# TODO blockfy similar components together and simplify
|
|
@@ -350,7 +349,8 @@ Below we describe how to use the tool. Also feel free to check out the [video]()
|
|
| 350 |
inputs=[
|
| 351 |
abstract_text_input,
|
| 352 |
pdf_file_input,
|
| 353 |
-
author_id_input
|
|
|
|
| 354 |
],
|
| 355 |
outputs=[
|
| 356 |
selected_papers_radio,
|
|
@@ -391,7 +391,8 @@ Below we describe how to use the tool. Also feel free to check out the [video]()
|
|
| 391 |
sent_pair_source3_2_hl,
|
| 392 |
sent_pair_candidate3_2,
|
| 393 |
sent_pair_candidate3_2_hl,
|
| 394 |
-
see_more_rel_btn
|
|
|
|
| 395 |
]
|
| 396 |
)
|
| 397 |
|
|
@@ -412,7 +413,8 @@ Below we describe how to use the tool. Also feel free to check out the [video]()
|
|
| 412 |
fn=change_output_highlight,
|
| 413 |
inputs=[
|
| 414 |
selected_papers_radio,
|
| 415 |
-
source_sentences
|
|
|
|
| 416 |
],
|
| 417 |
outputs=highlight
|
| 418 |
)
|
|
@@ -420,7 +422,10 @@ Below we describe how to use the tool. Also feel free to check out the [video]()
|
|
| 420 |
# change paper to show based on selected papers
|
| 421 |
selected_papers_radio.change(
|
| 422 |
fn=change_paper,
|
| 423 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
| 424 |
outputs= [
|
| 425 |
paper_title,
|
| 426 |
paper_abstract,
|
|
|
|
| 27 |
abstract_text_input,
|
| 28 |
pdf_file_input,
|
| 29 |
author_id_input,
|
| 30 |
+
results={} # variable will be updated and returned
|
| 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)
|
|
|
|
| 54 |
batch=50
|
| 55 |
)
|
| 56 |
|
| 57 |
+
results = {
|
| 58 |
'titles': titles,
|
| 59 |
'abstracts': abstracts,
|
| 60 |
'doc_scores': doc_scores
|
|
|
|
| 92 |
"interpretation": list(zip(info['all_words'], info[i]['scores']))
|
| 93 |
}
|
| 94 |
|
| 95 |
+
results[display_title[aa]] = {
|
| 96 |
'title': tt,
|
| 97 |
'abstract': ab,
|
| 98 |
'doc_score': ds,
|
|
|
|
| 101 |
'top_pairs': top_pairs_info
|
| 102 |
}
|
| 103 |
|
|
|
|
|
|
|
| 104 |
end = time.time()
|
| 105 |
print('done in [%0.2f] seconds'%(end - start))
|
| 106 |
|
| 107 |
+
## Set up output elements
|
| 108 |
+
|
| 109 |
# set up elements to show
|
| 110 |
out = [
|
| 111 |
gr.update(choices=display_title, interactive=True, visible=False), # set of papers (radio)
|
|
|
|
| 121 |
gr.update(value=titles[i], visible=True),
|
| 122 |
gr.update(value=doc_scores[i], visible=True)
|
| 123 |
]
|
| 124 |
+
tp = results[display_title[i]]['top_pairs']
|
| 125 |
for j in range(top_num_info_show):
|
| 126 |
out_tmp += [
|
| 127 |
gr.update(value=tp[j]['score'], visible=True),
|
|
|
|
| 136 |
out = out + summary_out + [gr.update(visible=True)] # show more button
|
| 137 |
assert(len(out) == (top_num_info_show * 5 + 2) * top_papers_show + 3)
|
| 138 |
|
| 139 |
+
# add the search results to pass on to the Gradio State varaible
|
| 140 |
+
out += [results]
|
| 141 |
+
|
| 142 |
return tuple(out)
|
| 143 |
|
| 144 |
def show_more():
|
|
|
|
| 155 |
|
| 156 |
return gr.update(value=name)
|
| 157 |
|
| 158 |
+
def change_output_highlight(selected_papers_radio, source_sent_choice, info={}):
|
| 159 |
# change the output highlight based on the sentence selected from the submission
|
| 160 |
+
if len(info.keys()) != 0: # if the info is not empty
|
| 161 |
+
source_sents = info[selected_papers_radio]['source_sentences']
|
| 162 |
+
highlights = info[selected_papers_radio]['highlight']
|
|
|
|
|
|
|
| 163 |
for i, s in enumerate(source_sents):
|
| 164 |
#print('changing highlight')
|
| 165 |
if source_sent_choice == s:
|
|
|
|
| 167 |
else:
|
| 168 |
return
|
| 169 |
|
| 170 |
+
def change_paper(selected_papers_radio, info={}):
|
| 171 |
+
if len(info.keys()) != 0: # if the info is not empty
|
| 172 |
+
title = info[selected_papers_radio]['title']
|
| 173 |
+
abstract = info[selected_papers_radio]['abstract']
|
| 174 |
+
aff_score = info[selected_papers_radio]['doc_score']
|
| 175 |
+
highlights = info[selected_papers_radio]['highlight']
|
|
|
|
|
|
|
|
|
|
| 176 |
return title, abstract, aff_score, highlights['0']
|
| 177 |
|
| 178 |
else:
|
| 179 |
return
|
| 180 |
|
| 181 |
with gr.Blocks() as demo:
|
| 182 |
+
info = gr.State({}) # cached search results as a State variable shared throughout
|
| 183 |
|
| 184 |
# Text description about the app and disclaimer
|
| 185 |
### TEXT Description
|
|
|
|
| 228 |
with gr.Row():
|
| 229 |
compute_btn = gr.Button('What Makes This a Good Match?')
|
| 230 |
|
|
|
|
| 231 |
### OVERVIEW
|
| 232 |
# Paper title, score, and top-ranking sentence pairs -- two sentence pairs per paper, three papers
|
| 233 |
# TODO blockfy similar components together and simplify
|
|
|
|
| 349 |
inputs=[
|
| 350 |
abstract_text_input,
|
| 351 |
pdf_file_input,
|
| 352 |
+
author_id_input,
|
| 353 |
+
info
|
| 354 |
],
|
| 355 |
outputs=[
|
| 356 |
selected_papers_radio,
|
|
|
|
| 391 |
sent_pair_source3_2_hl,
|
| 392 |
sent_pair_candidate3_2,
|
| 393 |
sent_pair_candidate3_2_hl,
|
| 394 |
+
see_more_rel_btn,
|
| 395 |
+
info
|
| 396 |
]
|
| 397 |
)
|
| 398 |
|
|
|
|
| 413 |
fn=change_output_highlight,
|
| 414 |
inputs=[
|
| 415 |
selected_papers_radio,
|
| 416 |
+
source_sentences,
|
| 417 |
+
info
|
| 418 |
],
|
| 419 |
outputs=highlight
|
| 420 |
)
|
|
|
|
| 422 |
# change paper to show based on selected papers
|
| 423 |
selected_papers_radio.change(
|
| 424 |
fn=change_paper,
|
| 425 |
+
inputs=[
|
| 426 |
+
selected_papers_radio,
|
| 427 |
+
info,
|
| 428 |
+
],
|
| 429 |
outputs= [
|
| 430 |
paper_title,
|
| 431 |
paper_abstract,
|