Spaces:
Sleeping
Sleeping
feat: implement Edit Dataset functionality with test case management
Browse files- Add dataset editing interface with test case display
- Implement add new test case functionality
- Add classification selector (green/yellow/red) for new test cases
- Implement close editor button
- Fix dataset dropdown initialization in Enhanced Dataset Mode
- Add proper event handlers for edit operations
- Improve UI with HTML rendering for test cases display
src/interface/enhanced_verification_interface.py
CHANGED
|
@@ -202,8 +202,108 @@ class EnhancedVerificationInterface:
|
|
| 202 |
gr.Markdown("Select and customize test datasets for verification.")
|
| 203 |
back_from_dataset_btn = gr.Button("β Back to Mode Selection", size="sm")
|
| 204 |
gr.Markdown("---")
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
manual_input_interface = gr.Row(visible=False)
|
| 209 |
with manual_input_interface:
|
|
@@ -439,9 +539,44 @@ class EnhancedVerificationInterface:
|
|
| 439 |
status_msg # status_message
|
| 440 |
)
|
| 441 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
# Bind mode selection buttons
|
| 443 |
enhanced_dataset_btn.click(
|
| 444 |
-
|
| 445 |
inputs=[],
|
| 446 |
outputs=[
|
| 447 |
mode_selection_section,
|
|
@@ -449,7 +584,9 @@ class EnhancedVerificationInterface:
|
|
| 449 |
manual_input_interface,
|
| 450 |
file_upload_interface,
|
| 451 |
current_mode_state,
|
| 452 |
-
status_message
|
|
|
|
|
|
|
| 453 |
]
|
| 454 |
)
|
| 455 |
|
|
@@ -599,6 +736,183 @@ class EnhancedVerificationInterface:
|
|
| 599 |
status_message
|
| 600 |
]
|
| 601 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 602 |
|
| 603 |
return interface
|
| 604 |
|
|
|
|
| 202 |
gr.Markdown("Select and customize test datasets for verification.")
|
| 203 |
back_from_dataset_btn = gr.Button("β Back to Mode Selection", size="sm")
|
| 204 |
gr.Markdown("---")
|
| 205 |
+
|
| 206 |
+
# Create dataset interface components directly here
|
| 207 |
+
from src.interface.enhanced_dataset_interface import EnhancedDatasetInterfaceController
|
| 208 |
+
dataset_controller = EnhancedDatasetInterfaceController()
|
| 209 |
+
|
| 210 |
+
# Pre-load dataset choices for initialization
|
| 211 |
+
try:
|
| 212 |
+
initial_choices, _, _, _ = dataset_controller.initialize_interface()
|
| 213 |
+
except Exception:
|
| 214 |
+
initial_choices = []
|
| 215 |
+
|
| 216 |
+
# Dataset selection interface
|
| 217 |
+
with gr.Row():
|
| 218 |
+
with gr.Column(scale=2):
|
| 219 |
+
gr.Markdown("## π Select Dataset")
|
| 220 |
+
|
| 221 |
+
dataset_selector = gr.Dropdown(
|
| 222 |
+
choices=initial_choices,
|
| 223 |
+
value=initial_choices[0] if initial_choices else None,
|
| 224 |
+
label="Available Datasets",
|
| 225 |
+
info="Choose a dataset to verify or edit",
|
| 226 |
+
interactive=True
|
| 227 |
+
)
|
| 228 |
+
|
| 229 |
+
with gr.Row():
|
| 230 |
+
load_dataset_btn = gr.Button("π₯ Load Dataset", variant="primary", scale=2)
|
| 231 |
+
edit_dataset_btn = gr.Button("βοΈ Edit Dataset", variant="secondary", scale=1)
|
| 232 |
+
|
| 233 |
+
with gr.Column(scale=1):
|
| 234 |
+
gr.Markdown("## π Dataset Information")
|
| 235 |
+
dataset_info_display = gr.Markdown(
|
| 236 |
+
"Select a dataset to view details",
|
| 237 |
+
label="Dataset Details"
|
| 238 |
+
)
|
| 239 |
+
|
| 240 |
+
# Verification interface (initially hidden)
|
| 241 |
+
verification_section = gr.Row(visible=False)
|
| 242 |
+
with verification_section:
|
| 243 |
+
with gr.Column():
|
| 244 |
+
gr.Markdown("## π Dataset Verification")
|
| 245 |
+
|
| 246 |
+
# Verification controls
|
| 247 |
+
with gr.Row():
|
| 248 |
+
with gr.Column(scale=2):
|
| 249 |
+
verifier_name_input = gr.Textbox(
|
| 250 |
+
label="Verifier Name",
|
| 251 |
+
placeholder="Enter your name...",
|
| 252 |
+
interactive=True
|
| 253 |
+
)
|
| 254 |
+
|
| 255 |
+
with gr.Column(scale=1):
|
| 256 |
+
start_verification_btn = gr.Button(
|
| 257 |
+
"π Start Verification",
|
| 258 |
+
variant="primary",
|
| 259 |
+
size="lg"
|
| 260 |
+
)
|
| 261 |
+
|
| 262 |
+
# Progress display
|
| 263 |
+
verification_progress = gr.Markdown(
|
| 264 |
+
"Ready to start verification",
|
| 265 |
+
label="Progress"
|
| 266 |
+
)
|
| 267 |
+
|
| 268 |
+
# Edit Dataset interface (initially hidden)
|
| 269 |
+
edit_section = gr.Row(visible=False)
|
| 270 |
+
with edit_section:
|
| 271 |
+
with gr.Column():
|
| 272 |
+
gr.Markdown("## βοΈ Edit Dataset")
|
| 273 |
+
|
| 274 |
+
# Test cases display
|
| 275 |
+
test_cases_display = gr.HTML(
|
| 276 |
+
value="<p>Loading test cases...</p>",
|
| 277 |
+
label="Test Cases"
|
| 278 |
+
)
|
| 279 |
+
|
| 280 |
+
gr.Markdown("### β Add New Test Case")
|
| 281 |
+
with gr.Row():
|
| 282 |
+
with gr.Column(scale=3):
|
| 283 |
+
new_message_text = gr.Textbox(
|
| 284 |
+
label="Message Text",
|
| 285 |
+
placeholder="Enter the test message...",
|
| 286 |
+
lines=3,
|
| 287 |
+
interactive=True
|
| 288 |
+
)
|
| 289 |
+
with gr.Column(scale=1):
|
| 290 |
+
new_message_classification = gr.Radio(
|
| 291 |
+
choices=["green", "yellow", "red"],
|
| 292 |
+
label="Expected Classification",
|
| 293 |
+
value="yellow"
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
+
with gr.Row():
|
| 297 |
+
add_test_case_btn = gr.Button("β Add Test Case", variant="primary")
|
| 298 |
+
close_edit_btn = gr.Button("βοΈ Close Editor", variant="secondary")
|
| 299 |
+
|
| 300 |
+
# Status message for dataset interface
|
| 301 |
+
dataset_status_message = gr.Markdown("", visible=True)
|
| 302 |
+
|
| 303 |
+
# Dataset state
|
| 304 |
+
current_dataset_state = gr.State(value=None)
|
| 305 |
+
verification_session_state = gr.State(value=None)
|
| 306 |
+
editing_dataset_state = gr.State(value=None)
|
| 307 |
|
| 308 |
manual_input_interface = gr.Row(visible=False)
|
| 309 |
with manual_input_interface:
|
|
|
|
| 539 |
status_msg # status_message
|
| 540 |
)
|
| 541 |
|
| 542 |
+
# Special function for enhanced dataset mode initialization
|
| 543 |
+
def switch_to_enhanced_dataset():
|
| 544 |
+
"""Switch to enhanced dataset mode with proper initialization."""
|
| 545 |
+
try:
|
| 546 |
+
# Get first dataset info for display
|
| 547 |
+
dataset_choices, _, _, _ = dataset_controller.initialize_interface()
|
| 548 |
+
first_dataset = None
|
| 549 |
+
dataset_info = "Select a dataset to view details"
|
| 550 |
+
|
| 551 |
+
if dataset_choices:
|
| 552 |
+
first_info, first_dataset = dataset_controller.get_dataset_info(dataset_choices[0])
|
| 553 |
+
dataset_info = first_info
|
| 554 |
+
|
| 555 |
+
return (
|
| 556 |
+
gr.Row(visible=False), # mode_selection_section
|
| 557 |
+
gr.Row(visible=True), # enhanced_dataset_interface
|
| 558 |
+
gr.Row(visible=False), # manual_input_interface
|
| 559 |
+
gr.Row(visible=False), # file_upload_interface
|
| 560 |
+
"enhanced_dataset", # current_mode_state
|
| 561 |
+
"β
Switched to Enhanced Datasets mode", # status_message
|
| 562 |
+
dataset_info, # dataset_info_display
|
| 563 |
+
first_dataset # current_dataset_state
|
| 564 |
+
)
|
| 565 |
+
except Exception as e:
|
| 566 |
+
return (
|
| 567 |
+
gr.Row(visible=False), # mode_selection_section
|
| 568 |
+
gr.Row(visible=True), # enhanced_dataset_interface
|
| 569 |
+
gr.Row(visible=False), # manual_input_interface
|
| 570 |
+
gr.Row(visible=False), # file_upload_interface
|
| 571 |
+
"enhanced_dataset", # current_mode_state
|
| 572 |
+
f"β Error initializing dataset mode: {str(e)}", # status_message
|
| 573 |
+
"Error loading datasets", # dataset_info_display
|
| 574 |
+
None # current_dataset_state
|
| 575 |
+
)
|
| 576 |
+
|
| 577 |
# Bind mode selection buttons
|
| 578 |
enhanced_dataset_btn.click(
|
| 579 |
+
switch_to_enhanced_dataset,
|
| 580 |
inputs=[],
|
| 581 |
outputs=[
|
| 582 |
mode_selection_section,
|
|
|
|
| 584 |
manual_input_interface,
|
| 585 |
file_upload_interface,
|
| 586 |
current_mode_state,
|
| 587 |
+
status_message,
|
| 588 |
+
dataset_info_display,
|
| 589 |
+
current_dataset_state
|
| 590 |
]
|
| 591 |
)
|
| 592 |
|
|
|
|
| 736 |
status_message
|
| 737 |
]
|
| 738 |
)
|
| 739 |
+
|
| 740 |
+
# Dataset interface event handlers
|
| 741 |
+
def on_dataset_selection_change(dataset_selection):
|
| 742 |
+
"""Handle dataset selection change."""
|
| 743 |
+
try:
|
| 744 |
+
dataset_info, dataset_obj = dataset_controller.get_dataset_info(dataset_selection)
|
| 745 |
+
return (
|
| 746 |
+
dataset_info, # dataset_info_display
|
| 747 |
+
dataset_obj # current_dataset_state
|
| 748 |
+
)
|
| 749 |
+
except Exception as e:
|
| 750 |
+
return (
|
| 751 |
+
f"β Error loading dataset info: {str(e)}", # dataset_info_display
|
| 752 |
+
None # current_dataset_state
|
| 753 |
+
)
|
| 754 |
+
|
| 755 |
+
def on_load_dataset(current_dataset):
|
| 756 |
+
"""Handle load dataset for verification."""
|
| 757 |
+
try:
|
| 758 |
+
if not current_dataset:
|
| 759 |
+
return (
|
| 760 |
+
gr.Row(visible=False), # verification_section
|
| 761 |
+
"β No dataset selected" # dataset_status_message
|
| 762 |
+
)
|
| 763 |
+
|
| 764 |
+
return (
|
| 765 |
+
gr.Row(visible=True), # verification_section
|
| 766 |
+
f"β
Dataset '{current_dataset.name}' loaded for verification" # dataset_status_message
|
| 767 |
+
)
|
| 768 |
+
except Exception as e:
|
| 769 |
+
return (
|
| 770 |
+
gr.Row(visible=False), # verification_section
|
| 771 |
+
f"β Error loading dataset: {str(e)}" # dataset_status_message
|
| 772 |
+
)
|
| 773 |
+
|
| 774 |
+
def on_edit_dataset(current_dataset):
|
| 775 |
+
"""Handle edit dataset button."""
|
| 776 |
+
try:
|
| 777 |
+
if not current_dataset:
|
| 778 |
+
return (
|
| 779 |
+
gr.Row(visible=False), # edit_section
|
| 780 |
+
"", # test_cases_display
|
| 781 |
+
current_dataset, # editing_dataset_state
|
| 782 |
+
"β No dataset selected for editing" # dataset_status_message
|
| 783 |
+
)
|
| 784 |
+
|
| 785 |
+
# Render test cases HTML
|
| 786 |
+
test_cases_html = dataset_controller.render_test_cases_display(current_dataset)
|
| 787 |
+
|
| 788 |
+
return (
|
| 789 |
+
gr.Row(visible=True), # edit_section
|
| 790 |
+
test_cases_html, # test_cases_display
|
| 791 |
+
current_dataset, # editing_dataset_state
|
| 792 |
+
f"βοΈ Editing dataset: '{current_dataset.name}'" # dataset_status_message
|
| 793 |
+
)
|
| 794 |
+
except Exception as e:
|
| 795 |
+
return (
|
| 796 |
+
gr.Row(visible=False), # edit_section
|
| 797 |
+
"", # test_cases_display
|
| 798 |
+
None, # editing_dataset_state
|
| 799 |
+
f"β Error accessing dataset for editing: {str(e)}" # dataset_status_message
|
| 800 |
+
)
|
| 801 |
+
|
| 802 |
+
def on_close_edit():
|
| 803 |
+
"""Close the edit section."""
|
| 804 |
+
return (
|
| 805 |
+
gr.Row(visible=False), # edit_section
|
| 806 |
+
"β
Editor closed" # dataset_status_message
|
| 807 |
+
)
|
| 808 |
+
|
| 809 |
+
def on_add_test_case(editing_dataset, message_text, classification):
|
| 810 |
+
"""Add a new test case to the dataset."""
|
| 811 |
+
try:
|
| 812 |
+
if not editing_dataset:
|
| 813 |
+
return (
|
| 814 |
+
"", # test_cases_display
|
| 815 |
+
editing_dataset, # editing_dataset_state
|
| 816 |
+
"β No dataset being edited" # dataset_status_message
|
| 817 |
+
)
|
| 818 |
+
|
| 819 |
+
if not message_text or not message_text.strip():
|
| 820 |
+
return (
|
| 821 |
+
dataset_controller.render_test_cases_display(editing_dataset), # test_cases_display
|
| 822 |
+
editing_dataset, # editing_dataset_state
|
| 823 |
+
"β Message text is required" # dataset_status_message
|
| 824 |
+
)
|
| 825 |
+
|
| 826 |
+
# Add test case
|
| 827 |
+
success, message, updated_dataset = dataset_controller.add_test_case(
|
| 828 |
+
editing_dataset, message_text.strip(), classification
|
| 829 |
+
)
|
| 830 |
+
|
| 831 |
+
if success:
|
| 832 |
+
# Render updated test cases
|
| 833 |
+
test_cases_html = dataset_controller.render_test_cases_display(updated_dataset)
|
| 834 |
+
return (
|
| 835 |
+
test_cases_html, # test_cases_display
|
| 836 |
+
updated_dataset, # editing_dataset_state
|
| 837 |
+
message # dataset_status_message
|
| 838 |
+
)
|
| 839 |
+
else:
|
| 840 |
+
return (
|
| 841 |
+
dataset_controller.render_test_cases_display(editing_dataset), # test_cases_display
|
| 842 |
+
editing_dataset, # editing_dataset_state
|
| 843 |
+
message # dataset_status_message
|
| 844 |
+
)
|
| 845 |
+
except Exception as e:
|
| 846 |
+
return (
|
| 847 |
+
"", # test_cases_display
|
| 848 |
+
editing_dataset, # editing_dataset_state
|
| 849 |
+
f"β Error adding test case: {str(e)}" # dataset_status_message
|
| 850 |
+
)
|
| 851 |
+
|
| 852 |
+
def on_start_verification(current_dataset, verifier_name):
|
| 853 |
+
"""Handle starting verification session."""
|
| 854 |
+
try:
|
| 855 |
+
if not current_dataset:
|
| 856 |
+
return (
|
| 857 |
+
None, # verification_session_state
|
| 858 |
+
"β No dataset selected" # dataset_status_message
|
| 859 |
+
)
|
| 860 |
+
|
| 861 |
+
success, message, session = dataset_controller.start_verification_session(
|
| 862 |
+
current_dataset, verifier_name
|
| 863 |
+
)
|
| 864 |
+
|
| 865 |
+
if success:
|
| 866 |
+
return (
|
| 867 |
+
session, # verification_session_state
|
| 868 |
+
message # dataset_status_message
|
| 869 |
+
)
|
| 870 |
+
else:
|
| 871 |
+
return (
|
| 872 |
+
None, # verification_session_state
|
| 873 |
+
message # dataset_status_message
|
| 874 |
+
)
|
| 875 |
+
except Exception as e:
|
| 876 |
+
return (
|
| 877 |
+
None, # verification_session_state
|
| 878 |
+
f"β Error starting verification: {str(e)}" # dataset_status_message
|
| 879 |
+
)
|
| 880 |
+
|
| 881 |
+
# Bind dataset interface events
|
| 882 |
+
dataset_selector.change(
|
| 883 |
+
on_dataset_selection_change,
|
| 884 |
+
inputs=[dataset_selector],
|
| 885 |
+
outputs=[dataset_info_display, current_dataset_state]
|
| 886 |
+
)
|
| 887 |
+
|
| 888 |
+
load_dataset_btn.click(
|
| 889 |
+
on_load_dataset,
|
| 890 |
+
inputs=[current_dataset_state],
|
| 891 |
+
outputs=[verification_section, dataset_status_message]
|
| 892 |
+
)
|
| 893 |
+
|
| 894 |
+
edit_dataset_btn.click(
|
| 895 |
+
on_edit_dataset,
|
| 896 |
+
inputs=[current_dataset_state],
|
| 897 |
+
outputs=[edit_section, test_cases_display, editing_dataset_state, dataset_status_message]
|
| 898 |
+
)
|
| 899 |
+
|
| 900 |
+
close_edit_btn.click(
|
| 901 |
+
on_close_edit,
|
| 902 |
+
outputs=[edit_section, dataset_status_message]
|
| 903 |
+
)
|
| 904 |
+
|
| 905 |
+
add_test_case_btn.click(
|
| 906 |
+
on_add_test_case,
|
| 907 |
+
inputs=[editing_dataset_state, new_message_text, new_message_classification],
|
| 908 |
+
outputs=[test_cases_display, editing_dataset_state, dataset_status_message]
|
| 909 |
+
)
|
| 910 |
+
|
| 911 |
+
start_verification_btn.click(
|
| 912 |
+
on_start_verification,
|
| 913 |
+
inputs=[current_dataset_state, verifier_name_input],
|
| 914 |
+
outputs=[verification_session_state, dataset_status_message]
|
| 915 |
+
)
|
| 916 |
|
| 917 |
return interface
|
| 918 |
|