refactor: gradio
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import gradio as gr
|
|
| 6 |
|
| 7 |
from llmdataparser import ParserRegistry
|
| 8 |
from llmdataparser.base_parser import (
|
|
|
|
| 9 |
DatasetDescription,
|
| 10 |
DatasetParser,
|
| 11 |
EvaluationMetric,
|
|
@@ -250,6 +251,29 @@ def update_metric_details(metric_name: str, parser_name: str) -> str:
|
|
| 250 |
return f"Error loading metric details: {str(e)}"
|
| 251 |
|
| 252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
def create_interface() -> gr.Blocks:
|
| 254 |
"""Create and return the Gradio interface."""
|
| 255 |
with gr.Blocks(css="footer {display: none !important}") as demo:
|
|
@@ -279,6 +303,14 @@ def create_interface() -> gr.Blocks:
|
|
| 279 |
with gr.Tab("Dataset Explorer"):
|
| 280 |
with gr.Row():
|
| 281 |
with gr.Column(scale=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
# Parser selection and controls
|
| 283 |
available_parsers = ParserRegistry.list_parsers()
|
| 284 |
parser_dropdown = gr.Dropdown(
|
|
@@ -345,6 +377,20 @@ def create_interface() -> gr.Blocks:
|
|
| 345 |
)
|
| 346 |
metric_details = gr.Markdown()
|
| 347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
# Event handlers
|
| 349 |
parser_dropdown.change(
|
| 350 |
fn=update_parser_options,
|
|
|
|
| 6 |
|
| 7 |
from llmdataparser import ParserRegistry
|
| 8 |
from llmdataparser.base_parser import (
|
| 9 |
+
VALID_CATEGORIES,
|
| 10 |
DatasetDescription,
|
| 11 |
DatasetParser,
|
| 12 |
EvaluationMetric,
|
|
|
|
| 251 |
return f"Error loading metric details: {str(e)}"
|
| 252 |
|
| 253 |
|
| 254 |
+
def get_parser_categories(parser_name: str) -> list[str]:
|
| 255 |
+
"""Get categories for a specific parser."""
|
| 256 |
+
try:
|
| 257 |
+
parser = get_parser_instance(parser_name)
|
| 258 |
+
description = parser.get_dataset_description()
|
| 259 |
+
return description.category
|
| 260 |
+
except Exception:
|
| 261 |
+
return []
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
def filter_parsers_by_category(category: str | None) -> list[str]:
|
| 265 |
+
"""Filter available parsers by category."""
|
| 266 |
+
if not category:
|
| 267 |
+
return ParserRegistry.list_parsers()
|
| 268 |
+
|
| 269 |
+
filtered_parsers = []
|
| 270 |
+
for parser_name in ParserRegistry.list_parsers():
|
| 271 |
+
categories = get_parser_categories(parser_name)
|
| 272 |
+
if category in categories:
|
| 273 |
+
filtered_parsers.append(parser_name)
|
| 274 |
+
return filtered_parsers
|
| 275 |
+
|
| 276 |
+
|
| 277 |
def create_interface() -> gr.Blocks:
|
| 278 |
"""Create and return the Gradio interface."""
|
| 279 |
with gr.Blocks(css="footer {display: none !important}") as demo:
|
|
|
|
| 303 |
with gr.Tab("Dataset Explorer"):
|
| 304 |
with gr.Row():
|
| 305 |
with gr.Column(scale=1):
|
| 306 |
+
# Add category dropdown before parser selection
|
| 307 |
+
category_dropdown = gr.Dropdown(
|
| 308 |
+
choices=["All"] + list(VALID_CATEGORIES),
|
| 309 |
+
label="Filter by Category",
|
| 310 |
+
value="All",
|
| 311 |
+
interactive=True,
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
# Parser selection and controls
|
| 315 |
available_parsers = ParserRegistry.list_parsers()
|
| 316 |
parser_dropdown = gr.Dropdown(
|
|
|
|
| 377 |
)
|
| 378 |
metric_details = gr.Markdown()
|
| 379 |
|
| 380 |
+
# Add new event handler for category filtering
|
| 381 |
+
def update_parser_list(category: str) -> gr.Dropdown:
|
| 382 |
+
filtered_parsers = filter_parsers_by_category(
|
| 383 |
+
None if category == "All" else category
|
| 384 |
+
)
|
| 385 |
+
return gr.Dropdown(
|
| 386 |
+
choices=filtered_parsers,
|
| 387 |
+
value=filtered_parsers[0] if filtered_parsers else None,
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
category_dropdown.change(
|
| 391 |
+
fn=update_parser_list, inputs=[category_dropdown], outputs=[parser_dropdown]
|
| 392 |
+
)
|
| 393 |
+
|
| 394 |
# Event handlers
|
| 395 |
parser_dropdown.change(
|
| 396 |
fn=update_parser_options,
|