fix bugs
Browse files
__pycache__/live_preview_helpers.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/live_preview_helpers.cpython-310.pyc and b/__pycache__/live_preview_helpers.cpython-310.pyc differ
|
|
|
__pycache__/optim_utils.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/optim_utils.cpython-310.pyc and b/__pycache__/optim_utils.cpython-310.pyc differ
|
|
|
__pycache__/utils.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/utils.cpython-310.pyc and b/__pycache__/utils.cpython-310.pyc differ
|
|
|
app.py
CHANGED
|
@@ -33,7 +33,7 @@ inverted_prompt = ""
|
|
| 33 |
|
| 34 |
VERBAL_MSG = "Please verbally describe why you are satisfied or unsatisfied at the generated images."
|
| 35 |
DEFAULT_SCENARIO = "Product advertisement"
|
| 36 |
-
METHODS = ["
|
| 37 |
MAX_ROUND = 5
|
| 38 |
# intermittent memory
|
| 39 |
counter1, counter2 = 1, 1
|
|
@@ -138,9 +138,9 @@ def check_satisfaction(sim_radio, active_tab):
|
|
| 138 |
counter = counter1 if method == METHODS[0] else counter2
|
| 139 |
|
| 140 |
fully_satisfied_option = ["Satisfied", "Very Satisfied"] # The value to trigger submit
|
| 141 |
-
enable_submit = sim_radio in fully_satisfied_option
|
| 142 |
|
| 143 |
-
return gr.update(interactive=enable_submit)
|
| 144 |
|
| 145 |
def check_participant(participant):
|
| 146 |
if participant == "":
|
|
@@ -208,6 +208,8 @@ def display_scenario(participant, choice):
|
|
| 208 |
dislike_image2: None,
|
| 209 |
history_images1: [],
|
| 210 |
history_images2: [],
|
|
|
|
|
|
|
| 211 |
next_btn1: gr.update(interactive=False),
|
| 212 |
next_btn2: gr.update(interactive=False),
|
| 213 |
redesign_btn1: gr.update(interactive=True),
|
|
@@ -252,17 +254,12 @@ def redesign(participant, scenario, prompt, sim_radio, current_images, history_i
|
|
| 252 |
method = current_task1 if active_tab == "Task A" else current_task2
|
| 253 |
|
| 254 |
if check_evaluation(sim_radio) and check_participant(participant):
|
| 255 |
-
if method == METHODS[0]:
|
| 256 |
-
counter1 += 1
|
| 257 |
-
counter = counter1
|
| 258 |
-
else:
|
| 259 |
-
counter2 += 1
|
| 260 |
-
counter = counter2
|
| 261 |
|
| 262 |
-
|
| 263 |
-
responses_memory[participant][method][counter
|
| 264 |
-
responses_memory[participant][method][counter
|
| 265 |
-
|
|
|
|
| 266 |
|
| 267 |
history_prompts = [[v["prompt"]] for v in responses_memory[participant][method].values()]
|
| 268 |
if not history_images:
|
|
@@ -276,6 +273,13 @@ def redesign(participant, scenario, prompt, sim_radio, current_images, history_i
|
|
| 276 |
redesign_state = gr.update(interactive=False) if counter >= MAX_ROUND else gr.update(interactive=True)
|
| 277 |
submit_state = gr.update(interactive=True) if counter >= MAX_ROUND else gr.update(interactive=False)
|
| 278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
return None, None, None, current_images, history_images, examples_state, prompt_state, next_state, redesign_state, submit_state
|
| 280 |
else:
|
| 281 |
return {submit_btn1: gr.skip()} if active_tab == "Task A" else {submit_btn2: gr.skip()}
|
|
@@ -299,7 +303,7 @@ def save_response(participant, scenario, prompt, sim_radio, active_tab):
|
|
| 299 |
sheet = gc.open("DiverseGen-phase3").sheet1
|
| 300 |
|
| 301 |
for i, entry in responses_memory[participant][method].items():
|
| 302 |
-
sheet.append_row([participant, scenario, method, i, entry["prompt"], entry["sim_radio"]])
|
| 303 |
|
| 304 |
display_info_message("✅ Your answer is saved!")
|
| 305 |
|
|
@@ -312,17 +316,18 @@ def save_response(participant, scenario, prompt, sim_radio, active_tab):
|
|
| 312 |
task1_success = True
|
| 313 |
else:
|
| 314 |
task2_success = True
|
|
|
|
| 315 |
# decide if change scenario
|
| 316 |
next_scenario = assigned_scenarios[1] if task1_success and task2_success else assigned_scenarios[0]
|
| 317 |
-
|
| 318 |
-
|
| 319 |
prompt_state = gr.update(interactive=False)
|
| 320 |
next_state = gr.update(visible=False, interactive=False)
|
| 321 |
submit_state = gr.update(interactive=False)
|
| 322 |
redesign_state = gr.update(interactive=False)
|
| 323 |
tabs = switch_tab(active_tab)
|
| 324 |
|
| 325 |
-
return None, None, None,
|
| 326 |
|
| 327 |
except Exception as e:
|
| 328 |
display_error_message(f"❌ Error saving response: {str(e)}")
|
|
@@ -501,14 +506,14 @@ with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Inconsolata"), "
|
|
| 501 |
participant.change(fn=set_user, inputs=[participant], outputs=[scenario])
|
| 502 |
scenario.change(display_scenario,
|
| 503 |
inputs=[participant, scenario],
|
| 504 |
-
outputs=[scenario_content, prompt1, prompt2, images_method1, images_method2, like_image1, dislike_image1, like_image2, dislike_image2, history_images1, history_images2, next_btn1, next_btn2, redesign_btn1, redesign_btn2, submit_btn1, submit_btn2])
|
| 505 |
|
| 506 |
# prompt1.change(fn=reset_gallery, inputs=[], outputs=[gallery_state1])
|
| 507 |
# prompt2.change(fn=reset_gallery, inputs=[], outputs=[gallery_state2])
|
| 508 |
next_btn1.click(fn=generate_image, inputs=[participant, scenario, prompt1, active_tab, like_image1, dislike_image1], outputs=[images_method1])
|
| 509 |
next_btn2.click(fn=generate_image, inputs=[participant, scenario, prompt2, active_tab, like_image2, dislike_image2], outputs=[images_method2])
|
| 510 |
-
sim_radio1.change(fn=check_satisfaction, inputs=[sim_radio1, active_tab], outputs=[submit_btn1
|
| 511 |
-
sim_radio2.change(fn=check_satisfaction, inputs=[sim_radio2, active_tab], outputs=[submit_btn2
|
| 512 |
dislike_radio1.select(fn=select_image, inputs=[dislike_radio1, images_method1], outputs=[dislike_image1])
|
| 513 |
like_radio1.select(fn=select_image, inputs=[like_radio1, images_method1], outputs=[like_image1])
|
| 514 |
dislike_radio2.select(fn=select_image, inputs=[dislike_radio2, images_method2], outputs=[dislike_image2])
|
|
@@ -526,11 +531,11 @@ with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Inconsolata"), "
|
|
| 526 |
)
|
| 527 |
submit_btn1.click(fn=save_response,
|
| 528 |
inputs=[participant, scenario, prompt1, sim_radio1, active_tab],
|
| 529 |
-
outputs=[sim_radio1, dislike_radio1, like_radio1,
|
| 530 |
|
| 531 |
submit_btn2.click(fn=save_response,
|
| 532 |
inputs=[participant, scenario, prompt2, sim_radio2, active_tab],
|
| 533 |
-
outputs=[sim_radio2, dislike_radio2, like_radio2,
|
| 534 |
|
| 535 |
|
| 536 |
if __name__ == "__main__":
|
|
|
|
| 33 |
|
| 34 |
VERBAL_MSG = "Please verbally describe why you are satisfied or unsatisfied at the generated images."
|
| 35 |
DEFAULT_SCENARIO = "Product advertisement"
|
| 36 |
+
METHODS = ["Baseline", "Experimental"]
|
| 37 |
MAX_ROUND = 5
|
| 38 |
# intermittent memory
|
| 39 |
counter1, counter2 = 1, 1
|
|
|
|
| 138 |
counter = counter1 if method == METHODS[0] else counter2
|
| 139 |
|
| 140 |
fully_satisfied_option = ["Satisfied", "Very Satisfied"] # The value to trigger submit
|
| 141 |
+
enable_submit = sim_radio in fully_satisfied_option
|
| 142 |
|
| 143 |
+
return gr.update(interactive=enable_submit)
|
| 144 |
|
| 145 |
def check_participant(participant):
|
| 146 |
if participant == "":
|
|
|
|
| 208 |
dislike_image2: None,
|
| 209 |
history_images1: [],
|
| 210 |
history_images2: [],
|
| 211 |
+
example1.dataset: gr.update(samples=[], visible=False),
|
| 212 |
+
example2.dataset: gr.update(samples=[], visible=False),
|
| 213 |
next_btn1: gr.update(interactive=False),
|
| 214 |
next_btn2: gr.update(interactive=False),
|
| 215 |
redesign_btn1: gr.update(interactive=True),
|
|
|
|
| 254 |
method = current_task1 if active_tab == "Task A" else current_task2
|
| 255 |
|
| 256 |
if check_evaluation(sim_radio) and check_participant(participant):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
+
|
| 259 |
+
responses_memory[participant][method][counter] = {}
|
| 260 |
+
responses_memory[participant][method][counter]["prompt"] = prompt
|
| 261 |
+
responses_memory[participant][method][counter]["sim_radio"] = sim_radio
|
| 262 |
+
# responses_memory[participant][method][counter]["response"] = response
|
| 263 |
|
| 264 |
history_prompts = [[v["prompt"]] for v in responses_memory[participant][method].values()]
|
| 265 |
if not history_images:
|
|
|
|
| 273 |
redesign_state = gr.update(interactive=False) if counter >= MAX_ROUND else gr.update(interactive=True)
|
| 274 |
submit_state = gr.update(interactive=True) if counter >= MAX_ROUND else gr.update(interactive=False)
|
| 275 |
|
| 276 |
+
if method == METHODS[0]:
|
| 277 |
+
counter1 += 1
|
| 278 |
+
counter = counter1
|
| 279 |
+
else:
|
| 280 |
+
counter2 += 1
|
| 281 |
+
counter = counter2
|
| 282 |
+
|
| 283 |
return None, None, None, current_images, history_images, examples_state, prompt_state, next_state, redesign_state, submit_state
|
| 284 |
else:
|
| 285 |
return {submit_btn1: gr.skip()} if active_tab == "Task A" else {submit_btn2: gr.skip()}
|
|
|
|
| 303 |
sheet = gc.open("DiverseGen-phase3").sheet1
|
| 304 |
|
| 305 |
for i, entry in responses_memory[participant][method].items():
|
| 306 |
+
sheet.append_row([participant, scenario, f"{active_tab}, {method}", i, entry["prompt"], entry["sim_radio"]])
|
| 307 |
|
| 308 |
display_info_message("✅ Your answer is saved!")
|
| 309 |
|
|
|
|
| 316 |
task1_success = True
|
| 317 |
else:
|
| 318 |
task2_success = True
|
| 319 |
+
|
| 320 |
# decide if change scenario
|
| 321 |
next_scenario = assigned_scenarios[1] if task1_success and task2_success else assigned_scenarios[0]
|
| 322 |
+
|
| 323 |
+
# reset buttons
|
| 324 |
prompt_state = gr.update(interactive=False)
|
| 325 |
next_state = gr.update(visible=False, interactive=False)
|
| 326 |
submit_state = gr.update(interactive=False)
|
| 327 |
redesign_state = gr.update(interactive=False)
|
| 328 |
tabs = switch_tab(active_tab)
|
| 329 |
|
| 330 |
+
return None, None, None, prompt_state, next_state, redesign_state, submit_state, next_scenario, tabs
|
| 331 |
|
| 332 |
except Exception as e:
|
| 333 |
display_error_message(f"❌ Error saving response: {str(e)}")
|
|
|
|
| 506 |
participant.change(fn=set_user, inputs=[participant], outputs=[scenario])
|
| 507 |
scenario.change(display_scenario,
|
| 508 |
inputs=[participant, scenario],
|
| 509 |
+
outputs=[scenario_content, prompt1, prompt2, images_method1, images_method2, like_image1, dislike_image1, like_image2, dislike_image2, history_images1, history_images2, example1.dataset, example2.dataset, next_btn1, next_btn2, redesign_btn1, redesign_btn2, submit_btn1, submit_btn2])
|
| 510 |
|
| 511 |
# prompt1.change(fn=reset_gallery, inputs=[], outputs=[gallery_state1])
|
| 512 |
# prompt2.change(fn=reset_gallery, inputs=[], outputs=[gallery_state2])
|
| 513 |
next_btn1.click(fn=generate_image, inputs=[participant, scenario, prompt1, active_tab, like_image1, dislike_image1], outputs=[images_method1])
|
| 514 |
next_btn2.click(fn=generate_image, inputs=[participant, scenario, prompt2, active_tab, like_image2, dislike_image2], outputs=[images_method2])
|
| 515 |
+
sim_radio1.change(fn=check_satisfaction, inputs=[sim_radio1, active_tab], outputs=[submit_btn1])
|
| 516 |
+
sim_radio2.change(fn=check_satisfaction, inputs=[sim_radio2, active_tab], outputs=[submit_btn2])
|
| 517 |
dislike_radio1.select(fn=select_image, inputs=[dislike_radio1, images_method1], outputs=[dislike_image1])
|
| 518 |
like_radio1.select(fn=select_image, inputs=[like_radio1, images_method1], outputs=[like_image1])
|
| 519 |
dislike_radio2.select(fn=select_image, inputs=[dislike_radio2, images_method2], outputs=[dislike_image2])
|
|
|
|
| 531 |
)
|
| 532 |
submit_btn1.click(fn=save_response,
|
| 533 |
inputs=[participant, scenario, prompt1, sim_radio1, active_tab],
|
| 534 |
+
outputs=[sim_radio1, dislike_radio1, like_radio1, prompt1, next_btn1, redesign_btn1, submit_btn1, scenario, tabs])
|
| 535 |
|
| 536 |
submit_btn2.click(fn=save_response,
|
| 537 |
inputs=[participant, scenario, prompt2, sim_radio2, active_tab],
|
| 538 |
+
outputs=[sim_radio2, dislike_radio2, like_radio2, prompt2, next_btn2, redesign_btn2, submit_btn2, scenario, tabs])
|
| 539 |
|
| 540 |
|
| 541 |
if __name__ == "__main__":
|