Spaces:
Sleeping
Sleeping
backup
Browse files
app.py
CHANGED
@@ -219,13 +219,15 @@ def evaluate(verdict, state):
|
|
219 |
False,
|
220 |
False,
|
221 |
False,
|
|
|
222 |
None,
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
None,
|
228 |
-
None,
|
|
|
229 |
)
|
230 |
|
231 |
# Save the evaluation
|
@@ -233,6 +235,9 @@ def evaluate(verdict, state):
|
|
233 |
|
234 |
# Get next sample
|
235 |
next_sample = get_random_sample()
|
|
|
|
|
|
|
236 |
|
237 |
# Reset button styles
|
238 |
a_better_reset = gr.update(variant="secondary")
|
@@ -247,18 +252,19 @@ def evaluate(verdict, state):
|
|
247 |
next_sample["instruction"],
|
248 |
next_sample["simplified_instruction"],
|
249 |
f"Model A: {next_sample['model_a']} | Model B: {next_sample['model_b']}",
|
250 |
-
|
251 |
None, # selected_verdict
|
252 |
-
False,
|
253 |
-
False,
|
254 |
-
False,
|
255 |
-
False, #
|
256 |
a_better_reset, # reset A is better button style
|
257 |
b_better_reset, # reset B is better button style
|
258 |
neither_reset, # reset neither is good button style
|
259 |
tie_reset, # reset tie button style
|
260 |
next_sample["post_id"],
|
261 |
next_sample["simplified_instruction"],
|
|
|
262 |
)
|
263 |
|
264 |
|
@@ -275,9 +281,26 @@ def select_verdict(verdict, state):
|
|
275 |
)
|
276 |
|
277 |
|
278 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
"""Initialize the interface with first sample"""
|
280 |
sample = get_random_sample()
|
|
|
|
|
|
|
|
|
281 |
return (
|
282 |
sample["source_image"],
|
283 |
sample["image_a"],
|
@@ -285,7 +308,7 @@ def initialize():
|
|
285 |
sample["instruction"],
|
286 |
sample["simplified_instruction"],
|
287 |
f"Model A: {sample['model_a']} | Model B: {sample['model_b']}",
|
288 |
-
|
289 |
None, # selected_verdict
|
290 |
False, # a_better_selected
|
291 |
False, # b_better_selected
|
@@ -293,6 +316,7 @@ def initialize():
|
|
293 |
False, # tie_selected
|
294 |
sample["post_id"],
|
295 |
sample["simplified_instruction"],
|
|
|
296 |
)
|
297 |
|
298 |
|
@@ -321,15 +345,6 @@ def create_instruction_page(html_content, image_path=None):
|
|
321 |
gr.Image(image_path, container=False)
|
322 |
|
323 |
|
324 |
-
# Add before the main Gradio interface
|
325 |
-
def handle_username_submit(username, current_page):
|
326 |
-
"""Handle username submission and advance to next page"""
|
327 |
-
if not username or len(username.strip()) < 2:
|
328 |
-
# Just stay on current page if validation fails
|
329 |
-
return current_page, gr.update(value=username)
|
330 |
-
return 2, gr.update(value="") # Advance to page 2 and clear the input
|
331 |
-
|
332 |
-
|
333 |
def advance_page(current_page):
|
334 |
"""Handle next button clicks to advance pages"""
|
335 |
return current_page + 1
|
@@ -339,7 +354,7 @@ def advance_page(current_page):
|
|
339 |
with gr.Blocks() as demo:
|
340 |
# Add states for page management and user info
|
341 |
current_page = gr.State(1) # Start at page 1
|
342 |
-
username_state = gr.State(None)
|
343 |
|
344 |
# Create container for all pages
|
345 |
with gr.Column() as page_container:
|
@@ -458,6 +473,9 @@ with gr.Blocks() as demo:
|
|
458 |
show_label=True,
|
459 |
interactive=False,
|
460 |
)
|
|
|
|
|
|
|
461 |
state = gr.State()
|
462 |
selected_verdict = gr.State()
|
463 |
|
@@ -481,7 +499,7 @@ with gr.Blocks() as demo:
|
|
481 |
|
482 |
# Initialize the interface
|
483 |
demo.load(
|
484 |
-
initialize,
|
485 |
outputs=[
|
486 |
source_image,
|
487 |
image_a,
|
@@ -497,6 +515,7 @@ with gr.Blocks() as demo:
|
|
497 |
tie_selected,
|
498 |
post_id_display,
|
499 |
simplified_instruction_debug,
|
|
|
500 |
],
|
501 |
)
|
502 |
|
@@ -606,6 +625,7 @@ with gr.Blocks() as demo:
|
|
606 |
tie_btn,
|
607 |
post_id_display,
|
608 |
simplified_instruction_debug,
|
|
|
609 |
],
|
610 |
)
|
611 |
|
@@ -623,11 +643,16 @@ with gr.Blocks() as demo:
|
|
623 |
start_btn.click(
|
624 |
handle_username_submit,
|
625 |
inputs=[username_input, current_page],
|
626 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
627 |
).then(
|
628 |
update_page_visibility,
|
629 |
inputs=[current_page],
|
630 |
-
outputs=[page1, page2, page3, main_ui],
|
631 |
).then(
|
632 |
lambda x: gr.update(visible=x is None),
|
633 |
inputs=[current_page],
|
@@ -651,9 +676,10 @@ with gr.Blocks() as demo:
|
|
651 |
).then(
|
652 |
update_page_visibility,
|
653 |
inputs=[current_page],
|
654 |
-
outputs=[page1, page2, page3, main_ui],
|
655 |
).then(
|
656 |
initialize,
|
|
|
657 |
outputs=[
|
658 |
source_image,
|
659 |
image_a,
|
@@ -669,6 +695,7 @@ with gr.Blocks() as demo:
|
|
669 |
tie_selected,
|
670 |
post_id_display,
|
671 |
simplified_instruction_debug,
|
|
|
672 |
],
|
673 |
)
|
674 |
|
|
|
219 |
False,
|
220 |
False,
|
221 |
False,
|
222 |
+
False,
|
223 |
None,
|
224 |
+
gr.update(variant="secondary"), # a_better_btn
|
225 |
+
gr.update(variant="secondary"), # b_better_btn
|
226 |
+
gr.update(variant="secondary"), # neither_btn
|
227 |
+
gr.update(variant="secondary"), # tie_btn
|
228 |
+
None, # post_id
|
229 |
+
None, # simplified_instruction
|
230 |
+
"", # username_debug
|
231 |
)
|
232 |
|
233 |
# Save the evaluation
|
|
|
235 |
|
236 |
# Get next sample
|
237 |
next_sample = get_random_sample()
|
238 |
+
# Preserve username in state
|
239 |
+
next_state = next_sample.copy()
|
240 |
+
next_state["username"] = state["username"]
|
241 |
|
242 |
# Reset button styles
|
243 |
a_better_reset = gr.update(variant="secondary")
|
|
|
252 |
next_sample["instruction"],
|
253 |
next_sample["simplified_instruction"],
|
254 |
f"Model A: {next_sample['model_a']} | Model B: {next_sample['model_b']}",
|
255 |
+
next_state, # Now includes username
|
256 |
None, # selected_verdict
|
257 |
+
False, # a_better_selected
|
258 |
+
False, # b_better_selected
|
259 |
+
False, # neither_selected
|
260 |
+
False, # tie_selected
|
261 |
a_better_reset, # reset A is better button style
|
262 |
b_better_reset, # reset B is better button style
|
263 |
neither_reset, # reset neither is good button style
|
264 |
tie_reset, # reset tie button style
|
265 |
next_sample["post_id"],
|
266 |
next_sample["simplified_instruction"],
|
267 |
+
state["username"], # Use username from state
|
268 |
)
|
269 |
|
270 |
|
|
|
281 |
)
|
282 |
|
283 |
|
284 |
+
def handle_username_submit(username, current_page):
|
285 |
+
"""Handle username submission and advance to next page"""
|
286 |
+
if not username or len(username.strip()) < 2:
|
287 |
+
# Just stay on current page if validation fails
|
288 |
+
return current_page, gr.update(value=username), gr.update(value=""), None
|
289 |
+
return (
|
290 |
+
2, # next page
|
291 |
+
gr.update(value=""), # clear input
|
292 |
+
gr.update(value=username), # update debug
|
293 |
+
username, # update state
|
294 |
+
)
|
295 |
+
|
296 |
+
|
297 |
+
def initialize(username):
|
298 |
"""Initialize the interface with first sample"""
|
299 |
sample = get_random_sample()
|
300 |
+
# Create state with username included
|
301 |
+
state = sample.copy()
|
302 |
+
state["username"] = username
|
303 |
+
|
304 |
return (
|
305 |
sample["source_image"],
|
306 |
sample["image_a"],
|
|
|
308 |
sample["instruction"],
|
309 |
sample["simplified_instruction"],
|
310 |
f"Model A: {sample['model_a']} | Model B: {sample['model_b']}",
|
311 |
+
state, # Now includes username
|
312 |
None, # selected_verdict
|
313 |
False, # a_better_selected
|
314 |
False, # b_better_selected
|
|
|
316 |
False, # tie_selected
|
317 |
sample["post_id"],
|
318 |
sample["simplified_instruction"],
|
319 |
+
username or "", # Use stored username or empty string
|
320 |
)
|
321 |
|
322 |
|
|
|
345 |
gr.Image(image_path, container=False)
|
346 |
|
347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
def advance_page(current_page):
|
349 |
"""Handle next button clicks to advance pages"""
|
350 |
return current_page + 1
|
|
|
354 |
with gr.Blocks() as demo:
|
355 |
# Add states for page management and user info
|
356 |
current_page = gr.State(1) # Start at page 1
|
357 |
+
username_state = gr.State(None) # We'll actually use this now
|
358 |
|
359 |
# Create container for all pages
|
360 |
with gr.Column() as page_container:
|
|
|
473 |
show_label=True,
|
474 |
interactive=False,
|
475 |
)
|
476 |
+
username_debug = gr.Textbox(
|
477 |
+
label="Username", show_label=True, interactive=False
|
478 |
+
)
|
479 |
state = gr.State()
|
480 |
selected_verdict = gr.State()
|
481 |
|
|
|
499 |
|
500 |
# Initialize the interface
|
501 |
demo.load(
|
502 |
+
lambda: initialize(None), # Pass None on initial load
|
503 |
outputs=[
|
504 |
source_image,
|
505 |
image_a,
|
|
|
515 |
tie_selected,
|
516 |
post_id_display,
|
517 |
simplified_instruction_debug,
|
518 |
+
username_debug,
|
519 |
],
|
520 |
)
|
521 |
|
|
|
625 |
tie_btn,
|
626 |
post_id_display,
|
627 |
simplified_instruction_debug,
|
628 |
+
username_debug,
|
629 |
],
|
630 |
)
|
631 |
|
|
|
643 |
start_btn.click(
|
644 |
handle_username_submit,
|
645 |
inputs=[username_input, current_page],
|
646 |
+
outputs=[
|
647 |
+
current_page,
|
648 |
+
username_input,
|
649 |
+
username_debug,
|
650 |
+
username_state, # Add username_state to outputs
|
651 |
+
],
|
652 |
).then(
|
653 |
update_page_visibility,
|
654 |
inputs=[current_page],
|
655 |
+
outputs=[page1, page2, page3, main_ui],
|
656 |
).then(
|
657 |
lambda x: gr.update(visible=x is None),
|
658 |
inputs=[current_page],
|
|
|
676 |
).then(
|
677 |
update_page_visibility,
|
678 |
inputs=[current_page],
|
679 |
+
outputs=[page1, page2, page3, main_ui],
|
680 |
).then(
|
681 |
initialize,
|
682 |
+
inputs=[username_state], # Pass username_state to initialize
|
683 |
outputs=[
|
684 |
source_image,
|
685 |
image_a,
|
|
|
695 |
tie_selected,
|
696 |
post_id_display,
|
697 |
simplified_instruction_debug,
|
698 |
+
username_debug,
|
699 |
],
|
700 |
)
|
701 |
|