elibrowne commited on
Commit
db8fc2d
·
1 Parent(s): 1947dff
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -17,7 +17,7 @@ qIDs = ["mbe_46", "mbe_132", "mbe_287", "mbe_326", "mbe_334", "mbe_389", "mbe_56
17
  mode_options = ["e5", "colbert"]
18
  # Control global variables
19
  step = 0
20
- mode = 0
21
 
22
  def load_user_data(id):
23
  global user_data
@@ -171,12 +171,12 @@ with gr.Blocks(theme = theme) as user_eval:
171
  global current_response
172
  step += 1
173
  # Add user data to the current response
174
- current_response[user_data["modes"][user_data["current"]][mode] + "_scores"].append([e0, e1, e2, e3])
175
  # Next item
176
- if step == len(current_question["top10_" + user_data["modes"][user_data["current"]][mode]]): # should always be 10
177
  # Step 10: all sources
178
  collapsible_string = "<h2> Set of Passages </h2>\n"
179
- for i, passage in enumerate(current_question["top10_" + user_data["modes"][user_data["current"]][mode]]):
180
  collapsible_string += """
181
  <strong>Passage """ + str(i + 1) + """</strong>
182
  <p> """ + passage + """ </p>
@@ -194,7 +194,7 @@ with gr.Blocks(theme = theme) as user_eval:
194
  return {
195
  selection: gr.HTML("""
196
  <h2> Retrieved Passage </h2>
197
- <p> """ + current_question["top10_" + user_data["modes"][user_data["current"]][mode]][step] + "</p>"),
198
  eval_0: gr.Radio(value = None),
199
  eval_1: gr.Slider(value = 3),
200
  eval_2: gr.Slider(value = 3),
@@ -211,11 +211,12 @@ with gr.Blocks(theme = theme) as user_eval:
211
  if step == 11:
212
  # Step 11: guaranteed to be generation
213
  # Add user data to the current response as SET evaluation, which comes before the generation
214
- current_response[user_data["modes"][user_data["current"]][mode] + "_set"] = [e_h, e_s]
 
215
  return {
216
  selection: gr.HTML("""
217
  <h2> Autogenerated Response </h2>
218
- <p>""" + markdown(current_question["generation_" + user_data["modes"][user_data["current"]][mode]]) + "</p>"),
219
  eval_helps: gr.Slider(value = 0),
220
  eval_satisfied: gr.Slider(value = 3)
221
  }
@@ -236,7 +237,8 @@ with gr.Blocks(theme = theme) as user_eval:
236
  # When mode is 1 -> display GP and GP generation, then switch
237
  if step == 12:
238
  # The user just evaluated a generation for mode 1
239
- current_response[user_data["modes"][user_data["current"]][mode] + "_generation"] = [e_h, e_s]
 
240
  return {
241
  selection: gr.HTML("""
242
  <h2> Retrieved Passage </h2>
@@ -348,7 +350,7 @@ with gr.Blocks(theme = theme) as user_eval:
348
  global step
349
  global mode
350
  step = 0
351
- if mode == 0:
352
  mode = 1 # update mode to 1, will restart with same Q, next set of Ps
353
  print("Next set of passages for same question")
354
  return {
@@ -358,7 +360,8 @@ with gr.Blocks(theme = theme) as user_eval:
358
  question: gr.Row(visible = False),
359
  }
360
  else:
361
- mode = 0 # reset mode to 0, will restart with new Q (set up new Q), first set of Ps
 
362
  print("New question")
363
  new_answers = current_question["answers"].copy()
364
  new_answers[current_question["correct_answer_index"]] = "**" + current_question["answers"][current_question["correct_answer_index"]] + "** ✅"
@@ -385,8 +388,8 @@ with gr.Blocks(theme = theme) as user_eval:
385
  + """ + new_answers[3]),
386
  selection: gr.HTML("""
387
  <h2> Retrieved Passage </h2>
388
- <p> """ + current_question["top10_" + user_data["modes"][user_data["current"]][mode]][0] + "</p>")
389
- }
390
 
391
  forward_btn.change(fn = toggle, inputs = None, outputs = [scores_p, scores_g, evals, question, q_text, a, b, c, d, passage_display, selection])
392
 
@@ -417,7 +420,8 @@ with gr.Blocks(theme = theme) as user_eval:
417
  login: gr.Row(visible = False),
418
  selection: gr.HTML("""
419
  <h2> Retrieved Passage </h2>
420
- <p> """ + current_question["top10_" + user_data["modes"][user_data["current"]][mode]][0] + "</p>"),
 
421
  passage_display: gr.Markdown("""
422
  ## Question and Answer
423
  *""" + current_question["question"] +
 
17
  mode_options = ["e5", "colbert"]
18
  # Control global variables
19
  step = 0
20
+ mode = 1
21
 
22
  def load_user_data(id):
23
  global user_data
 
171
  global current_response
172
  step += 1
173
  # Add user data to the current response
174
+ current_response["e5_scores"].append([e0, e1, e2, e3])
175
  # Next item
176
+ if step == len(current_question["top10_e5"]): # should always be 10
177
  # Step 10: all sources
178
  collapsible_string = "<h2> Set of Passages </h2>\n"
179
+ for i, passage in enumerate(current_question["top10_e5"]):
180
  collapsible_string += """
181
  <strong>Passage """ + str(i + 1) + """</strong>
182
  <p> """ + passage + """ </p>
 
194
  return {
195
  selection: gr.HTML("""
196
  <h2> Retrieved Passage </h2>
197
+ <p> """ + current_question["top10_e5"][step] + "</p>"),
198
  eval_0: gr.Radio(value = None),
199
  eval_1: gr.Slider(value = 3),
200
  eval_2: gr.Slider(value = 3),
 
211
  if step == 11:
212
  # Step 11: guaranteed to be generation
213
  # Add user data to the current response as SET evaluation, which comes before the generation
214
+ # CHANGED FROM user_data["modes"][user_data["current"]] + "_set", as are all direct references to top10_e5
215
+ current_response["e5_set"] = [e_h, e_s]
216
  return {
217
  selection: gr.HTML("""
218
  <h2> Autogenerated Response </h2>
219
+ <p>""" + markdown(current_question["generation_e5"]) + "</p>"),
220
  eval_helps: gr.Slider(value = 0),
221
  eval_satisfied: gr.Slider(value = 3)
222
  }
 
237
  # When mode is 1 -> display GP and GP generation, then switch
238
  if step == 12:
239
  # The user just evaluated a generation for mode 1
240
+ # CHANGE from user_data["modes"][user_data["current"]] + "_generation"
241
+ current_response["e5_generation"] = [e_h, e_s]
242
  return {
243
  selection: gr.HTML("""
244
  <h2> Retrieved Passage </h2>
 
350
  global step
351
  global mode
352
  step = 0
353
+ if mode == 0: # temporarily disabled — will never be mode 0
354
  mode = 1 # update mode to 1, will restart with same Q, next set of Ps
355
  print("Next set of passages for same question")
356
  return {
 
360
  question: gr.Row(visible = False),
361
  }
362
  else:
363
+ # reset mode to 0, will restart with new Q (set up new Q), first set of Ps
364
+ # mode = 0 -> RIGHT NOW, ALWAYS 1
365
  print("New question")
366
  new_answers = current_question["answers"].copy()
367
  new_answers[current_question["correct_answer_index"]] = "**" + current_question["answers"][current_question["correct_answer_index"]] + "** ✅"
 
388
  + """ + new_answers[3]),
389
  selection: gr.HTML("""
390
  <h2> Retrieved Passage </h2>
391
+ <p> """ + current_question["top10_e5"][0] + "</p>")
392
+ } # note change from "top10_" + user_data["modes"][user_data["current"]][mode]][0]
393
 
394
  forward_btn.change(fn = toggle, inputs = None, outputs = [scores_p, scores_g, evals, question, q_text, a, b, c, d, passage_display, selection])
395
 
 
420
  login: gr.Row(visible = False),
421
  selection: gr.HTML("""
422
  <h2> Retrieved Passage </h2>
423
+ <p> """ + current_question["top10_e5"][0] + "</p>"),
424
+ # when testing both ColBERT and E5, this was "top10_" + user_data["modes"][user_data["current"]][mode]][0]
425
  passage_display: gr.Markdown("""
426
  ## Question and Answer
427
  *""" + current_question["question"] +