xh365 commited on
Commit
a92b2e7
·
1 Parent(s): d5d70f7

update saving to each iteration

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
@@ -266,8 +266,23 @@ def generate_image(participant, scenario, prompt, active_tab, like_image, dislik
266
  img = infer(refined_prompts[i])
267
  gallery_images.append(img)
268
  yield gallery_images
 
 
 
 
 
 
 
 
 
269
 
270
- def redesign(participant, scenario, prompt, sim_radio, like_radio, dislike_radio, current_images, history_images, active_tab):
 
 
 
 
 
 
271
  global counter1, counter2, responses_memory, current_task1, current_task2, enable_submit1, enable_submit2
272
  method = current_task1 if active_tab == "Task A" else current_task2
273
 
@@ -282,6 +297,8 @@ def redesign(participant, scenario, prompt, sim_radio, like_radio, dislike_radio
282
  responses_memory[participant][method][counter]["satisfied_img"] = f"round {counter}, {like_radio}"
283
  responses_memory[participant][method][counter]["unsatisfied_img"] = f"round {counter}, {dislike_radio}"
284
 
 
 
285
  enable_submit = True if sim_radio in ["Satisfied", "Very Satisfied"] or enable_submit else False
286
 
287
  history_prompts = [[v["prompt"]] for v in responses_memory[participant][method].values()]
@@ -337,18 +354,7 @@ def save_response(participant, scenario, prompt, sim_radio, like_radio, dislike_
337
  responses_memory[participant][method][counter]["unsatisfied_img"] = f"round {counter}, {dislike_radio}"
338
 
339
  try:
340
- # save responses in google sheet
341
- gc = gspread.service_account(filename='credentials.json')
342
- sheet = gc.open("DiverseGen-phase3").sheet1
343
-
344
- for i, entry in responses_memory[participant][method].items():
345
- sheet.append_row([participant, scenario, f"{active_tab}, {method}", i, entry["prompt"], entry["sim_radio"], entry["response"], entry["satisfied_img"], entry["unsatisfied_img"]])
346
-
347
- # save images in google drive
348
- creds = Credentials.from_service_account_file('credentials.json',scopes=scopes)
349
- save_image(creds, like_image, dislike_image, f"{participant}_{scenario}_{active_tab}_{method}")
350
-
351
- display_info_message("✅ Your answer is saved!")
352
 
353
  # reset global variables
354
  if method == METHODS[0]:
@@ -579,12 +585,12 @@ with gr.Blocks(theme=gr.themes.Soft(font=[gr.themes.GoogleFont("Inconsolata"), "
579
 
580
  redesign_btn1.click(
581
  fn=redesign,
582
- inputs=[participant, scenario, prompt1, sim_radio1, like_radio1, dislike_radio1, images_method1, history_images1, active_tab],
583
  outputs=[sim_radio1, dislike_radio1, like_radio1, images_method1, history_images1, example1.dataset, prompt1, next_btn1, redesign_btn1, submit_btn1]
584
  )
585
  redesign_btn2.click(
586
  fn=redesign,
587
- inputs=[participant, scenario, prompt2, sim_radio2, like_radio2, dislike_radio2, images_method2, history_images2, active_tab],
588
  outputs=[sim_radio2, dislike_radio2, like_radio2, images_method2, history_images2, example2.dataset, prompt2, next_btn2, redesign_btn2, submit_btn2]
589
  )
590
  submit_btn1.click(fn=save_response,
 
266
  img = infer(refined_prompts[i])
267
  gallery_images.append(img)
268
  yield gallery_images
269
+
270
+ def save_response_to_sheet(participant, method, scenario, active_tab, round, like_image, dislike_image):
271
+ global responses_memory
272
+ gc = gspread.service_account(filename='credentials.json')
273
+ sheet = gc.open("DiverseGen-phase3").sheet1
274
+
275
+ entry = responses_memory[participant][method][round]
276
+ print(entry)
277
+ sheet.append_row([participant, scenario, f"{active_tab}, {method}", round, entry["prompt"], entry["sim_radio"], entry["response"], entry["satisfied_img"], entry["unsatisfied_img"]])
278
 
279
+ # save images in google drive
280
+ creds = Credentials.from_service_account_file('credentials.json',scopes=scopes)
281
+ save_image(creds, like_image, dislike_image, f"{participant}_{scenario}_{active_tab}_{method}_round{round}")
282
+
283
+ display_info_message("✅ Your answer is saved!")
284
+
285
+ def redesign(participant, scenario, prompt, sim_radio, like_radio, dislike_radio, current_images, history_images, active_tab, like_image, dislike_image):
286
  global counter1, counter2, responses_memory, current_task1, current_task2, enable_submit1, enable_submit2
287
  method = current_task1 if active_tab == "Task A" else current_task2
288
 
 
297
  responses_memory[participant][method][counter]["satisfied_img"] = f"round {counter}, {like_radio}"
298
  responses_memory[participant][method][counter]["unsatisfied_img"] = f"round {counter}, {dislike_radio}"
299
 
300
+ save_response_to_sheet(participant, method, scenario, active_tab, counter, like_image, dislike_image)
301
+
302
  enable_submit = True if sim_radio in ["Satisfied", "Very Satisfied"] or enable_submit else False
303
 
304
  history_prompts = [[v["prompt"]] for v in responses_memory[participant][method].values()]
 
354
  responses_memory[participant][method][counter]["unsatisfied_img"] = f"round {counter}, {dislike_radio}"
355
 
356
  try:
357
+ save_response_to_sheet(participant, method, scenario, active_tab, counter, like_image, dislike_image)
 
 
 
 
 
 
 
 
 
 
 
358
 
359
  # reset global variables
360
  if method == METHODS[0]:
 
585
 
586
  redesign_btn1.click(
587
  fn=redesign,
588
+ inputs=[participant, scenario, prompt1, sim_radio1, like_radio1, dislike_radio1, images_method1, history_images1, active_tab, like_image1, dislike_image1],
589
  outputs=[sim_radio1, dislike_radio1, like_radio1, images_method1, history_images1, example1.dataset, prompt1, next_btn1, redesign_btn1, submit_btn1]
590
  )
591
  redesign_btn2.click(
592
  fn=redesign,
593
+ inputs=[participant, scenario, prompt2, sim_radio2, like_radio2, dislike_radio2, images_method2, history_images2, active_tab, like_image2, dislike_image2],
594
  outputs=[sim_radio2, dislike_radio2, like_radio2, images_method2, history_images2, example2.dataset, prompt2, next_btn2, redesign_btn2, submit_btn2]
595
  )
596
  submit_btn1.click(fn=save_response,