Fix zoom state
Browse files
app.py
CHANGED
@@ -185,13 +185,16 @@ def gradio_interface():
|
|
185 |
state_model_b_name = gr.State(model_b_name)
|
186 |
state_filename = gr.State(filename)
|
187 |
|
|
|
|
|
|
|
188 |
# Compute the absolute difference between the masks
|
189 |
mask_difference = compute_mask_difference(segmented_a, segmented_b)
|
190 |
|
191 |
with gr.Row():
|
192 |
image_a_display = gr.Image(
|
193 |
value=segmented_a,
|
194 |
-
label="
|
195 |
width=500,
|
196 |
height=500
|
197 |
)
|
@@ -203,7 +206,7 @@ def gradio_interface():
|
|
203 |
)
|
204 |
image_b_display = gr.Image(
|
205 |
value=segmented_b,
|
206 |
-
label="
|
207 |
width=500,
|
208 |
height=500
|
209 |
)
|
@@ -243,28 +246,43 @@ def gradio_interface():
|
|
243 |
# Update the notice markdown with the new vote count
|
244 |
new_notice_markdown = get_notice_markdown()
|
245 |
|
246 |
-
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
|
249 |
vote_a_button.click(
|
250 |
fn=lambda username: vote_for_model("model_a", state_filename, state_model_a_name, state_model_b_name, username),
|
251 |
inputs=username_input,
|
252 |
outputs=[
|
253 |
-
state_filename, input_image_display, image_a_display, image_b_display, state_model_a_name, state_model_b_name, notice_markdown, state_segmented_a, state_segmented_b
|
254 |
]
|
255 |
)
|
256 |
vote_b_button.click(
|
257 |
fn=lambda username: vote_for_model("model_b", state_filename, state_model_a_name, state_model_b_name, username),
|
258 |
inputs=username_input,
|
259 |
outputs=[
|
260 |
-
state_filename, input_image_display, image_a_display, image_b_display, state_model_a_name, state_model_b_name, notice_markdown, state_segmented_a, state_segmented_b
|
261 |
]
|
262 |
)
|
263 |
vote_tie_button.click(
|
264 |
fn=lambda username: vote_for_model("tie", state_filename, state_model_a_name, state_model_b_name, username),
|
265 |
inputs=username_input,
|
266 |
outputs=[
|
267 |
-
state_filename, input_image_display, image_a_display, image_b_display, state_model_a_name, state_model_b_name, notice_markdown, state_segmented_a, state_segmented_b
|
268 |
]
|
269 |
)
|
270 |
|
@@ -274,7 +292,7 @@ def gradio_interface():
|
|
274 |
if zoomed_state:
|
275 |
return gr.Image(
|
276 |
value=segmented_image,
|
277 |
-
label="
|
278 |
width=500,
|
279 |
height=500
|
280 |
), False
|
@@ -312,8 +330,7 @@ def gradio_interface():
|
|
312 |
|
313 |
return output_image, True
|
314 |
|
315 |
-
|
316 |
-
zoomed_state_b = gr.State(False)
|
317 |
image_a_display.select(handle_zoom, [image_a_display, zoomed_state_a, state_segmented_a], [image_a_display, zoomed_state_a])
|
318 |
image_b_display.select(handle_zoom, [image_b_display, zoomed_state_b, state_segmented_b], [image_b_display, zoomed_state_b])
|
319 |
|
|
|
185 |
state_model_b_name = gr.State(model_b_name)
|
186 |
state_filename = gr.State(filename)
|
187 |
|
188 |
+
zoomed_state_a = gr.State(False)
|
189 |
+
zoomed_state_b = gr.State(False)
|
190 |
+
|
191 |
# Compute the absolute difference between the masks
|
192 |
mask_difference = compute_mask_difference(segmented_a, segmented_b)
|
193 |
|
194 |
with gr.Row():
|
195 |
image_a_display = gr.Image(
|
196 |
value=segmented_a,
|
197 |
+
label="Image",
|
198 |
width=500,
|
199 |
height=500
|
200 |
)
|
|
|
206 |
)
|
207 |
image_b_display = gr.Image(
|
208 |
value=segmented_b,
|
209 |
+
label="Image",
|
210 |
width=500,
|
211 |
height=500
|
212 |
)
|
|
|
246 |
# Update the notice markdown with the new vote count
|
247 |
new_notice_markdown = get_notice_markdown()
|
248 |
|
249 |
+
# Reinitialize zoom states to False
|
250 |
+
zoomed_state_a.value = False
|
251 |
+
zoomed_state_b.value = False
|
252 |
+
|
253 |
+
return (
|
254 |
+
original_filename.value,
|
255 |
+
(new_input_image, [(mask_difference, button_name)]),
|
256 |
+
new_segmented_a,
|
257 |
+
new_segmented_b,
|
258 |
+
model_a_name.value,
|
259 |
+
model_b_name.value,
|
260 |
+
new_notice_markdown,
|
261 |
+
state_segmented_a.value,
|
262 |
+
state_segmented_b.value,
|
263 |
+
zoomed_state_a.value,
|
264 |
+
zoomed_state_b.value
|
265 |
+
)
|
266 |
|
267 |
vote_a_button.click(
|
268 |
fn=lambda username: vote_for_model("model_a", state_filename, state_model_a_name, state_model_b_name, username),
|
269 |
inputs=username_input,
|
270 |
outputs=[
|
271 |
+
state_filename, input_image_display, image_a_display, image_b_display, state_model_a_name, state_model_b_name, notice_markdown, state_segmented_a, state_segmented_b, zoomed_state_a, zoomed_state_b
|
272 |
]
|
273 |
)
|
274 |
vote_b_button.click(
|
275 |
fn=lambda username: vote_for_model("model_b", state_filename, state_model_a_name, state_model_b_name, username),
|
276 |
inputs=username_input,
|
277 |
outputs=[
|
278 |
+
state_filename, input_image_display, image_a_display, image_b_display, state_model_a_name, state_model_b_name, notice_markdown, state_segmented_a, state_segmented_b, zoomed_state_a, zoomed_state_b
|
279 |
]
|
280 |
)
|
281 |
vote_tie_button.click(
|
282 |
fn=lambda username: vote_for_model("tie", state_filename, state_model_a_name, state_model_b_name, username),
|
283 |
inputs=username_input,
|
284 |
outputs=[
|
285 |
+
state_filename, input_image_display, image_a_display, image_b_display, state_model_a_name, state_model_b_name, notice_markdown, state_segmented_a, state_segmented_b, zoomed_state_a, zoomed_state_b
|
286 |
]
|
287 |
)
|
288 |
|
|
|
292 |
if zoomed_state:
|
293 |
return gr.Image(
|
294 |
value=segmented_image,
|
295 |
+
label="Image",
|
296 |
width=500,
|
297 |
height=500
|
298 |
), False
|
|
|
330 |
|
331 |
return output_image, True
|
332 |
|
333 |
+
|
|
|
334 |
image_a_display.select(handle_zoom, [image_a_display, zoomed_state_a, state_segmented_a], [image_a_display, zoomed_state_a])
|
335 |
image_b_display.select(handle_zoom, [image_b_display, zoomed_state_b, state_segmented_b], [image_b_display, zoomed_state_b])
|
336 |
|