Spaces:
Running
on
Zero
Running
on
Zero
| 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 |