Spaces:
Running
on
Zero
Running
on
Zero
added reference answer toggle
Browse files- utils/ui_helpers.py +23 -0
utils/ui_helpers.py
CHANGED
@@ -27,6 +27,29 @@ def toggle_context_display(example, current_state):
|
|
27 |
# Return the values as list in the expected order, not as a dictionary
|
28 |
return new_state, gr.update(value=context_html), gr.update(value=button_text, elem_classes=elem_classes)
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def update_feedback(choice):
|
31 |
"""Updates the feedback list state when checkbox selections change."""
|
32 |
# Return the value directly, not as a dictionary
|
|
|
27 |
# Return the values as list in the expected order, not as a dictionary
|
28 |
return new_state, gr.update(value=context_html), gr.update(value=button_text, elem_classes=elem_classes)
|
29 |
|
30 |
+
def toggle_reference_answer(current_state, example):
|
31 |
+
"""
|
32 |
+
Toggle reference answer visibility - exactly like FAQ toggle.
|
33 |
+
"""
|
34 |
+
new_state = not current_state
|
35 |
+
|
36 |
+
# Button text with arrow icons (exactly like FAQ)
|
37 |
+
button_text = "▼ Hide Reference Answer" if new_state else "▶ Show Reference Answer"
|
38 |
+
|
39 |
+
# Get reference answer only when expanding
|
40 |
+
reference_answer = ""
|
41 |
+
if new_state and isinstance(example, dict):
|
42 |
+
reference_answer = example.get('answer', '')
|
43 |
+
if not reference_answer or reference_answer.strip() == '':
|
44 |
+
reference_answer = "No reference answer available for this question."
|
45 |
+
|
46 |
+
return (
|
47 |
+
new_state,
|
48 |
+
gr.update(visible=new_state),
|
49 |
+
gr.update(value=button_text),
|
50 |
+
gr.update(value=reference_answer)
|
51 |
+
)
|
52 |
+
|
53 |
def update_feedback(choice):
|
54 |
"""Updates the feedback list state when checkbox selections change."""
|
55 |
# Return the value directly, not as a dictionary
|