Spaces:
Sleeping
Sleeping
Commit ·
9b4331d
1
Parent(s): 922e525
feat(ui): auto-refresh table and focus row after validation conflicts
Browse files- src/ui/app_factory.py +102 -12
src/ui/app_factory.py
CHANGED
|
@@ -193,6 +193,20 @@ def _extract_detection_key(rows: object, selected_index: int) -> str:
|
|
| 193 |
return detection_key
|
| 194 |
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
def _extract_expected_version(rows: object, selected_index: int) -> int:
|
| 197 |
normalized_rows: list[list[object]]
|
| 198 |
|
|
@@ -280,6 +294,62 @@ def _save_selected_validation(
|
|
| 280 |
return f"Falha ao salvar validacao: {exc}", cache_key, None
|
| 281 |
|
| 282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
def create_app() -> gr.Blocks:
|
| 284 |
project_slug = "demo-project"
|
| 285 |
service = _seed_service()
|
|
@@ -402,9 +472,11 @@ def create_app() -> gr.Blocks:
|
|
| 402 |
outputs=[status, audio_player],
|
| 403 |
)
|
| 404 |
approve_btn.click(
|
| 405 |
-
fn=lambda rows, idx, name, notes, cache_key:
|
| 406 |
validation_service=validation_service,
|
| 407 |
audio_service=audio_service,
|
|
|
|
|
|
|
| 408 |
project_slug=project_slug,
|
| 409 |
rows=rows,
|
| 410 |
selected_index=int(idx),
|
|
@@ -412,14 +484,19 @@ def create_app() -> gr.Blocks:
|
|
| 412 |
validator=name,
|
| 413 |
notes=notes,
|
| 414 |
cache_key=cache_key,
|
|
|
|
|
|
|
|
|
|
| 415 |
),
|
| 416 |
-
inputs=[table, selected_index, validator_name, validation_notes, cache_key_state],
|
| 417 |
-
outputs=[status, cache_key_state, audio_player],
|
| 418 |
)
|
| 419 |
reject_btn.click(
|
| 420 |
-
fn=lambda rows, idx, name, notes, cache_key:
|
| 421 |
validation_service=validation_service,
|
| 422 |
audio_service=audio_service,
|
|
|
|
|
|
|
| 423 |
project_slug=project_slug,
|
| 424 |
rows=rows,
|
| 425 |
selected_index=int(idx),
|
|
@@ -427,14 +504,19 @@ def create_app() -> gr.Blocks:
|
|
| 427 |
validator=name,
|
| 428 |
notes=notes,
|
| 429 |
cache_key=cache_key,
|
|
|
|
|
|
|
|
|
|
| 430 |
),
|
| 431 |
-
inputs=[table, selected_index, validator_name, validation_notes, cache_key_state],
|
| 432 |
-
outputs=[status, cache_key_state, audio_player],
|
| 433 |
)
|
| 434 |
uncertain_btn.click(
|
| 435 |
-
fn=lambda rows, idx, name, notes, cache_key:
|
| 436 |
validation_service=validation_service,
|
| 437 |
audio_service=audio_service,
|
|
|
|
|
|
|
| 438 |
project_slug=project_slug,
|
| 439 |
rows=rows,
|
| 440 |
selected_index=int(idx),
|
|
@@ -442,14 +524,19 @@ def create_app() -> gr.Blocks:
|
|
| 442 |
validator=name,
|
| 443 |
notes=notes,
|
| 444 |
cache_key=cache_key,
|
|
|
|
|
|
|
|
|
|
| 445 |
),
|
| 446 |
-
inputs=[table, selected_index, validator_name, validation_notes, cache_key_state],
|
| 447 |
-
outputs=[status, cache_key_state, audio_player],
|
| 448 |
)
|
| 449 |
skip_btn.click(
|
| 450 |
-
fn=lambda rows, idx, name, notes, cache_key:
|
| 451 |
validation_service=validation_service,
|
| 452 |
audio_service=audio_service,
|
|
|
|
|
|
|
| 453 |
project_slug=project_slug,
|
| 454 |
rows=rows,
|
| 455 |
selected_index=int(idx),
|
|
@@ -457,9 +544,12 @@ def create_app() -> gr.Blocks:
|
|
| 457 |
validator=name,
|
| 458 |
notes=notes,
|
| 459 |
cache_key=cache_key,
|
|
|
|
|
|
|
|
|
|
| 460 |
),
|
| 461 |
-
inputs=[table, selected_index, validator_name, validation_notes, cache_key_state],
|
| 462 |
-
outputs=[status, cache_key_state, audio_player],
|
| 463 |
)
|
| 464 |
report_btn.click(
|
| 465 |
fn=lambda: _build_validation_report(validation_repository, project_slug),
|
|
|
|
| 193 |
return detection_key
|
| 194 |
|
| 195 |
|
| 196 |
+
def _find_detection_row_index(rows: object, detection_key: str) -> int:
|
| 197 |
+
normalized_rows: list[list[object]]
|
| 198 |
+
|
| 199 |
+
if hasattr(rows, "values"):
|
| 200 |
+
normalized_rows = [list(item) for item in rows.values.tolist()]
|
| 201 |
+
else:
|
| 202 |
+
normalized_rows = [list(item) for item in rows] if rows else []
|
| 203 |
+
|
| 204 |
+
for index, row in enumerate(normalized_rows):
|
| 205 |
+
if str(row[0]).strip() == detection_key:
|
| 206 |
+
return index
|
| 207 |
+
return 0
|
| 208 |
+
|
| 209 |
+
|
| 210 |
def _extract_expected_version(rows: object, selected_index: int) -> int:
|
| 211 |
normalized_rows: list[list[object]]
|
| 212 |
|
|
|
|
| 294 |
return f"Falha ao salvar validacao: {exc}", cache_key, None
|
| 295 |
|
| 296 |
|
| 297 |
+
def _save_selected_validation_with_refresh(
|
| 298 |
+
validation_service: _ValidationServiceProtocol,
|
| 299 |
+
audio_service: _AudioServiceProtocol,
|
| 300 |
+
queue_service: _QueueServiceProtocol,
|
| 301 |
+
snapshot_reader: _ValidationReadRepositoryProtocol,
|
| 302 |
+
project_slug: str,
|
| 303 |
+
rows: object,
|
| 304 |
+
selected_index: int,
|
| 305 |
+
status_value: str,
|
| 306 |
+
validator: str,
|
| 307 |
+
notes: str,
|
| 308 |
+
cache_key: str,
|
| 309 |
+
page: int,
|
| 310 |
+
scientific_name: str,
|
| 311 |
+
min_confidence: float,
|
| 312 |
+
) -> tuple[str, str, str | None, list[list[object]], int, int]:
|
| 313 |
+
selected_key = ""
|
| 314 |
+
try:
|
| 315 |
+
selected_key = _extract_detection_key(rows=rows, selected_index=selected_index)
|
| 316 |
+
except Exception:
|
| 317 |
+
selected_key = ""
|
| 318 |
+
|
| 319 |
+
save_status, updated_cache_key, audio_path = _save_selected_validation(
|
| 320 |
+
validation_service=validation_service,
|
| 321 |
+
audio_service=audio_service,
|
| 322 |
+
project_slug=project_slug,
|
| 323 |
+
rows=rows,
|
| 324 |
+
selected_index=selected_index,
|
| 325 |
+
status_value=status_value,
|
| 326 |
+
validator=validator,
|
| 327 |
+
notes=notes,
|
| 328 |
+
cache_key=cache_key,
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
refreshed_rows, page_status, refreshed_page = _page_to_table(
|
| 332 |
+
service=queue_service,
|
| 333 |
+
snapshot_reader=snapshot_reader,
|
| 334 |
+
project_slug=project_slug,
|
| 335 |
+
page=page,
|
| 336 |
+
scientific_name=scientific_name,
|
| 337 |
+
min_confidence=min_confidence,
|
| 338 |
+
)
|
| 339 |
+
|
| 340 |
+
if selected_key:
|
| 341 |
+
refreshed_index = _find_detection_row_index(refreshed_rows, selected_key)
|
| 342 |
+
else:
|
| 343 |
+
refreshed_index = 0
|
| 344 |
+
|
| 345 |
+
if "Conflito de concorrencia" in save_status:
|
| 346 |
+
status = f"{save_status} Tabela recarregada para resolver conflito."
|
| 347 |
+
else:
|
| 348 |
+
status = f"{save_status} | {page_status}"
|
| 349 |
+
|
| 350 |
+
return status, updated_cache_key, audio_path, refreshed_rows, refreshed_page, refreshed_index
|
| 351 |
+
|
| 352 |
+
|
| 353 |
def create_app() -> gr.Blocks:
|
| 354 |
project_slug = "demo-project"
|
| 355 |
service = _seed_service()
|
|
|
|
| 472 |
outputs=[status, audio_player],
|
| 473 |
)
|
| 474 |
approve_btn.click(
|
| 475 |
+
fn=lambda rows, idx, name, notes, cache_key, page, species, confidence: _save_selected_validation_with_refresh(
|
| 476 |
validation_service=validation_service,
|
| 477 |
audio_service=audio_service,
|
| 478 |
+
queue_service=service,
|
| 479 |
+
snapshot_reader=validation_repository,
|
| 480 |
project_slug=project_slug,
|
| 481 |
rows=rows,
|
| 482 |
selected_index=int(idx),
|
|
|
|
| 484 |
validator=name,
|
| 485 |
notes=notes,
|
| 486 |
cache_key=cache_key,
|
| 487 |
+
page=int(page),
|
| 488 |
+
scientific_name=species,
|
| 489 |
+
min_confidence=float(confidence),
|
| 490 |
),
|
| 491 |
+
inputs=[table, selected_index, validator_name, validation_notes, cache_key_state, page_state, species_filter, min_confidence],
|
| 492 |
+
outputs=[status, cache_key_state, audio_player, table, page_state, selected_index],
|
| 493 |
)
|
| 494 |
reject_btn.click(
|
| 495 |
+
fn=lambda rows, idx, name, notes, cache_key, page, species, confidence: _save_selected_validation_with_refresh(
|
| 496 |
validation_service=validation_service,
|
| 497 |
audio_service=audio_service,
|
| 498 |
+
queue_service=service,
|
| 499 |
+
snapshot_reader=validation_repository,
|
| 500 |
project_slug=project_slug,
|
| 501 |
rows=rows,
|
| 502 |
selected_index=int(idx),
|
|
|
|
| 504 |
validator=name,
|
| 505 |
notes=notes,
|
| 506 |
cache_key=cache_key,
|
| 507 |
+
page=int(page),
|
| 508 |
+
scientific_name=species,
|
| 509 |
+
min_confidence=float(confidence),
|
| 510 |
),
|
| 511 |
+
inputs=[table, selected_index, validator_name, validation_notes, cache_key_state, page_state, species_filter, min_confidence],
|
| 512 |
+
outputs=[status, cache_key_state, audio_player, table, page_state, selected_index],
|
| 513 |
)
|
| 514 |
uncertain_btn.click(
|
| 515 |
+
fn=lambda rows, idx, name, notes, cache_key, page, species, confidence: _save_selected_validation_with_refresh(
|
| 516 |
validation_service=validation_service,
|
| 517 |
audio_service=audio_service,
|
| 518 |
+
queue_service=service,
|
| 519 |
+
snapshot_reader=validation_repository,
|
| 520 |
project_slug=project_slug,
|
| 521 |
rows=rows,
|
| 522 |
selected_index=int(idx),
|
|
|
|
| 524 |
validator=name,
|
| 525 |
notes=notes,
|
| 526 |
cache_key=cache_key,
|
| 527 |
+
page=int(page),
|
| 528 |
+
scientific_name=species,
|
| 529 |
+
min_confidence=float(confidence),
|
| 530 |
),
|
| 531 |
+
inputs=[table, selected_index, validator_name, validation_notes, cache_key_state, page_state, species_filter, min_confidence],
|
| 532 |
+
outputs=[status, cache_key_state, audio_player, table, page_state, selected_index],
|
| 533 |
)
|
| 534 |
skip_btn.click(
|
| 535 |
+
fn=lambda rows, idx, name, notes, cache_key, page, species, confidence: _save_selected_validation_with_refresh(
|
| 536 |
validation_service=validation_service,
|
| 537 |
audio_service=audio_service,
|
| 538 |
+
queue_service=service,
|
| 539 |
+
snapshot_reader=validation_repository,
|
| 540 |
project_slug=project_slug,
|
| 541 |
rows=rows,
|
| 542 |
selected_index=int(idx),
|
|
|
|
| 544 |
validator=name,
|
| 545 |
notes=notes,
|
| 546 |
cache_key=cache_key,
|
| 547 |
+
page=int(page),
|
| 548 |
+
scientific_name=species,
|
| 549 |
+
min_confidence=float(confidence),
|
| 550 |
),
|
| 551 |
+
inputs=[table, selected_index, validator_name, validation_notes, cache_key_state, page_state, species_filter, min_confidence],
|
| 552 |
+
outputs=[status, cache_key_state, audio_player, table, page_state, selected_index],
|
| 553 |
)
|
| 554 |
report_btn.click(
|
| 555 |
fn=lambda: _build_validation_report(validation_repository, project_slug),
|