tdurbor commited on
Commit
9d0dec9
·
1 Parent(s): 078c9a8

Random images at init

Browse files
Files changed (1) hide show
  1. app.py +42 -33
app.py CHANGED
@@ -230,40 +230,49 @@ def gradio_interface():
230
  outputs=feedback_output
231
  )
232
 
233
- def refresh_states():
234
- filename, input_image, segmented_a, segmented_b, model_a_name, model_b_name = select_new_image()
235
- mask_difference = compute_mask_difference(segmented_a, segmented_b)
236
- image_a = gr.Image(
237
- value=segmented_a,
238
- label="Image",
239
- width=image_width
240
- )
241
-
242
- input_image_display = gr.AnnotatedImage(
243
- value=(input_image, [(mask_difference > 0, button_name)]),
244
- label="Input Image",
245
- width=image_width
246
- )
247
-
248
- image_b = gr.Image(
249
- value=segmented_b,
250
- label="Image",
251
- width=image_width
252
- )
253
-
254
- state_model_a_name = gr.State(model_a_name)
255
- state_model_b_name = gr.State(model_b_name)
256
- state_filename = gr.State(filename)
257
-
258
- outputs = [
259
- state_filename, image_a, image_b, state_model_a_name, state_model_b_name,
260
- input_image_display
261
- ]
262
- return outputs
263
 
264
  with gr.Row():
265
- state_filename, image_a, image_b, state_model_a_name, state_model_b_name, input_image_display = refresh_states()
266
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  with gr.Row():
268
  vote_a_button = gr.Button("👈 A is better")
269
  vote_tie_button = gr.Button("🤝 Tie")
@@ -396,7 +405,7 @@ def gradio_interface():
396
  fn=lambda: get_weekly_user_leaderboard(),
397
  outputs=user_leaderboard_table
398
  )
399
-
400
  return demo
401
 
402
  def dump_database_to_json():
 
230
  outputs=feedback_output
231
  )
232
 
233
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
234
 
235
  with gr.Row():
236
+ # Initialize components with empty states
237
+ state_filename = gr.State("")
238
+ state_model_a_name = gr.State("")
239
+ state_model_b_name = gr.State("")
240
+ image_a = gr.Image(label="Image A", width=image_width)
241
+ input_image_display = gr.AnnotatedImage(label="Input Image", width=image_width)
242
+ image_b = gr.Image(label="Image B", width=image_width)
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)
255
+
256
+ # Update states with new data
257
+ state_filename.value = filename
258
+ state_model_a_name.value = model_a_name
259
+ state_model_b_name.value = model_b_name
260
+
261
+ # Create new gr.Image components with updated values
262
+ image_a = gr.Image(value=segmented_a, label="Image A", width=image_width)
263
+ image_b = gr.Image(value=segmented_b, label="Image B", width=image_width)
264
+ input_image_display = gr.AnnotatedImage(
265
+ value=(input_image, [(mask_difference > 0, button_name)]),
266
+ width=image_width
267
+ )
268
+
269
+ outputs = [
270
+ state_filename, image_a, image_b, state_model_a_name, state_model_b_name,
271
+ input_image_display
272
+ ]
273
+ return outputs
274
+
275
+
276
  with gr.Row():
277
  vote_a_button = gr.Button("👈 A is better")
278
  vote_tie_button = gr.Button("🤝 Tie")
 
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():