jskim commited on
Commit
e16ae7e
·
1 Parent(s): 580aef7

showing multiple top papers from the author

Browse files
Files changed (2) hide show
  1. app.py +45 -21
  2. input_format.py +0 -2
app.py CHANGED
@@ -52,14 +52,16 @@ def get_similar_paper(
52
  'abstracts': abstracts,
53
  'doc_scores': doc_scores
54
  }
55
- pickle.dump(tmp, open('tmp_paperinfo.pkl', 'wb'))
56
 
57
  # Select top K choices of papers to show
58
  titles = titles[:num_papers_show]
59
  abstracts = abstracts[:num_papers_show]
60
  doc_scores = doc_scores[:num_papers_show]
61
 
62
- return titles[0], abstracts[0], doc_scores[0], gr.update(choices=input_sentences, interactive=True), gr.update(visible=True)
 
 
63
 
64
  def get_highlights(
65
  abstract_text_input,
@@ -101,18 +103,32 @@ def update_name(author_id_input):
101
  return gr.update(value=name)
102
 
103
  def change_output_highlight(source_sent_choice):
 
104
  # change the output highlight based on the sentence selected from the submission
105
- if os.path.exists('highlight_info.pkl'):
106
- tmp = pickle.load(open('highlight_info.pkl', 'rb'))
107
  source_sents = tmp['source_sentences']
108
  highlights = tmp['highlight']
109
  for i, s in enumerate(source_sents):
110
- print('changing highlight!')
111
  if source_sent_choice == s:
112
  return highlights[str(i)]
113
  else:
114
  return
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  with gr.Blocks() as demo:
117
 
118
  ### INPUT
@@ -130,24 +146,22 @@ with gr.Blocks() as demo:
130
  with gr.Row():
131
  compute_btn = gr.Button('Search Similar Papers from the Reviewer')
132
 
133
-
134
- # with gr.Row(visible=False) as reviewer_name_info:
135
- # name = gr.Textbox(label='Reveiwer Author Name')
136
- # with gr.Row():
137
- # with gr.Tabs():
138
- # for tt in range(num_papers_show):
139
- # with gr.TabItem('Paper %d'%(tt+1)):
140
-
141
- # TODO handle multiple papers
142
 
143
  ### PAPER INFORMATION
144
- with gr.Row():
145
  with gr.Column(scale=3):
146
  paper_title = gr.Textbox(label='Title', interactive=False)
147
  with gr.Column(scale=1):
148
  affinity= gr.Number(label='Affinity', interactive=False, value=0)
149
- with gr.Row():
150
- paper_abstract = gr.Textbox(label='Abstract', interactive=False)
151
 
152
  with gr.Row(visible=False) as explain_button_row:
153
  explain_btn = gr.Button('Show Relevant Parts from Selected Paper')
@@ -172,11 +186,11 @@ with gr.Blocks() as demo:
172
  author_id_input
173
  ],
174
  outputs=[
175
- paper_title,
176
- paper_abstract,
177
- affinity,
178
  source_sentences,
179
- explain_button_row
 
 
180
  ]
181
  )
182
 
@@ -195,6 +209,16 @@ with gr.Blocks() as demo:
195
  inputs=source_sentences,
196
  outputs=highlight
197
  )
 
 
 
 
 
 
 
 
 
 
198
 
199
  if __name__ == "__main__":
200
  demo.launch()
 
52
  'abstracts': abstracts,
53
  'doc_scores': doc_scores
54
  }
55
+ pickle.dump(tmp, open('paper_info.pkl', 'wb'))
56
 
57
  # Select top K choices of papers to show
58
  titles = titles[:num_papers_show]
59
  abstracts = abstracts[:num_papers_show]
60
  doc_scores = doc_scores[:num_papers_show]
61
 
62
+ display_title = ['[ %0.3f ] %s'%(s, t) for t, s in zip(titles, doc_scores)]
63
+
64
+ return gr.update(choices=display_title, interactive=True, visible=True), gr.update(choices=input_sentences, interactive=True), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
65
 
66
  def get_highlights(
67
  abstract_text_input,
 
103
  return gr.update(value=name)
104
 
105
  def change_output_highlight(source_sent_choice):
106
+ fname = 'highlight_info.pkl'
107
  # change the output highlight based on the sentence selected from the submission
108
+ if os.path.exists(fname):
109
+ tmp = pickle.load(open(fname, 'rb'))
110
  source_sents = tmp['source_sentences']
111
  highlights = tmp['highlight']
112
  for i, s in enumerate(source_sents):
113
+ #print('changing highlight')
114
  if source_sent_choice == s:
115
  return highlights[str(i)]
116
  else:
117
  return
118
 
119
+ def change_paper(selected_papers_radio):
120
+ # change the paper to show
121
+ fname = 'paper_info.pkl'
122
+ if os.path.exists(fname):
123
+ tmp = pickle.load(open(fname, 'rb'))
124
+ for title, abstract, aff_score in zip(tmp['titles'], tmp['abstracts'], tmp['doc_scores']):
125
+ display_title = '[ %0.3f ] %s'%(aff_score, title)
126
+ if display_title == selected_papers_radio:
127
+ #print('changing paper')
128
+ return title, abstract, aff_score
129
+ else:
130
+ return
131
+
132
  with gr.Blocks() as demo:
133
 
134
  ### INPUT
 
146
  with gr.Row():
147
  compute_btn = gr.Button('Search Similar Papers from the Reviewer')
148
 
149
+ # show multiple papers in radio check box to select from
150
+ with gr.Row():
151
+ selected_papers_radio = gr.Radio(
152
+ choices=[], # will be udpated with the button click
153
+ visible=False, # also will be updated with the button click
154
+ label='Selected Top Papers from the Reviewer'
155
+ )
 
 
156
 
157
  ### PAPER INFORMATION
158
+ with gr.Row(visible=False) as title_row:
159
  with gr.Column(scale=3):
160
  paper_title = gr.Textbox(label='Title', interactive=False)
161
  with gr.Column(scale=1):
162
  affinity= gr.Number(label='Affinity', interactive=False, value=0)
163
+ with gr.Row(visibe=False) as abstract_row:
164
+ paper_abstract = gr.Textbox(label='Abstract', interactive=False, visible=False)
165
 
166
  with gr.Row(visible=False) as explain_button_row:
167
  explain_btn = gr.Button('Show Relevant Parts from Selected Paper')
 
186
  author_id_input
187
  ],
188
  outputs=[
189
+ selected_papers_radio,
 
 
190
  source_sentences,
191
+ title_row,
192
+ paper_abstract,
193
+ explain_button_row,
194
  ]
195
  )
196
 
 
209
  inputs=source_sentences,
210
  outputs=highlight
211
  )
212
+
213
+ selected_papers_radio.change(
214
+ fn=change_paper,
215
+ inputs=selected_papers_radio,
216
+ outputs= [
217
+ paper_title,
218
+ paper_abstract,
219
+ affinity
220
+ ]
221
+ )
222
 
223
  if __name__ == "__main__":
224
  demo.launch()
input_format.py CHANGED
@@ -24,8 +24,6 @@ def get_text_from_url(url, file_path='paper.pdf'):
24
  """
25
  Get text of the paper from a url
26
  """
27
- # TODO check for other valid urls (e.g. semantic scholar)
28
-
29
  ## Check for different URL cases
30
  url_parts = urlparse(url)
31
  # arxiv
 
24
  """
25
  Get text of the paper from a url
26
  """
 
 
27
  ## Check for different URL cases
28
  url_parts = urlparse(url)
29
  # arxiv