xh365 commited on
Commit
de22521
Β·
1 Parent(s): 9cf98ec

preference images update

Browse files
__pycache__/live_preview_helpers.cpython-310.pyc ADDED
Binary file (4.54 kB). View file
 
__pycache__/optim_utils.cpython-310.pyc ADDED
Binary file (6.04 kB). View file
 
__pycache__/utils.cpython-310.pyc ADDED
Binary file (7.19 kB). View file
 
app.py CHANGED
@@ -8,7 +8,7 @@ import re
8
  import open_clip
9
  from optim_utils import optimize_prompt
10
  from utils import clean_response_gpt, setup_model, init_gpt_api, call_gpt_api, get_refine_msg, clean_cache
11
- from utils import SCENARIOS, PROMPTS, IMAGES, OPTIONS, T2I_MODELS, INSTRUCTION
12
  import spaces #[uncomment to use ZeroGPU]
13
  import transformers
14
  import gspread
@@ -274,6 +274,18 @@ def check_evaluation(sim_radio, response):
274
 
275
  return True
276
 
 
 
 
 
 
 
 
 
 
 
 
 
277
  def redesign(participant, scenario, prompt, sim_radio, response, images_method, active_tab):
278
  global counter1, counter2, responses_memory, current_task1, current_task2
279
  method = current_task1 if active_tab == "Task A" else current_task2
@@ -367,6 +379,11 @@ css="""
367
  max-width: 1000px;
368
  }
369
 
 
 
 
 
 
370
  #button-container {
371
  display: flex;
372
  justify-content: center; /* Centers the buttons horizontally */
@@ -418,17 +435,34 @@ with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Inconsolata"), "
418
  )
419
  next_btn1 = gr.Button("Generate", variant="primary", scale=1, interactive=False, visible=False)
420
 
421
- with gr.Column(elem_id="col-container"):
422
- gallery_state1 = gr.State(IMAGES[DEFAULT_SCENARIO]["baseline"])
423
- images_method1 = gr.Gallery(show_label=False, columns=[4], rows=[1], elem_id="gallery")
 
 
 
 
424
  with gr.Column(elem_id="col-container2"):
425
  gr.Markdown("### πŸ“ Evaluation")
426
  sim_radio1 = gr.Radio(
427
  OPTIONS,
428
- label="How would you evaluate your satisfaction with the generated images, based on your expectations for the specified scenario?",
 
 
 
 
 
 
 
 
 
 
 
 
429
  type="value",
430
  elem_classes=["gradio-radio"]
431
  )
 
432
  response1 = gr.Textbox(
433
  label="Verbally describe key differences found in the image pair.",
434
  max_lines=1,
@@ -455,21 +489,37 @@ with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Inconsolata"), "
455
  scale=4,
456
  visible=False
457
  )
458
-
459
  next_btn2 = gr.Button("Generate", variant="primary", scale=1, interactive=False, visible=False)
460
 
461
- with gr.Column(elem_id="col-container"):
462
- gallery_state2 = gr.State(IMAGES[DEFAULT_SCENARIO]["ours"])
463
- images_method2 = gr.Gallery(show_label=False, columns=[4], rows=[1], elem_id="gallery")
 
 
 
 
464
 
465
  with gr.Column(elem_id="col-container2"):
466
  gr.Markdown("### πŸ“ Evaluation")
467
  sim_radio2 = gr.Radio(
468
  OPTIONS,
469
- label="How would you evaluate your satisfaction with the generated images, based on your expectations for the specified scenario?",
 
 
 
 
 
 
470
  type="value",
471
  elem_classes=["gradio-radio"]
472
  )
 
 
 
 
 
 
 
473
  response2 = gr.Textbox(
474
  label="Verbally describe key differences found in the image pair.",
475
  max_lines=1,
@@ -494,6 +544,11 @@ with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Inconsolata"), "
494
  next_btn2.click(fn=generate_image, inputs=[participant, scenario, prompt2, gallery_state2, active_tab], outputs=[images_method2])
495
  sim_radio1.change(fn=check_satisfaction, inputs=[sim_radio1, active_tab], outputs=[submit_btn1, redesign_btn1])
496
  sim_radio2.change(fn=check_satisfaction, inputs=[sim_radio2, active_tab], outputs=[submit_btn2, redesign_btn2])
 
 
 
 
 
497
  redesign_btn1.click(
498
  fn=redesign,
499
  inputs=[participant, scenario, prompt1, sim_radio1, response1, images_method1, active_tab],
 
8
  import open_clip
9
  from optim_utils import optimize_prompt
10
  from utils import clean_response_gpt, setup_model, init_gpt_api, call_gpt_api, get_refine_msg, clean_cache
11
+ from utils import SCENARIOS, PROMPTS, IMAGES, OPTIONS, T2I_MODELS, INSTRUCTION, IMAGE_OPTIONS
12
  import spaces #[uncomment to use ZeroGPU]
13
  import transformers
14
  import gspread
 
274
 
275
  return True
276
 
277
+ def select_dislike(like_radio, images_method):
278
+ if like_radio == IMAGE_OPTIONS[0]:
279
+ return images_method[0]
280
+ elif like_radio == IMAGE_OPTIONS[1]:
281
+ return images_method[1]
282
+ elif like_radio == IMAGE_OPTIONS[2]:
283
+ return images_method[2]
284
+ elif like_radio == IMAGE_OPTIONS[3]:
285
+ return images_method[3]
286
+ else:
287
+ return None
288
+
289
  def redesign(participant, scenario, prompt, sim_radio, response, images_method, active_tab):
290
  global counter1, counter2, responses_memory, current_task1, current_task2
291
  method = current_task1 if active_tab == "Task A" else current_task2
 
379
  max-width: 1000px;
380
  }
381
 
382
+ #col-container3 {
383
+ margin: 0 auto;
384
+ max-width: 300px;
385
+ }
386
+
387
  #button-container {
388
  display: flex;
389
  justify-content: center; /* Centers the buttons horizontally */
 
435
  )
436
  next_btn1 = gr.Button("Generate", variant="primary", scale=1, interactive=False, visible=False)
437
 
438
+ with gr.Row():
439
+ with gr.Column(elem_id="col-container"):
440
+ gallery_state1 = gr.State([])
441
+ images_method1 = gr.Gallery(show_label=False, columns=[4], rows=[1], height=420, elem_id="gallery")
442
+ with gr.Column(elem_id="col-container3"):
443
+ like_image1 = gr.Image(label="Satisfied Image", width=200, height=200, sources='upload')
444
+ dislike_image1 = gr.Image(label="Unsatisfied Image", width=200, height=200, sources='upload')
445
  with gr.Column(elem_id="col-container2"):
446
  gr.Markdown("### πŸ“ Evaluation")
447
  sim_radio1 = gr.Radio(
448
  OPTIONS,
449
+ label="How would you rate your satisfaction with the generated images, based on your expectations for the specified scenario?",
450
+ type="value",
451
+ elem_classes=["gradio-radio"]
452
+ )
453
+ like_radio1 = gr.Radio(
454
+ IMAGE_OPTIONS,
455
+ label="Select the image you are most satisfied.",
456
+ type="value",
457
+ elem_classes=["gradio-radio"]
458
+ )
459
+ dislike_radio1 = gr.Radio(
460
+ IMAGE_OPTIONS,
461
+ label="Select the image you are most unsatisfied.",
462
  type="value",
463
  elem_classes=["gradio-radio"]
464
  )
465
+
466
  response1 = gr.Textbox(
467
  label="Verbally describe key differences found in the image pair.",
468
  max_lines=1,
 
489
  scale=4,
490
  visible=False
491
  )
 
492
  next_btn2 = gr.Button("Generate", variant="primary", scale=1, interactive=False, visible=False)
493
 
494
+ with gr.Row():
495
+ with gr.Column(elem_id="col-container"):
496
+ gallery_state2 = gr.State(IMAGES[DEFAULT_SCENARIO]["ours"])
497
+ images_method2 = gr.Gallery(height=420, show_label=False, columns=[4], rows=[1], elem_id="gallery")
498
+ with gr.Column(elem_id="col-container3"):
499
+ like_image2 = gr.Image(label="Satisfied Image", width=200, height=200, sources='upload')
500
+ dislike_image2 = gr.Image(label="Unsatisfied Image", width=200, height=200, sources='upload')
501
 
502
  with gr.Column(elem_id="col-container2"):
503
  gr.Markdown("### πŸ“ Evaluation")
504
  sim_radio2 = gr.Radio(
505
  OPTIONS,
506
+ label="How would you rate your satisfaction with the generated images, based on your expectations for the specified scenario?",
507
+ type="value",
508
+ elem_classes=["gradio-radio"]
509
+ )
510
+ like_radio2 = gr.Radio(
511
+ IMAGE_OPTIONS,
512
+ label="Select the image you are most satisfied.",
513
  type="value",
514
  elem_classes=["gradio-radio"]
515
  )
516
+ dislike_radio2 = gr.Radio(
517
+ IMAGE_OPTIONS,
518
+ label="Select the image you are most unsatisfied.",
519
+ type="value",
520
+ elem_classes=["gradio-radio"]
521
+ )
522
+
523
  response2 = gr.Textbox(
524
  label="Verbally describe key differences found in the image pair.",
525
  max_lines=1,
 
544
  next_btn2.click(fn=generate_image, inputs=[participant, scenario, prompt2, gallery_state2, active_tab], outputs=[images_method2])
545
  sim_radio1.change(fn=check_satisfaction, inputs=[sim_radio1, active_tab], outputs=[submit_btn1, redesign_btn1])
546
  sim_radio2.change(fn=check_satisfaction, inputs=[sim_radio2, active_tab], outputs=[submit_btn2, redesign_btn2])
547
+ dislike_radio1.select(fn=select_dislike, inputs=[dislike_radio1, gallery_state1], outputs=[dislike_image1])
548
+ like_radio1.select(fn=select_dislike, inputs=[like_radio1, gallery_state1], outputs=[like_image1])
549
+ dislike_radio2.select(fn=select_dislike, inputs=[dislike_radio2, gallery_state2], outputs=[dislike_image2])
550
+ like_radio2.select(fn=select_dislike, inputs=[like_radio2, gallery_state2], outputs=[like_image2])
551
+
552
  redesign_btn1.click(
553
  fn=redesign,
554
  inputs=[participant, scenario, prompt1, sim_radio1, response1, images_method1, active_tab],
utils.py CHANGED
@@ -43,7 +43,7 @@ IMAGES = {
43
  }
44
 
45
  OPTIONS = ["Very Unsatisfied", "Unsatisfied", "Slightly Unsatisfied", "Neutral", "Slightly Satisfied", "Satisfied", "Very Satisfied"]
46
-
47
  INSTRUCTION = "πŸ“Œ **Instruction**: Now, we want to understand your satisfaction with the images generated. <br /> πŸ“Œ Step 1: You will start from evaluating the following images based on the given prompt. <br /> πŸ“Œ Step 2: Then please modify the prompt according to your expectations for the given scenario background, and answer the evaluation question **until you are satisfied** with at least one of the images generated below. If you are not satisfied with the generated images, you can repeatedly modify the prompts for at most **5 times**."
48
  def clean_cache():
49
  subprocess.run("rm -rf /data-nvme/zerogpu-offload/*", env={}, shell=True)
 
43
  }
44
 
45
  OPTIONS = ["Very Unsatisfied", "Unsatisfied", "Slightly Unsatisfied", "Neutral", "Slightly Satisfied", "Satisfied", "Very Satisfied"]
46
+ IMAGE_OPTIONS = ["First Image", "Second Image", "Third Image", "Fourth Image", "None of them"]
47
  INSTRUCTION = "πŸ“Œ **Instruction**: Now, we want to understand your satisfaction with the images generated. <br /> πŸ“Œ Step 1: You will start from evaluating the following images based on the given prompt. <br /> πŸ“Œ Step 2: Then please modify the prompt according to your expectations for the given scenario background, and answer the evaluation question **until you are satisfied** with at least one of the images generated below. If you are not satisfied with the generated images, you can repeatedly modify the prompts for at most **5 times**."
48
  def clean_cache():
49
  subprocess.run("rm -rf /data-nvme/zerogpu-offload/*", env={}, shell=True)