Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,980 Bytes
8a142a6 c508d80 8a142a6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
from .context_processor import get_context_html
def toggle_context_display(example, current_state):
"""
Toggles between full context and highlights display.
Parameters:
- example: The current example data
- current_state: Boolean indicating if full context is already shown
Returns:
- Updated context HTML and toggle button text
"""
new_state = not current_state
# UPDATED: Changed button text based on new state
button_text = "Show Highlights" if new_state else "Show Full Context"
context_html = get_context_html(example, show_full=new_state)
# Add or remove the showing-full class to the button
elem_classes = ["context-toggle-button"]
if new_state:
elem_classes.append("showing-full")
# Return the values as list in the expected order, not as a dictionary
return new_state, gr.update(value=context_html), gr.update(value=button_text, elem_classes=elem_classes)
def toggle_reference_answer(current_state, example):
"""
Toggle reference answer visibility - exactly like FAQ toggle.
"""
new_state = not current_state
# Button text with arrow icons (exactly like FAQ)
button_text = "▼ Hide Reference Answer" if new_state else "▶ Show Reference Answer"
# Get reference answer only when expanding
reference_answer = ""
if new_state and isinstance(example, dict):
reference_answer = example.get('answer', '')
if not reference_answer or reference_answer.strip() == '':
reference_answer = "No reference answer available for this question."
return (
new_state,
gr.update(visible=new_state),
gr.update(value=button_text),
gr.update(value=reference_answer)
)
def update_feedback(choice):
"""Updates the feedback list state when checkbox selections change."""
# Return the value directly, not as a dictionary
return choice |