jskim commited on
Commit
c2dbf38
·
1 Parent(s): 6004e76

adding slider to the top results

Browse files
Files changed (2) hide show
  1. app.py +259 -226
  2. input_format.py +0 -1
app.py CHANGED
@@ -1,17 +1,17 @@
1
  import gradio as gr
2
- import os
3
  from transformers import AutoTokenizer, AutoModel
4
  from sentence_transformers import SentenceTransformer
5
  import pickle
6
  import nltk
7
- nltk.download('punkt') # tokenizer
8
- nltk.download('averaged_perceptron_tagger') # postagger
9
  import time
10
 
11
  from input_format import *
12
  from score import *
13
 
14
- # load document scoring model
 
 
 
15
  #torch.cuda.is_available = lambda : False # uncomment to test with CPU only
16
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
17
  #pretrained_model = 'allenai/specter'
@@ -20,21 +20,25 @@ tokenizer = AutoTokenizer.from_pretrained(pretrained_model)
20
  doc_model = AutoModel.from_pretrained(pretrained_model)
21
  doc_model.to(device)
22
 
23
- # load sentence model
24
  sent_model = doc_model # have the same model for document and sentence level
25
 
26
  # OR specify different model for sentence level
27
  #sent_model = SentenceTransformer('sentence-transformers/gtr-t5-base')
28
  #sent_model.to(device)
29
 
 
 
 
30
  def get_similar_paper(
31
  title_input,
32
  abstract_text_input,
33
  author_id_input,
 
 
34
  results={}, # this state variable will be updated and returned
35
- ):
36
  progress = gr.Progress()
37
- num_papers_show = 10 # number of top papers to show from the reviewer
38
  if title_input == None:
39
  title_input = '' # if no title is given, just focus on abstract.
40
  print('retrieving similar papers...')
@@ -60,17 +64,18 @@ def get_similar_paper(
60
 
61
  results = {
62
  'name': name,
 
63
  'titles': titles,
64
  'abstracts': abstracts,
65
  'urls': paper_urls,
66
  'doc_scores': doc_scores
67
  }
68
 
69
- # Select top K choices of papers to show
70
- titles = titles[:num_papers_show]
71
- abstracts = abstracts[:num_papers_show]
72
- doc_scores = doc_scores[:num_papers_show]
73
- paper_urls = paper_urls[:num_papers_show]
74
 
75
  display_title = ['[ %0.3f ] %s'%(s, t) for t, s in zip(titles, doc_scores)]
76
  end = time.time()
@@ -90,8 +95,8 @@ def get_similar_paper(
90
  tokenizer,
91
  abstract_text_input,
92
  ab,
93
- K=None, # top two sentences from the candidate
94
- top_pair_num=3, # top five sentence pairs to show upfront
95
  )
96
  num_cand_sents = sent_ids.shape[1]
97
 
@@ -116,104 +121,136 @@ def get_similar_paper(
116
  'top_pairs': top_pairs_info,
117
  'url': url
118
  }
119
-
120
  end = time.time()
121
  highlight_time = end - start
122
  print('done in [%0.2f] seconds'%(highlight_time))
123
 
124
- # debugging only
125
- pickle.dump(results, open('info.pkl', 'wb'))
126
-
127
  ## Set up output elements
128
 
129
- # first the list of top papers, sentences to select from, paper_title, affinity
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  title = results[display_title[0]]['title'] # set default title as the top paper
131
  url = results[display_title[0]]['url']
132
  aff_score = results[display_title[0]]['doc_score']
133
  title_out = """<a href="%s" target="_blank"><h5>%s</h5></a>"""%(url, title)
134
  aff_score_out = '##### Affinity Score: %s'%aff_score
135
- out = [
 
 
 
136
  gr.update(choices=display_title, value=display_title[0], interactive=True), # set of papers (radio)
137
  gr.update(choices=input_sentences, value=input_sentences[0], interactive=True), # submission sentences
138
  gr.update(value=title_out), # paper_title
139
- gr.update(value=aff_score_out) # affinity
 
 
140
  ]
141
 
142
- # set up elements to visualize upfront
143
- top_papers_show = 3 # number of top papers to show upfront
144
- top_num_info_show = 2 # number of sentence pairs from each paper to show upfront
145
- summary_out = []
 
 
 
 
 
 
 
 
 
 
 
 
146
  for i in range(top_papers_show):
147
  if i == 0:
148
- out_tmp = [
149
- gr.update(value="""<a href="%s" target="_blank"><h4>%s</h4></a>"""%(paper_urls[i], titles[i]), visible=True),
 
 
150
  gr.update(value="""#### Affinity Score: %0.3f
151
- <div class="help-tip">
152
  <p>Measures how similar the paper's abstract is to the submission abstract.</p>
153
- </div>
154
- """%doc_scores[i],
155
- visible=True) # document affinity
156
- ]
157
  else:
158
- out_tmp = [
159
- gr.update(value="""<a href="%s" target="_blank"><h4>%s</h4></a>"""%(paper_urls[i], titles[i]), visible=True),
 
 
160
  gr.update(value='#### Affinity Score: %0.3f'%doc_scores[i], visible=True) # document affinity
161
- ]
162
- tp = results[display_title[i]]['top_pairs']
 
 
 
163
  for j in range(top_num_info_show):
164
  if i == 0 and j == 0:
165
- out_tmp += [
 
166
  gr.update(value="""Sentence Relevance:\n%0.3f
167
  <div class="help-tip">
168
  <p>Measures how similar the sentence pairs are.</p>
169
- </div>"""%tp[j]['score'], visible=True), # sentence relevance
170
- tp[j]['query']['original'],
171
- tp[j]['query'],
172
- tp[j]['candidate']['original'],
173
- tp[j]['candidate']
174
- ]
175
  else:
176
- out_tmp += [
177
- gr.update(value='Sentence Relevance:\n%0.3f'%tp[j]['score'], visible=True), # sentence relevance
178
- tp[j]['query']['original'],
179
- tp[j]['query'],
180
- tp[j]['candidate']['original'],
181
- tp[j]['candidate']
182
- ]
183
- summary_out += out_tmp
 
 
 
 
 
184
 
185
- # add updates to the show more button
186
- out = out + summary_out + [gr.update(visible=True)] # make show more button visible
187
- assert(len(out) == (top_num_info_show * 5 + 2) * top_papers_show + 5)
 
 
 
 
 
 
188
 
189
- out += [gr.update(value="""
190
- <h3>Top three relevant papers by the reviewer <a href="%s" target="_blank">%s</a></h3>
191
-
192
- For each paper, two sentence pairs (one from the submission, one from the paper) with the highest relevance scores are shown.
193
-
194
- **<span style="color:black;background-color:#65B5E3;">Blue highlights</span>**: phrases that appear in both sentences.
195
- """%(author_id_input, results['name']),
196
- visible=True)] # result 1 description
197
 
198
- out += [gr.update(visible=True), gr.update(visible=True)] # demarcation line between results
199
 
200
- # progress status
201
- out += [gr.update(value='Done (in %0.1f seconds)'%(retrieval_time+highlight_time), visible=True)]
202
-
203
- # result 2 description
204
- desc = """
205
- ##### Click a paper by %s on the left (sorted by affinity scores), and a sentence from the submission on the right, to see which parts of the paper are relevant.
206
- """%results['name']
207
- out += [gr.update(value=desc)]
208
-
209
- # slider to control the number of highlights
210
- out += [gr.update(value=1, maximum=len(sent_tokenize(abstracts[0])))]
211
-
212
- # finally add the search results to pass on to the Gradio State varaible
213
- out += [results]
214
-
215
- return tuple(out)
216
-
217
  def show_more(info):
218
  # show the interactive part of the app
219
  return (
@@ -290,6 +327,49 @@ def change_num_highlight(
290
  else:
291
  return
292
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  with gr.Blocks(css='style.css') as demo:
294
  info = gr.State({}) # cached search results as a State variable shared throughout
295
 
@@ -310,15 +390,13 @@ A typical meta-reviewer workflow lacks supportive information on **what makes th
310
 
311
  R2P2 provides more information about each reviewer. It searches for the **most relevant papers** among the reviewer's previous publications and **highlights relevant parts** within them.
312
  """
313
- # TODO add instruction video link
314
  # More details (video, addendum)
315
- more_details_instruction = """Check out <a href="", target="_blank">this video</a> for a quick demo of what R2P2 is and how it can help. You can find more details <a href="file/details.html", target="_blank">here</a>, along with our privacy policy and disclaimer."""
316
 
317
  gr.Markdown(general_instruction)
318
  gr.HTML(more_details_instruction)
319
  gr.Markdown("""---""")
320
 
321
-
322
  ### INPUT
323
  with gr.Row() as input_row:
324
  with gr.Column(scale=3):
@@ -350,97 +428,57 @@ R2P2 provides more information about each reviewer. It searches for the **most r
350
  with gr.Row():
351
  search_status = gr.Textbox(label='Search Status', interactive=False, visible=False)
352
 
353
-
354
- ### OVERVIEW
355
- # Paper title, score, and top-ranking sentence pairs -- two sentence pairs per paper, three papers
356
- ## ONE BLOCK OF INFO FOR A SINGLE PAPER
357
- ## PAPER1
358
- with gr.Row():
359
- result1_desc = gr.Markdown(value='', visible=False)
360
  with gr.Row():
361
- with gr.Column(scale=3):
362
- paper_title1 = gr.Markdown(value='', visible=False)
363
- with gr.Column(scale=1):
364
- affinity1 = gr.Markdown(value='', visible=False)
365
- with gr.Row() as rel1_1:
366
- with gr.Column(scale=1):
367
- sent_pair_score1_1 = gr.Markdown(interactive=False, value='', visible=False)
368
- with gr.Column(scale=4):
369
- sent_pair_source1_1 = gr.Textbox(label='Sentence from Submission', visible=False)
370
- sent_pair_source1_1_hl = gr.components.Interpretation(sent_pair_source1_1)
371
- with gr.Column(scale=4):
372
- sent_pair_candidate1_1 = gr.Textbox(label="Sentence from Reviewer's Paper", visible=False)
373
- sent_pair_candidate1_1_hl = gr.components.Interpretation(sent_pair_candidate1_1)
374
- with gr.Row() as rel1_2:
375
- with gr.Column(scale=1):
376
- sent_pair_score1_2 = gr.Markdown(interactive=False, value='', visible=False)
377
- with gr.Column(scale=4):
378
- sent_pair_source1_2 = gr.Textbox(label='Sentence from Submission', visible=False)
379
- sent_pair_source1_2_hl = gr.components.Interpretation(sent_pair_source1_2)
380
- with gr.Column(scale=4):
381
- sent_pair_candidate1_2 = gr.Textbox(label="Sentence from Reviewer's Paper", visible=False)
382
- sent_pair_candidate1_2_hl = gr.components.Interpretation(sent_pair_candidate1_2)
383
-
384
- with gr.Row(visible=False) as demarc1:
385
- gr.Markdown(
386
- """---"""
387
- )
388
-
389
- ## PAPER 2
390
- with gr.Row():
391
- with gr.Column(scale=3):
392
- paper_title2 = gr.Markdown(value='', visible=False)
393
- with gr.Column(scale=1):
394
- affinity2 = gr.Markdown(value='', visible=False)
395
- with gr.Row() as rel2_1:
396
- with gr.Column(scale=1):
397
- sent_pair_score2_1 = gr.Markdown(interactive=False, value='', visible=False)
398
- with gr.Column(scale=4):
399
- sent_pair_source2_1 = gr.Textbox(label='Sentence from Submission', visible=False)
400
- sent_pair_source2_1_hl = gr.components.Interpretation(sent_pair_source2_1)
401
- with gr.Column(scale=4):
402
- sent_pair_candidate2_1 = gr.Textbox(label="Sentence from Reviewer's Paper", visible=False)
403
- sent_pair_candidate2_1_hl = gr.components.Interpretation(sent_pair_candidate2_1)
404
- with gr.Row() as rel2_2:
405
- with gr.Column(scale=1):
406
- sent_pair_score2_2 = gr.Markdown(interactive=False, value='', visible=False)
407
- with gr.Column(scale=4):
408
- sent_pair_source2_2 = gr.Textbox(label='Sentence from Submission', visible=False)
409
- sent_pair_source2_2_hl = gr.components.Interpretation(sent_pair_source2_2)
410
- with gr.Column(scale=4):
411
- sent_pair_candidate2_2 = gr.Textbox(label="Sentence from Reviewer's Paper", visible=False)
412
- sent_pair_candidate2_2_hl = gr.components.Interpretation(sent_pair_candidate2_2)
413
-
414
- with gr.Row(visible=False) as demarc2:
415
- gr.Markdown(
416
- """---"""
417
- )
418
-
419
- ## PAPER 3
420
- with gr.Row():
421
- with gr.Column(scale=3):
422
- paper_title3 = gr.Markdown(value='', visible=False)
423
- with gr.Column(scale=1):
424
- affinity3 = gr.Markdown(value='', visible=False)
425
- with gr.Row() as rel3_1:
426
- with gr.Column(scale=1):
427
- sent_pair_score3_1 = gr.Markdown(interactive=False, value='', visible=False)
428
- with gr.Column(scale=4):
429
- sent_pair_source3_1 = gr.Textbox(label='Sentence from Submission', visible=False)
430
- sent_pair_source3_1_hl = gr.components.Interpretation(sent_pair_source3_1)
431
- with gr.Column(scale=4):
432
- sent_pair_candidate3_1 = gr.Textbox(label="Sentence from Reviewer's Paper", visible=False)
433
- sent_pair_candidate3_1_hl = gr.components.Interpretation(sent_pair_candidate3_1)
434
- with gr.Row() as rel3_2:
435
- with gr.Column(scale=1):
436
- sent_pair_score3_2 = gr.Markdown(interactive=False, value='', visible=False)
437
- with gr.Column(scale=4):
438
- sent_pair_source3_2 = gr.Textbox(label='Sentence from Submission', visible=False)
439
- sent_pair_source3_2_hl = gr.components.Interpretation(sent_pair_source3_2)
440
- with gr.Column(scale=4):
441
- sent_pair_candidate3_2 = gr.Textbox(label="Sentence from Reviewer's Paper", visible=False)
442
- sent_pair_candidate3_2_hl = gr.components.Interpretation(sent_pair_candidate3_2)
443
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  ## Show more button
445
  with gr.Row():
446
  see_more_rel_btn = gr.Button('Explore more', visible=False)
@@ -499,74 +537,47 @@ R2P2 provides more information about each reviewer. It searches for the **most r
499
  # highlighted text from paper
500
  highlight = gr.components.Interpretation(paper_abstract)
501
 
502
-
503
  ### EVENT LISTENERS
504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
505
  compute_btn.click(
506
  fn=show_status,
507
  inputs=[],
508
  outputs=search_status
509
  )
510
 
511
- # retrieve similar papers and show top results
512
  compute_btn.click(
513
  fn=get_similar_paper,
514
  inputs=[
515
  title_input,
516
  abstract_text_input,
517
  author_id_input,
 
 
518
  info
519
  ],
520
- outputs=[
521
- selected_papers_radio, # list of papers for show more section
522
- source_sentences, # list of sentences for show more section
523
- paper_title, # paper title for show more section
524
- affinity, # paper affinity for show more section
525
- paper_title1, # paper info
526
- affinity1,
527
- sent_pair_score1_1,
528
- sent_pair_source1_1,
529
- sent_pair_source1_1_hl,
530
- sent_pair_candidate1_1,
531
- sent_pair_candidate1_1_hl,
532
- sent_pair_score1_2,
533
- sent_pair_source1_2,
534
- sent_pair_source1_2_hl,
535
- sent_pair_candidate1_2,
536
- sent_pair_candidate1_2_hl,
537
- paper_title2,
538
- affinity2,
539
- sent_pair_score2_1,
540
- sent_pair_source2_1,
541
- sent_pair_source2_1_hl,
542
- sent_pair_candidate2_1,
543
- sent_pair_candidate2_1_hl,
544
- sent_pair_score2_2,
545
- sent_pair_source2_2,
546
- sent_pair_source2_2_hl,
547
- sent_pair_candidate2_2,
548
- sent_pair_candidate2_2_hl,
549
- paper_title3,
550
- affinity3,
551
- sent_pair_score3_1,
552
- sent_pair_source3_1,
553
- sent_pair_source3_1_hl,
554
- sent_pair_candidate3_1,
555
- sent_pair_candidate3_1_hl,
556
- sent_pair_score3_2,
557
- sent_pair_source3_2,
558
- sent_pair_source3_2_hl,
559
- sent_pair_candidate3_2,
560
- sent_pair_candidate3_2_hl,
561
- see_more_rel_btn,
562
- result1_desc,
563
- demarc1,
564
- demarc2,
565
- search_status,
566
- result2_desc,
567
- highlight_slider,
568
- info,
569
- ],
570
  show_progress=True,
571
  scroll_to_output=True
572
  )
@@ -617,6 +628,7 @@ R2P2 provides more information about each reviewer. It searches for the **most r
617
  ]
618
  )
619
 
 
620
  highlight_slider.change(
621
  fn=change_num_highlight,
622
  inputs=[
@@ -630,6 +642,27 @@ R2P2 provides more information about each reviewer. It searches for the **most r
630
  ]
631
  )
632
 
633
- if __name__ == "__main__":
634
- demo.queue().launch() # add ?__theme=light to force light mode
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
635
 
 
 
 
1
  import gradio as gr
 
2
  from transformers import AutoTokenizer, AutoModel
3
  from sentence_transformers import SentenceTransformer
4
  import pickle
5
  import nltk
 
 
6
  import time
7
 
8
  from input_format import *
9
  from score import *
10
 
11
+ nltk.download('punkt') # tokenizer
12
+ nltk.download('averaged_perceptron_tagger') # postagger
13
+
14
+ ## load document scoring model
15
  #torch.cuda.is_available = lambda : False # uncomment to test with CPU only
16
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
17
  #pretrained_model = 'allenai/specter'
 
20
  doc_model = AutoModel.from_pretrained(pretrained_model)
21
  doc_model.to(device)
22
 
23
+ ## load sentence model
24
  sent_model = doc_model # have the same model for document and sentence level
25
 
26
  # OR specify different model for sentence level
27
  #sent_model = SentenceTransformer('sentence-transformers/gtr-t5-base')
28
  #sent_model.to(device)
29
 
30
+ NUM_PAPERS_SHOW = 5 # max number of top papers to show from the reviewer upfront
31
+ NUM_PAIRS_SHOW = 5 # max number of top sentence pairs to show
32
+
33
  def get_similar_paper(
34
  title_input,
35
  abstract_text_input,
36
  author_id_input,
37
+ top_paper_slider,
38
+ top_pair_slider,
39
  results={}, # this state variable will be updated and returned
40
+ ):
41
  progress = gr.Progress()
 
42
  if title_input == None:
43
  title_input = '' # if no title is given, just focus on abstract.
44
  print('retrieving similar papers...')
 
64
 
65
  results = {
66
  'name': name,
67
+ 'author_url': author_id_input,
68
  'titles': titles,
69
  'abstracts': abstracts,
70
  'urls': paper_urls,
71
  'doc_scores': doc_scores
72
  }
73
 
74
+ # Select top 10 papers to show
75
+ titles = titles[:10]
76
+ abstracts = abstracts[:10]
77
+ doc_scores = doc_scores[:10]
78
+ paper_urls = paper_urls[:10]
79
 
80
  display_title = ['[ %0.3f ] %s'%(s, t) for t, s in zip(titles, doc_scores)]
81
  end = time.time()
 
95
  tokenizer,
96
  abstract_text_input,
97
  ab,
98
+ K=None,
99
+ top_pair_num=10, # top ten sentence pairs at max to show upfront
100
  )
101
  num_cand_sents = sent_ids.shape[1]
102
 
 
121
  'top_pairs': top_pairs_info,
122
  'url': url
123
  }
124
+
125
  end = time.time()
126
  highlight_time = end - start
127
  print('done in [%0.2f] seconds'%(highlight_time))
128
 
 
 
 
129
  ## Set up output elements
130
 
131
+ ## Components for Initial Part
132
+ result1_desc_value = """
133
+ <h3>Top %d relevant papers by the reviewer <a href="%s" target="_blank">%s</a></h3>
134
+
135
+ For each paper, top %d sentence pairs (one from the submission, one from the paper) with the highest relevance scores are shown.
136
+
137
+ **<span style="color:black;background-color:#65B5E3;">Blue highlights</span>**: phrases that appear in both sentences.
138
+ """%(int(top_paper_slider), author_id_input, results['name'], int(top_pair_slider))
139
+
140
+ out1 = [
141
+ gr.update(visible=True), # Explore more button
142
+ gr.update(value=result1_desc_value, visible=True), # result 1 description
143
+ gr.update(value='Done (in %0.1f seconds)'%(retrieval_time+highlight_time), visible=True), # search status
144
+ gr.update(visible=True), # top paper slider
145
+ gr.update(visible=True) # top pair slider
146
+ ]
147
+
148
+ ### Components for Results in Initial Part
149
+ top_papers_show = int(top_paper_slider) # number of top papers to show upfront
150
+ top_num_info_show = int(top_pair_slider) # number of sentence pairs from each paper to show upfront
151
+ output = setup_outputs(results, top_papers_show, top_num_info_show)
152
+ out2 = []
153
+ for x in output:
154
+ out2 += x
155
+
156
+ ### Components for Explore More Section
157
+ # list of top papers, sentences to select from, paper_title, affinity
158
  title = results[display_title[0]]['title'] # set default title as the top paper
159
  url = results[display_title[0]]['url']
160
  aff_score = results[display_title[0]]['doc_score']
161
  title_out = """<a href="%s" target="_blank"><h5>%s</h5></a>"""%(url, title)
162
  aff_score_out = '##### Affinity Score: %s'%aff_score
163
+ result2_desc_value = """
164
+ ##### Click a paper by %s (left, sorted by affinity scores), and a sentence from the submission (center), to see which parts of the paper are relevant (right).
165
+ """%results['name']
166
+ out3 = [
167
  gr.update(choices=display_title, value=display_title[0], interactive=True), # set of papers (radio)
168
  gr.update(choices=input_sentences, value=input_sentences[0], interactive=True), # submission sentences
169
  gr.update(value=title_out), # paper_title
170
+ gr.update(value=aff_score_out), # affinity
171
+ gr.update(value=result2_desc_value), # result 2 description (show more section)
172
+ gr.update(value=1, maximum=len(sent_tokenize(abstracts[0]))), # highlight slider to control
173
  ]
174
 
175
+ ## Return by adding the State variable info
176
+ return out1 + out2 + out3 + [results]
177
+
178
+ def setup_outputs(info, top_papers_show, top_num_info_show):
179
+ titles = info['titles']
180
+ doc_scores = info['doc_scores']
181
+ paper_urls = info['urls']
182
+ display_title = ['[ %0.3f ] %s'%(s, t) for t, s in zip(info['titles'], info['doc_scores'])]
183
+ title = []
184
+ affinity = []
185
+ sent_pair_score = []
186
+ sent_text_query = []
187
+ sent_text_candidate = []
188
+ sent_hl_query = []
189
+ sent_hl_candidate = []
190
+ demarc_lines = []
191
  for i in range(top_papers_show):
192
  if i == 0:
193
+ title.append(
194
+ gr.update(value="""<a href="%s" target="_blank"><h4>%s</h4></a>"""%(paper_urls[i], titles[i]), visible=True)
195
+ )
196
+ affinity.append(
197
  gr.update(value="""#### Affinity Score: %0.3f
198
+ <div class="help-tip">
199
  <p>Measures how similar the paper's abstract is to the submission abstract.</p>
200
+ </div>
201
+ """%doc_scores[i], visible=True) # document affinity
202
+ )
 
203
  else:
204
+ title.append(
205
+ gr.update(value="""<a href="%s" target="_blank"><h4>%s</h4></a>"""%(paper_urls[i], titles[i]), visible=True)
206
+ )
207
+ affinity.append(
208
  gr.update(value='#### Affinity Score: %0.3f'%doc_scores[i], visible=True) # document affinity
209
+ )
210
+ demarc_lines.append(gr.Markdown.update(visible=True))
211
+
212
+ # fill in the rest as
213
+ tp = info[display_title[i]]['top_pairs']
214
  for j in range(top_num_info_show):
215
  if i == 0 and j == 0:
216
+ # for the first entry add help tip
217
+ sent_pair_score.append(
218
  gr.update(value="""Sentence Relevance:\n%0.3f
219
  <div class="help-tip">
220
  <p>Measures how similar the sentence pairs are.</p>
221
+ </div>"""%tp[j]['score'], visible=True)
222
+ )
 
 
 
 
223
  else:
224
+ sent_pair_score.append(
225
+ gr.Textbox.update(value='Sentence Relevance:\n%0.3f'%tp[j]['score'], visible=True)
226
+ )
227
+ sent_text_query.append(gr.Textbox.update(tp[j]['query']['original']))
228
+ sent_text_candidate.append(gr.Textbox.update(tp[j]['candidate']['original']))
229
+ sent_hl_query.append(tp[j]['query'])
230
+ sent_hl_candidate.append(tp[j]['candidate'])
231
+ #row2.append(gr.update(visible=True))
232
+ sent_pair_score += [gr.Markdown.update(visible=False)] * (NUM_PAIRS_SHOW - top_num_info_show)
233
+ sent_text_query += [gr.Textbox.update(value='', visible=False)] * (NUM_PAIRS_SHOW - top_num_info_show)
234
+ sent_text_candidate += [gr.Textbox.update(value='', visible=False)] * (NUM_PAIRS_SHOW - top_num_info_show)
235
+ sent_hl_query += [None] * (NUM_PAIRS_SHOW - top_num_info_show)
236
+ sent_hl_candidate += [None] * (NUM_PAIRS_SHOW - top_num_info_show)
237
 
238
+ # mark others not visible
239
+ title += [gr.Markdown.update(visible=False)] * (NUM_PAPERS_SHOW - top_papers_show)
240
+ affinity += [gr.Markdown.update(visible=False)] * (NUM_PAPERS_SHOW - top_papers_show)
241
+ demarc_lines += [gr.Markdown.update(visible=False)] * (NUM_PAPERS_SHOW - top_papers_show)
242
+ sent_pair_score += [gr.Markdown.update(visible=False)] * (NUM_PAPERS_SHOW - top_papers_show) * NUM_PAIRS_SHOW
243
+ sent_text_query += [gr.Textbox.update(value='', visible=False)] * (NUM_PAPERS_SHOW - top_papers_show) * NUM_PAIRS_SHOW
244
+ sent_text_candidate += [gr.Textbox.update(value='', visible=False)] * (NUM_PAPERS_SHOW - top_papers_show) * NUM_PAIRS_SHOW
245
+ sent_hl_query += [None] * (NUM_PAPERS_SHOW - top_papers_show) * NUM_PAIRS_SHOW
246
+ sent_hl_candidate += [None] * (NUM_PAPERS_SHOW - top_papers_show) * NUM_PAIRS_SHOW
247
 
248
+ assert(len(title) == NUM_PAPERS_SHOW)
249
+ assert(len(affinity) == NUM_PAPERS_SHOW)
250
+ assert(len(sent_pair_score) == NUM_PAIRS_SHOW * NUM_PAPERS_SHOW)
 
 
 
 
 
251
 
252
+ return title, affinity, demarc_lines, sent_pair_score, sent_text_query, sent_text_candidate, sent_hl_query, sent_hl_candidate
253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  def show_more(info):
255
  # show the interactive part of the app
256
  return (
 
327
  else:
328
  return
329
 
330
+ def change_top_output(top_paper_slider, top_pair_slider, info={}):
331
+ top_papers_show = int(top_paper_slider)
332
+ top_num_info_show = int(top_pair_slider)
333
+
334
+ result1_desc_value = """
335
+ <h3>Top %d relevant papers by the reviewer <a href="%s" target="_blank">%s</a></h3>
336
+
337
+ For each paper, top %d sentence pairs (one from the submission, one from the paper) with the highest relevance scores are shown.
338
+
339
+ **<span style="color:black;background-color:#65B5E3;">Blue highlights</span>**: phrases that appear in both sentences.
340
+ """%(int(top_paper_slider), info['author_url'], info['name'], int(top_pair_slider))
341
+ if len(info.keys()) != 0:
342
+ tmp = setup_outputs(info, top_papers_show, top_num_info_show)
343
+ x = []
344
+ for t in tmp:
345
+ x += t
346
+ return x + [gr.update(value=result1_desc_value)]
347
+ else:
348
+ return
349
+
350
+ def reinit_hl(top_paper_slider, top_pair_slider, *args):
351
+ args = list(args)
352
+ base = 3*NUM_PAPERS_SHOW+NUM_PAPERS_SHOW*NUM_PAIRS_SHOW
353
+ increment = NUM_PAPERS_SHOW*NUM_PAIRS_SHOW
354
+ text_query = args[base:base+increment]
355
+ text_candidate = args[base+increment:base+2*increment]
356
+ hl_query = args[base+2*increment:base+3*increment]
357
+ hl_candidate = args[base+3*increment:base+4*increment]
358
+ for i in range(int(top_paper_slider)):
359
+ for j in range(int(top_pair_slider),NUM_PAIRS_SHOW):
360
+ hl_query[i*NUM_PAIRS_SHOW+j] = gr.components.Interpretation(text_query[i*NUM_PAIRS_SHOW+j])
361
+ hl_candidate[i*NUM_PAIRS_SHOW+j] = gr.components.Interpretation(text_candidate[i*NUM_PAIRS_SHOW+j])
362
+ for i in range(int(top_paper_slider),NUM_PAPERS_SHOW):
363
+ for j in range(NUM_PAPERS_SHOW):
364
+ hl_query[i*NUM_PAIRS_SHOW+j] = gr.components.Interpretation(text_query[i*NUM_PAIRS_SHOW+j])
365
+ hl_candidate[i*NUM_PAIRS_SHOW+j] = gr.components.Interpretation(text_candidate[i*NUM_PAIRS_SHOW+j])
366
+
367
+ args[base:base+increment] = text_query
368
+ args[base+increment:base+2*increment] = text_candidate
369
+ args[base+2*increment:base+3*increment] = hl_query
370
+ args[base+3*increment:base+4*increment] = hl_candidate
371
+ return args
372
+
373
  with gr.Blocks(css='style.css') as demo:
374
  info = gr.State({}) # cached search results as a State variable shared throughout
375
 
 
390
 
391
  R2P2 provides more information about each reviewer. It searches for the **most relevant papers** among the reviewer's previous publications and **highlights relevant parts** within them.
392
  """
 
393
  # More details (video, addendum)
394
+ more_details_instruction = """Check out <a href="https://drive.google.com/file/d/1Ex_-cOplBitO7riNGliecFc8H3chXUN-/view?usp=share_link", target="_blank">this video</a> for a quick introduction of what R2P2 is and how it can help. You can find more details <a href="file/details.html", target="_blank">here</a>, along with our privacy policy and disclaimer."""
395
 
396
  gr.Markdown(general_instruction)
397
  gr.HTML(more_details_instruction)
398
  gr.Markdown("""---""")
399
 
 
400
  ### INPUT
401
  with gr.Row() as input_row:
402
  with gr.Column(scale=3):
 
428
  with gr.Row():
429
  search_status = gr.Textbox(label='Search Status', interactive=False, visible=False)
430
 
431
+ ### OVERVIEW RESULTS
432
+ # Paper title, score, and top-ranking sentence pairs
433
+ # a knob for controlling the number of output displayed
 
 
 
 
434
  with gr.Row():
435
+ with gr.Column(scale=5):
436
+ result1_desc = gr.Markdown(value='', visible=False)
437
+ with gr.Column(scale=2):
438
+ with gr.Row():
439
+ top_paper_slider = gr.Slider(label='Top-K Papers by the Reviewer', value=3, minimum=3, step=1, maximum=NUM_PAPERS_SHOW, visible=False)
440
+ with gr.Row():
441
+ top_pair_slider = gr.Slider(label='Top-K Sentence Pairs per Paper', value=2, minimum=2, step=1, maximum=NUM_PAIRS_SHOW, visible=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
442
 
443
+ paper_title_up = []
444
+ paper_affinity_up = []
445
+ sent_pair_score = []
446
+ sent_text_query = []
447
+ sent_text_candidate = []
448
+ sent_hl_query = []
449
+ sent_hl_candidate = []
450
+ demarc_lines = []
451
+
452
+ row_elems1 = []
453
+ row_elems2 = []
454
+
455
+ for i in range(NUM_PAPERS_SHOW):
456
+ with gr.Row():
457
+ with gr.Column(scale=3):
458
+ tt = gr.Markdown(value='', visible=False)
459
+ paper_title_up.append(tt)
460
+ with gr.Column(scale=1):
461
+ aff = gr.Markdown(value='', visible=False)
462
+ paper_affinity_up.append(aff)
463
+ for j in range(NUM_PAIRS_SHOW):
464
+ with gr.Row():
465
+ with gr.Column(scale=1):
466
+ sps = gr.Markdown(value='', visible=False)
467
+ sent_pair_score.append(sps)
468
+ with gr.Column(scale=5):
469
+ stq = gr.Textbox(label='Sentence from Submission', visible=False)
470
+ shq = gr.components.Interpretation(stq, visible=False)
471
+ sent_text_query.append(stq)
472
+ sent_hl_query.append(shq)
473
+ with gr.Column(scale=5):
474
+ stc = gr.Textbox(label="Sentence from Reviewer's Paper", visible=False)
475
+ shc = gr.components.Interpretation(stc, visible=False)
476
+ sent_text_candidate.append(stc)
477
+ sent_hl_candidate.append(shc)
478
+ with gr.Row():
479
+ dml = gr.Markdown("""---""", visible=False)
480
+ demarc_lines.append(dml)
481
+
482
  ## Show more button
483
  with gr.Row():
484
  see_more_rel_btn = gr.Button('Explore more', visible=False)
 
537
  # highlighted text from paper
538
  highlight = gr.components.Interpretation(paper_abstract)
539
 
 
540
  ### EVENT LISTENERS
541
 
542
+ # components to work with
543
+ init_components = [
544
+ see_more_rel_btn, # explore more button
545
+ result1_desc, # description for first results
546
+ search_status, # search status
547
+ top_paper_slider,
548
+ top_pair_slider
549
+ ]
550
+
551
+ init_result_components = \
552
+ paper_title_up + paper_affinity_up + demarc_lines + sent_pair_score + \
553
+ sent_text_query + sent_text_candidate + sent_hl_query + sent_hl_candidate
554
+
555
+ explore_more_components = [
556
+ selected_papers_radio, # list of papers for show more section
557
+ source_sentences, # list of sentences for show more section
558
+ paper_title, # paper title for show more section
559
+ affinity, # affinity for show more section
560
+ result2_desc, # description for explore more
561
+ highlight_slider, # highlight slider
562
+ ]
563
+
564
  compute_btn.click(
565
  fn=show_status,
566
  inputs=[],
567
  outputs=search_status
568
  )
569
 
 
570
  compute_btn.click(
571
  fn=get_similar_paper,
572
  inputs=[
573
  title_input,
574
  abstract_text_input,
575
  author_id_input,
576
+ top_paper_slider,
577
+ top_pair_slider,
578
  info
579
  ],
580
+ outputs=init_components + init_result_components + explore_more_components + [info],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
  show_progress=True,
582
  scroll_to_output=True
583
  )
 
628
  ]
629
  )
630
 
631
+ # change number of higlights to show
632
  highlight_slider.change(
633
  fn=change_num_highlight,
634
  inputs=[
 
642
  ]
643
  )
644
 
645
+ # change number of top papers to show initially
646
+ top_paper_slider.change(
647
+ fn=change_top_output,
648
+ inputs=[
649
+ top_paper_slider,
650
+ top_pair_slider,
651
+ info
652
+ ],
653
+ outputs=init_result_components+[result1_desc]
654
+ )
655
+
656
+ # change number of top sentence pairs to show initially
657
+ top_pair_slider.change(
658
+ fn=change_top_output,
659
+ inputs=[
660
+ top_paper_slider,
661
+ top_pair_slider,
662
+ info
663
+ ],
664
+ outputs=init_result_components+[result1_desc]
665
+ )
666
 
667
+ if __name__ == "__main__":
668
+ demo.queue().launch() # add ?__theme=light to force light mode
input_format.py CHANGED
@@ -1,4 +1,3 @@
1
- import numpy as np
2
  from pypdf import PdfReader
3
  from urllib.parse import urlparse
4
  import requests
 
 
1
  from pypdf import PdfReader
2
  from urllib.parse import urlparse
3
  import requests