fix bug on counter, image
Browse files- __pycache__/utils.cpython-310.pyc +0 -0
- app.py +30 -16
- utils.py +1 -1
__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
|
@@ -42,7 +42,7 @@ responses_memory = {}
|
|
| 42 |
assigned_scenarios = list(SCENARIOS.keys())[:2]
|
| 43 |
current_task1, current_task2 = METHODS # current task 1 (tab 1)
|
| 44 |
task1_success, task2_success = False, False
|
| 45 |
-
|
| 46 |
|
| 47 |
########################################################################################################
|
| 48 |
# Generating images with two methods
|
|
@@ -134,13 +134,14 @@ def switch_tab(active_tab):
|
|
| 134 |
return gr.Tabs(selected="Task A")
|
| 135 |
|
| 136 |
def check_satisfaction(sim_radio, active_tab):
|
| 137 |
-
global
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
fully_satisfied_option = ["Satisfied", "Very Satisfied"] # The value to trigger submit
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
return gr.update(interactive=True)
|
| 142 |
-
else:
|
| 143 |
-
return gr.skip()
|
| 144 |
|
| 145 |
def check_participant(participant):
|
| 146 |
if participant == "":
|
|
@@ -180,10 +181,10 @@ def set_user(participant):
|
|
| 180 |
|
| 181 |
def display_scenario(participant, choice):
|
| 182 |
# reset intermittent storage when scenario change
|
| 183 |
-
global counter1, counter2, responses_memory, current_task1, current_task2, task1_success, task2_success,
|
| 184 |
-
|
| 185 |
task1_success, task2_success = False, False
|
| 186 |
-
|
| 187 |
counter1, counter2 = 1, 1
|
| 188 |
|
| 189 |
if check_participant(participant):
|
|
@@ -251,11 +252,12 @@ def generate_image(participant, scenario, prompt, active_tab, like_image, dislik
|
|
| 251 |
yield gallery_images
|
| 252 |
|
| 253 |
def redesign(participant, scenario, prompt, sim_radio, like_radio, dislike_radio, current_images, history_images, active_tab):
|
| 254 |
-
global counter1, counter2, responses_memory, current_task1, current_task2
|
| 255 |
method = current_task1 if active_tab == "Task A" else current_task2
|
| 256 |
|
| 257 |
if check_evaluation(sim_radio) and check_participant(participant):
|
| 258 |
counter = counter1 if method == METHODS[0] else counter2
|
|
|
|
| 259 |
|
| 260 |
responses_memory[participant][method][counter] = {}
|
| 261 |
responses_memory[participant][method][counter]["prompt"] = prompt
|
|
@@ -264,6 +266,8 @@ def redesign(participant, scenario, prompt, sim_radio, like_radio, dislike_radio
|
|
| 264 |
responses_memory[participant][method][counter]["satisfied_img"] = f"round {counter}, {like_radio}"
|
| 265 |
responses_memory[participant][method][counter]["unsatisfied_img"] = f"round {counter}, {dislike_radio}"
|
| 266 |
|
|
|
|
|
|
|
| 267 |
history_prompts = [[v["prompt"]] for v in responses_memory[participant][method].values()]
|
| 268 |
if not history_images:
|
| 269 |
history_images = current_images
|
|
@@ -280,8 +284,10 @@ def redesign(participant, scenario, prompt, sim_radio, like_radio, dislike_radio
|
|
| 280 |
# update counter
|
| 281 |
if method == METHODS[0]:
|
| 282 |
counter1 += 1
|
|
|
|
| 283 |
else:
|
| 284 |
counter2 += 1
|
|
|
|
| 285 |
|
| 286 |
return None, None, None, current_images, history_images, examples_state, prompt_state, next_state, redesign_state, submit_state
|
| 287 |
else:
|
|
@@ -290,7 +296,7 @@ def redesign(participant, scenario, prompt, sim_radio, like_radio, dislike_radio
|
|
| 290 |
|
| 291 |
def save_response(participant, scenario, prompt, sim_radio, like_radio, dislike_radio, active_tab):
|
| 292 |
global current_task1, current_task2 # not change
|
| 293 |
-
global task1_success, task2_success, counter1, counter2,
|
| 294 |
|
| 295 |
method = current_task1 if active_tab == "Task A" else current_task2
|
| 296 |
if check_evaluation(sim_radio) and check_participant(participant):
|
|
@@ -303,7 +309,6 @@ def save_response(participant, scenario, prompt, sim_radio, like_radio, dislike_
|
|
| 303 |
responses_memory[participant][method][counter]["satisfied_img"] = f"round {counter}, {like_radio}"
|
| 304 |
responses_memory[participant][method][counter]["unsatisfied_img"] = f"round {counter}, {dislike_radio}"
|
| 305 |
|
| 306 |
-
|
| 307 |
try:
|
| 308 |
gc = gspread.service_account(filename='credentials.json')
|
| 309 |
sheet = gc.open("DiverseGen-phase3").sheet1
|
|
@@ -316,16 +321,25 @@ def save_response(participant, scenario, prompt, sim_radio, like_radio, dislike_
|
|
| 316 |
# reset global variables
|
| 317 |
if method == METHODS[0]:
|
| 318 |
counter1 = 1
|
|
|
|
| 319 |
else:
|
| 320 |
counter2 = 1
|
|
|
|
| 321 |
if active_tab == "Task A":
|
| 322 |
task1_success = True
|
| 323 |
else:
|
| 324 |
task2_success = True
|
| 325 |
-
|
| 326 |
|
| 327 |
# decide if change scenario
|
| 328 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
|
| 330 |
# reset buttons
|
| 331 |
prompt_state = gr.update(interactive=False)
|
|
@@ -520,7 +534,7 @@ with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Inconsolata"), "
|
|
| 520 |
next_btn1.click(fn=generate_image, inputs=[participant, scenario, prompt1, active_tab, like_image1, dislike_image1], outputs=[images_method1])
|
| 521 |
next_btn2.click(fn=generate_image, inputs=[participant, scenario, prompt2, active_tab, like_image2, dislike_image2], outputs=[images_method2])
|
| 522 |
sim_radio1.change(fn=check_satisfaction, inputs=[sim_radio1, active_tab], outputs=[submit_btn1])
|
| 523 |
-
sim_radio2.change(fn=check_satisfaction, inputs=[sim_radio2, active_tab], outputs=[
|
| 524 |
dislike_radio1.select(fn=select_image, inputs=[dislike_radio1, images_method1], outputs=[dislike_image1])
|
| 525 |
like_radio1.select(fn=select_image, inputs=[like_radio1, images_method1], outputs=[like_image1])
|
| 526 |
dislike_radio2.select(fn=select_image, inputs=[dislike_radio2, images_method2], outputs=[dislike_image2])
|
|
|
|
| 42 |
assigned_scenarios = list(SCENARIOS.keys())[:2]
|
| 43 |
current_task1, current_task2 = METHODS # current task 1 (tab 1)
|
| 44 |
task1_success, task2_success = False, False
|
| 45 |
+
enable_submit1, enable_submit2 = False, False
|
| 46 |
|
| 47 |
########################################################################################################
|
| 48 |
# Generating images with two methods
|
|
|
|
| 134 |
return gr.Tabs(selected="Task A")
|
| 135 |
|
| 136 |
def check_satisfaction(sim_radio, active_tab):
|
| 137 |
+
global enable_submit1, enable_submit2, counter1, counter2
|
| 138 |
+
method = current_task1 if active_tab == "Task A" else current_task2
|
| 139 |
+
enable_submit = enable_submit1 if method == METHODS[0] else enable_submit2
|
| 140 |
+
counter = counter1 if method == METHODS[0] else counter2
|
| 141 |
+
|
| 142 |
fully_satisfied_option = ["Satisfied", "Very Satisfied"] # The value to trigger submit
|
| 143 |
+
if_submit = sim_radio in fully_satisfied_option or enable_submit or counter > MAX_ROUND
|
| 144 |
+
return gr.update(interactive=if_submit)
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
def check_participant(participant):
|
| 147 |
if participant == "":
|
|
|
|
| 181 |
|
| 182 |
def display_scenario(participant, choice):
|
| 183 |
# reset intermittent storage when scenario change
|
| 184 |
+
global counter1, counter2, responses_memory, current_task1, current_task2, task1_success, task2_success, enable_submit1, enable_submit2
|
| 185 |
+
|
| 186 |
task1_success, task2_success = False, False
|
| 187 |
+
enable_submit1, enable_submit2 = False, False
|
| 188 |
counter1, counter2 = 1, 1
|
| 189 |
|
| 190 |
if check_participant(participant):
|
|
|
|
| 252 |
yield gallery_images
|
| 253 |
|
| 254 |
def redesign(participant, scenario, prompt, sim_radio, like_radio, dislike_radio, current_images, history_images, active_tab):
|
| 255 |
+
global counter1, counter2, responses_memory, current_task1, current_task2, enable_submit1, enable_submit2
|
| 256 |
method = current_task1 if active_tab == "Task A" else current_task2
|
| 257 |
|
| 258 |
if check_evaluation(sim_radio) and check_participant(participant):
|
| 259 |
counter = counter1 if method == METHODS[0] else counter2
|
| 260 |
+
enable_submit = enable_submit1 if method == METHODS[0] else enable_submit2
|
| 261 |
|
| 262 |
responses_memory[participant][method][counter] = {}
|
| 263 |
responses_memory[participant][method][counter]["prompt"] = prompt
|
|
|
|
| 266 |
responses_memory[participant][method][counter]["satisfied_img"] = f"round {counter}, {like_radio}"
|
| 267 |
responses_memory[participant][method][counter]["unsatisfied_img"] = f"round {counter}, {dislike_radio}"
|
| 268 |
|
| 269 |
+
enable_submit = True if sim_radio in ["Satisfied", "Very Satisfied"] or enable_submit else False
|
| 270 |
+
|
| 271 |
history_prompts = [[v["prompt"]] for v in responses_memory[participant][method].values()]
|
| 272 |
if not history_images:
|
| 273 |
history_images = current_images
|
|
|
|
| 284 |
# update counter
|
| 285 |
if method == METHODS[0]:
|
| 286 |
counter1 += 1
|
| 287 |
+
enable_submit1 = enable_submit
|
| 288 |
else:
|
| 289 |
counter2 += 1
|
| 290 |
+
enable_submit2 = enable_submit
|
| 291 |
|
| 292 |
return None, None, None, current_images, history_images, examples_state, prompt_state, next_state, redesign_state, submit_state
|
| 293 |
else:
|
|
|
|
| 296 |
|
| 297 |
def save_response(participant, scenario, prompt, sim_radio, like_radio, dislike_radio, active_tab):
|
| 298 |
global current_task1, current_task2 # not change
|
| 299 |
+
global task1_success, task2_success, counter1, counter2, enable_submit1, enable_submit2, responses_memory, assigned_scenarios # will change
|
| 300 |
|
| 301 |
method = current_task1 if active_tab == "Task A" else current_task2
|
| 302 |
if check_evaluation(sim_radio) and check_participant(participant):
|
|
|
|
| 309 |
responses_memory[participant][method][counter]["satisfied_img"] = f"round {counter}, {like_radio}"
|
| 310 |
responses_memory[participant][method][counter]["unsatisfied_img"] = f"round {counter}, {dislike_radio}"
|
| 311 |
|
|
|
|
| 312 |
try:
|
| 313 |
gc = gspread.service_account(filename='credentials.json')
|
| 314 |
sheet = gc.open("DiverseGen-phase3").sheet1
|
|
|
|
| 321 |
# reset global variables
|
| 322 |
if method == METHODS[0]:
|
| 323 |
counter1 = 1
|
| 324 |
+
enable_submit1 = False
|
| 325 |
else:
|
| 326 |
counter2 = 1
|
| 327 |
+
enable_submit2 = False
|
| 328 |
if active_tab == "Task A":
|
| 329 |
task1_success = True
|
| 330 |
else:
|
| 331 |
task2_success = True
|
| 332 |
+
|
| 333 |
|
| 334 |
# decide if change scenario
|
| 335 |
+
if scenario == assigned_scenarios[0]:
|
| 336 |
+
next_scenario = assigned_scenarios[1] if task1_success and task2_success else assigned_scenarios[0]
|
| 337 |
+
else:
|
| 338 |
+
if task1_success and task2_success:
|
| 339 |
+
display_info_message("You have finished all scenarios, thank you!")
|
| 340 |
+
next_scenario = assigned_scenarios[0]
|
| 341 |
+
else:
|
| 342 |
+
next_scenario = assigned_scenarios[1]
|
| 343 |
|
| 344 |
# reset buttons
|
| 345 |
prompt_state = gr.update(interactive=False)
|
|
|
|
| 534 |
next_btn1.click(fn=generate_image, inputs=[participant, scenario, prompt1, active_tab, like_image1, dislike_image1], outputs=[images_method1])
|
| 535 |
next_btn2.click(fn=generate_image, inputs=[participant, scenario, prompt2, active_tab, like_image2, dislike_image2], outputs=[images_method2])
|
| 536 |
sim_radio1.change(fn=check_satisfaction, inputs=[sim_radio1, active_tab], outputs=[submit_btn1])
|
| 537 |
+
sim_radio2.change(fn=check_satisfaction, inputs=[sim_radio2, active_tab], outputs=[submit_btn2])
|
| 538 |
dislike_radio1.select(fn=select_image, inputs=[dislike_radio1, images_method1], outputs=[dislike_image1])
|
| 539 |
like_radio1.select(fn=select_image, inputs=[like_radio1, images_method1], outputs=[like_image1])
|
| 540 |
dislike_radio2.select(fn=select_image, inputs=[dislike_radio2, images_method2], outputs=[dislike_image2])
|
utils.py
CHANGED
|
@@ -37,7 +37,7 @@ IMAGES = {
|
|
| 37 |
"ours": ["images/scenario2_ours1.png","images/scenario2_ours2.png","images/scenario2_ours3.png","images/scenario2_ours4.png"]},
|
| 38 |
"Fictional character generation": {"baseline": ["images/scenario3_base1.png","images/scenario3_base2.png","images/scenario3_base3.png","images/scenario3_base4.png"],
|
| 39 |
"ours": ["images/scenario3_ours1.png","images/scenario3_ours2.png","images/scenario3_ours3.png","images/scenario3_ours4.png"]},
|
| 40 |
-
"Interior Design": {"baseline": ["images/scenario4_base1.png","images/scenario4_base2.png","images/
|
| 41 |
"ours": ["images/scenario4_ours1.png","images/scenario4_ours2.png","images/scenario4_ours3.png","images/scenario4_ours4.png"]},
|
| 42 |
}
|
| 43 |
|
|
|
|
| 37 |
"ours": ["images/scenario2_ours1.png","images/scenario2_ours2.png","images/scenario2_ours3.png","images/scenario2_ours4.png"]},
|
| 38 |
"Fictional character generation": {"baseline": ["images/scenario3_base1.png","images/scenario3_base2.png","images/scenario3_base3.png","images/scenario3_base4.png"],
|
| 39 |
"ours": ["images/scenario3_ours1.png","images/scenario3_ours2.png","images/scenario3_ours3.png","images/scenario3_ours4.png"]},
|
| 40 |
+
"Interior Design": {"baseline": ["images/scenario4_base1.png","images/scenario4_base2.png","images/scenario4_base3.png","images/scenario4_base4.png"],
|
| 41 |
"ours": ["images/scenario4_ours1.png","images/scenario4_ours2.png","images/scenario4_ours3.png","images/scenario4_ours4.png"]},
|
| 42 |
}
|
| 43 |
|