tdurbor commited on
Commit
ae51348
1 Parent(s): 9d0dec9

Fix info logging during votes

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -243,12 +243,7 @@ def gradio_interface():
243
 
244
  # Refresh states to load new image data
245
 
246
- def refresh_states():
247
- # Initialize empty states
248
- state_filename = gr.State("")
249
- state_model_a_name = gr.State("")
250
- state_model_b_name = gr.State("")
251
-
252
  # Call select_new_image to get new image data
253
  filename, input_image, segmented_a, segmented_b, model_a_name, model_b_name = select_new_image()
254
  mask_difference = compute_mask_difference(segmented_a, segmented_b)
@@ -280,7 +275,21 @@ def gradio_interface():
280
 
281
  def vote_for_model(choice, original_filename, model_a_name, model_b_name, user_username):
282
  """Submit a vote for a model and return updated images and model names."""
283
- logging.info("Voting for model: %s", choice)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  vote_data = {
285
  "image_id": original_filename.value,
286
  "model_a": model_a_name.value,
@@ -288,6 +297,7 @@ def gradio_interface():
288
  "winner": choice,
289
  "user_id": user_username or "anonymous"
290
  }
 
291
 
292
  try:
293
  logging.debug("Adding vote data to the database: %s", vote_data)
@@ -296,7 +306,7 @@ def gradio_interface():
296
  except Exception as e:
297
  logging.error("Error recording vote: %s", str(e))
298
 
299
- outputs = refresh_states()
300
  new_notice_markdown = get_notice_markdown()
301
 
302
  return outputs + [new_notice_markdown]
@@ -405,7 +415,7 @@ def gradio_interface():
405
  fn=lambda: get_weekly_user_leaderboard(),
406
  outputs=user_leaderboard_table
407
  )
408
- demo.load(lambda: refresh_states(), inputs=None, outputs=[state_filename, image_a, image_b, state_model_a_name, state_model_b_name, input_image_display])
409
  return demo
410
 
411
  def dump_database_to_json():
 
243
 
244
  # Refresh states to load new image data
245
 
246
+ def refresh_states(state_filename, state_model_a_name, state_model_b_name):
 
 
 
 
 
247
  # Call select_new_image to get new image data
248
  filename, input_image, segmented_a, segmented_b, model_a_name, model_b_name = select_new_image()
249
  mask_difference = compute_mask_difference(segmented_a, segmented_b)
 
275
 
276
  def vote_for_model(choice, original_filename, model_a_name, model_b_name, user_username):
277
  """Submit a vote for a model and return updated images and model names."""
278
+
279
+
280
+ if not original_filename.value:
281
+ logging.error("The field 'original_filename' is empty or None.")
282
+ raise ValueError("The field 'original_filename' must be provided and non-empty.")
283
+ if not model_a_name.value:
284
+ logging.error("The field 'model_a_name' is empty or None.")
285
+ raise ValueError("The field 'model_a_name' must be provided and non-empty.")
286
+ if not model_b_name.value:
287
+ logging.error("The field 'model_b_name' is empty or None.")
288
+ raise ValueError("The field 'model_b_name' must be provided and non-empty.")
289
+ if not choice:
290
+ logging.error("The field 'choice' is empty or None.")
291
+ raise ValueError("The field 'choice' must be provided and non-empty.")
292
+
293
  vote_data = {
294
  "image_id": original_filename.value,
295
  "model_a": model_a_name.value,
 
297
  "winner": choice,
298
  "user_id": user_username or "anonymous"
299
  }
300
+ logging.debug(vote_data)
301
 
302
  try:
303
  logging.debug("Adding vote data to the database: %s", vote_data)
 
306
  except Exception as e:
307
  logging.error("Error recording vote: %s", str(e))
308
 
309
+ outputs = refresh_states(state_filename, state_model_a_name, state_model_b_name)
310
  new_notice_markdown = get_notice_markdown()
311
 
312
  return outputs + [new_notice_markdown]
 
415
  fn=lambda: get_weekly_user_leaderboard(),
416
  outputs=user_leaderboard_table
417
  )
418
+ demo.load(lambda: refresh_states(state_filename, state_model_a_name, state_model_b_name), inputs=None, outputs=[state_filename, image_a, image_b, state_model_a_name, state_model_b_name, input_image_display])
419
  return demo
420
 
421
  def dump_database_to_json():