patrickvonplaten commited on
Commit
831957f
1 Parent(s): 67e191e
Files changed (2) hide show
  1. __pycache__/app.cpython-310.pyc +0 -0
  2. app.py +106 -27
__pycache__/app.cpython-310.pyc CHANGED
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
 
app.py CHANGED
@@ -169,6 +169,7 @@ def process(dataframe, row_number=0):
169
  for i in range(len(SUBMISSIONS))
170
  ]
171
  images = (SUBMISSIONS[c][int(image_id)]["images"] for c in choices)
 
172
 
173
  prompt = SUBMISSIONS[choices[0]][int(image_id)]["Prompt"]
174
  prompt = f'# "{prompt}"'
@@ -182,7 +183,9 @@ def write_result(user_choice, row_number, dataframe):
182
  return row_number, dataframe
183
 
184
  user_choice = int(user_choice)
 
185
  chosen_model = submission_names[dataframe.iloc[row_number][f"choice_{user_choice}"]]
 
186
 
187
  dataframe.loc[row_number, "result"] = chosen_model
188
  return row_number + 1, dataframe
@@ -320,32 +323,108 @@ with gr.Blocks() as demo:
320
  fn=process, inputs=[dataframe], outputs=[image_1, image_2, image_3, image_4, prompt, counter]
321
  )
322
 
323
- images = [image_1_button, image_2_button, image_3_button, image_4_button]
324
- for i, button in enumerate(images):
325
- button.click(
326
- fn=lambda: i,
327
- inputs=[],
328
- outputs=[selected_image],
329
- ).then(
330
- fn=write_result,
331
- inputs=[selected_image, row_number, dataframe],
332
- outputs=[row_number, dataframe],
333
- ).then(
334
- fn=change_view,
335
- inputs=[row_number, dataframe],
336
- outputs=[intro_view, result_view, gallery_view, start_view, result]
337
- ).then(
338
- fn=process,
339
- inputs=[dataframe, row_number],
340
- outputs=[image_1, image_2, image_3, image_4, prompt, counter]
341
- ).then(
342
- fn=lambda x: 0 if x == NUM_QUESTIONS else x,
343
- inputs=[row_number],
344
- outputs=[row_number],
345
- ).then(
346
- fn=refresh,
347
- inputs=[row_number, dataframe],
348
- outputs=[dataframe],
349
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
 
351
  demo.launch()
 
169
  for i in range(len(SUBMISSIONS))
170
  ]
171
  images = (SUBMISSIONS[c][int(image_id)]["images"] for c in choices)
172
+ print({i: c for i, c in enumerate(choices)})
173
 
174
  prompt = SUBMISSIONS[choices[0]][int(image_id)]["Prompt"]
175
  prompt = f'# "{prompt}"'
 
183
  return row_number, dataframe
184
 
185
  user_choice = int(user_choice)
186
+ print(user_choice)
187
  chosen_model = submission_names[dataframe.iloc[row_number][f"choice_{user_choice}"]]
188
+ print(chosen_model)
189
 
190
  dataframe.loc[row_number, "result"] = chosen_model
191
  return row_number + 1, dataframe
 
323
  fn=process, inputs=[dataframe], outputs=[image_1, image_2, image_3, image_4, prompt, counter]
324
  )
325
 
326
+ image_1_button.click(
327
+ fn=lambda: 0,
328
+ inputs=[],
329
+ outputs=[selected_image],
330
+ ).then(
331
+ fn=write_result,
332
+ inputs=[selected_image, row_number, dataframe],
333
+ outputs=[row_number, dataframe],
334
+ ).then(
335
+ fn=change_view,
336
+ inputs=[row_number, dataframe],
337
+ outputs=[intro_view, result_view, gallery_view, start_view, result]
338
+ ).then(
339
+ fn=process,
340
+ inputs=[dataframe, row_number],
341
+ outputs=[image_1, image_2, image_3, image_4, prompt, counter]
342
+ ).then(
343
+ fn=lambda x: 0 if x == NUM_QUESTIONS else x,
344
+ inputs=[row_number],
345
+ outputs=[row_number],
346
+ ).then(
347
+ fn=refresh,
348
+ inputs=[row_number, dataframe],
349
+ outputs=[dataframe],
350
+ )
351
+
352
+ image_2_button.click(
353
+ fn=lambda: 1,
354
+ inputs=[],
355
+ outputs=[selected_image],
356
+ ).then(
357
+ fn=write_result,
358
+ inputs=[selected_image, row_number, dataframe],
359
+ outputs=[row_number, dataframe],
360
+ ).then(
361
+ fn=change_view,
362
+ inputs=[row_number, dataframe],
363
+ outputs=[intro_view, result_view, gallery_view, start_view, result]
364
+ ).then(
365
+ fn=process,
366
+ inputs=[dataframe, row_number],
367
+ outputs=[image_1, image_2, image_3, image_4, prompt, counter]
368
+ ).then(
369
+ fn=lambda x: 0 if x == NUM_QUESTIONS else x,
370
+ inputs=[row_number],
371
+ outputs=[row_number],
372
+ ).then(
373
+ fn=refresh,
374
+ inputs=[row_number, dataframe],
375
+ outputs=[dataframe],
376
+ )
377
+
378
+ image_3_button.click(
379
+ fn=lambda: 2,
380
+ inputs=[],
381
+ outputs=[selected_image],
382
+ ).then(
383
+ fn=write_result,
384
+ inputs=[selected_image, row_number, dataframe],
385
+ outputs=[row_number, dataframe],
386
+ ).then(
387
+ fn=change_view,
388
+ inputs=[row_number, dataframe],
389
+ outputs=[intro_view, result_view, gallery_view, start_view, result]
390
+ ).then(
391
+ fn=process,
392
+ inputs=[dataframe, row_number],
393
+ outputs=[image_1, image_2, image_3, image_4, prompt, counter]
394
+ ).then(
395
+ fn=lambda x: 0 if x == NUM_QUESTIONS else x,
396
+ inputs=[row_number],
397
+ outputs=[row_number],
398
+ ).then(
399
+ fn=refresh,
400
+ inputs=[row_number, dataframe],
401
+ outputs=[dataframe],
402
+ )
403
+
404
+ image_4_button.click(
405
+ fn=lambda: 3,
406
+ inputs=[],
407
+ outputs=[selected_image],
408
+ ).then(
409
+ fn=write_result,
410
+ inputs=[selected_image, row_number, dataframe],
411
+ outputs=[row_number, dataframe],
412
+ ).then(
413
+ fn=change_view,
414
+ inputs=[row_number, dataframe],
415
+ outputs=[intro_view, result_view, gallery_view, start_view, result]
416
+ ).then(
417
+ fn=process,
418
+ inputs=[dataframe, row_number],
419
+ outputs=[image_1, image_2, image_3, image_4, prompt, counter]
420
+ ).then(
421
+ fn=lambda x: 0 if x == NUM_QUESTIONS else x,
422
+ inputs=[row_number],
423
+ outputs=[row_number],
424
+ ).then(
425
+ fn=refresh,
426
+ inputs=[row_number, dataframe],
427
+ outputs=[dataframe],
428
+ )
429
 
430
  demo.launch()