Spaces:
Sleeping
Sleeping
Sync app from GitHub Actions
Browse files- src/ui/app_factory.py +54 -21
- src/ui/theme.py +14 -5
- tests/unit/test_app_factory_audio_helpers.py +14 -0
src/ui/app_factory.py
CHANGED
|
@@ -1638,12 +1638,7 @@ def _select_and_fetch_audio(
|
|
| 1638 |
allow_demo_fallback: bool = False,
|
| 1639 |
hf_token: str | None = None,
|
| 1640 |
) -> tuple[int, str | None, str, str, str | None]:
|
| 1641 |
-
|
| 1642 |
-
selected_index = int(evt.index[0])
|
| 1643 |
-
elif isinstance(evt.index, int):
|
| 1644 |
-
selected_index = int(evt.index)
|
| 1645 |
-
else:
|
| 1646 |
-
selected_index = 0
|
| 1647 |
|
| 1648 |
audio_path, updated_cache_key, status, spectrogram_path = _fetch_selected_audio_with_spectrogram(
|
| 1649 |
audio_service=audio_service,
|
|
@@ -1657,6 +1652,30 @@ def _select_and_fetch_audio(
|
|
| 1657 |
return selected_index, audio_path, updated_cache_key, status, spectrogram_path
|
| 1658 |
|
| 1659 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1660 |
def _normalize_rows(rows: object) -> list[list[object]]:
|
| 1661 |
if hasattr(rows, "values"):
|
| 1662 |
return [list(item) for item in rows.values.tolist()]
|
|
@@ -2595,18 +2614,6 @@ def create_app() -> gr.Blocks:
|
|
| 2595 |
outputs=[token_update_message, token_new_value, token_clear_checkbox, projects_table, seed_warning_state],
|
| 2596 |
)
|
| 2597 |
|
| 2598 |
-
gr.HTML("<div class='bn-spacer'></div>")
|
| 2599 |
-
with gr.Group(elem_classes=["bn-delete-project-panel"]):
|
| 2600 |
-
gr.Markdown("### Delete project")
|
| 2601 |
-
gr.HTML(inline_hint_html("Deleting a project removes assignments and pending invites. It does not delete the Hugging Face dataset.", "danger"))
|
| 2602 |
-
with gr.Row(elem_classes=["bn-delete-project-row"]):
|
| 2603 |
-
delete_project_slug = gr.Dropdown(
|
| 2604 |
-
choices=_project_slugs(),
|
| 2605 |
-
label="Project to delete",
|
| 2606 |
-
)
|
| 2607 |
-
delete_project_btn = gr.Button("Delete Project", variant="stop", elem_classes=["bn-delete-project-action"])
|
| 2608 |
-
delete_project_message = gr.Markdown()
|
| 2609 |
-
|
| 2610 |
def delete_project(session, project_slug: str):
|
| 2611 |
if session is None:
|
| 2612 |
return "Access denied. Login required.", gr.update(), gr.update(), gr.update(), session, gr.update(), gr.update()
|
|
@@ -2759,7 +2766,7 @@ def create_app() -> gr.Blocks:
|
|
| 2759 |
class_name="bn-panel-soft",
|
| 2760 |
)
|
| 2761 |
)
|
| 2762 |
-
with gr.Group(elem_classes=["bn-
|
| 2763 |
with gr.Row():
|
| 2764 |
pending_invites_filter_project = gr.Dropdown(
|
| 2765 |
choices=["all", *_project_slugs()],
|
|
@@ -2860,6 +2867,28 @@ def create_app() -> gr.Blocks:
|
|
| 2860 |
outputs=[pending_invites_table],
|
| 2861 |
)
|
| 2862 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2863 |
delete_project_btn.click(
|
| 2864 |
fn=delete_project,
|
| 2865 |
inputs=[session_state, delete_project_slug],
|
|
@@ -2913,9 +2942,13 @@ def create_app() -> gr.Blocks:
|
|
| 2913 |
)
|
| 2914 |
|
| 2915 |
session_state.change(
|
| 2916 |
-
fn=lambda s: (
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2917 |
inputs=[session_state],
|
| 2918 |
-
outputs=[admin_users_controls, admin_pending_controls],
|
| 2919 |
)
|
| 2920 |
|
| 2921 |
session_state.change(
|
|
|
|
| 1638 |
allow_demo_fallback: bool = False,
|
| 1639 |
hf_token: str | None = None,
|
| 1640 |
) -> tuple[int, str | None, str, str, str | None]:
|
| 1641 |
+
selected_index = _selected_dataframe_row_index(rows, evt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1642 |
|
| 1643 |
audio_path, updated_cache_key, status, spectrogram_path = _fetch_selected_audio_with_spectrogram(
|
| 1644 |
audio_service=audio_service,
|
|
|
|
| 1652 |
return selected_index, audio_path, updated_cache_key, status, spectrogram_path
|
| 1653 |
|
| 1654 |
|
| 1655 |
+
def _selected_dataframe_row_index(rows: object, evt: gr.SelectData) -> int:
|
| 1656 |
+
normalized_rows = _normalize_rows(rows)
|
| 1657 |
+
if not normalized_rows:
|
| 1658 |
+
return 0
|
| 1659 |
+
|
| 1660 |
+
row_value = getattr(evt, "row_value", None)
|
| 1661 |
+
if isinstance(row_value, (list, tuple)) and row_value:
|
| 1662 |
+
detection_key = str(row_value[0]).strip()
|
| 1663 |
+
if detection_key:
|
| 1664 |
+
return _find_detection_row_index(normalized_rows, detection_key)
|
| 1665 |
+
|
| 1666 |
+
raw_index = getattr(evt, "index", None)
|
| 1667 |
+
if isinstance(raw_index, int):
|
| 1668 |
+
return max(0, min(raw_index, len(normalized_rows) - 1))
|
| 1669 |
+
if isinstance(raw_index, tuple):
|
| 1670 |
+
numeric_candidates = [int(value) for value in raw_index if isinstance(value, int)]
|
| 1671 |
+
# Gradio Dataframe events carry a 2-D cell index. If row_value is not
|
| 1672 |
+
# available, prefer the only coordinate that is a valid table row.
|
| 1673 |
+
valid_candidates = [value for value in numeric_candidates if 0 <= value < len(normalized_rows)]
|
| 1674 |
+
if valid_candidates:
|
| 1675 |
+
return valid_candidates[-1]
|
| 1676 |
+
return 0
|
| 1677 |
+
|
| 1678 |
+
|
| 1679 |
def _normalize_rows(rows: object) -> list[list[object]]:
|
| 1680 |
if hasattr(rows, "values"):
|
| 1681 |
return [list(item) for item in rows.values.tolist()]
|
|
|
|
| 2614 |
outputs=[token_update_message, token_new_value, token_clear_checkbox, projects_table, seed_warning_state],
|
| 2615 |
)
|
| 2616 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2617 |
def delete_project(session, project_slug: str):
|
| 2618 |
if session is None:
|
| 2619 |
return "Access denied. Login required.", gr.update(), gr.update(), gr.update(), session, gr.update(), gr.update()
|
|
|
|
| 2766 |
class_name="bn-panel-soft",
|
| 2767 |
)
|
| 2768 |
)
|
| 2769 |
+
with gr.Group(elem_classes=["bn-card-body"]):
|
| 2770 |
with gr.Row():
|
| 2771 |
pending_invites_filter_project = gr.Dropdown(
|
| 2772 |
choices=["all", *_project_slugs()],
|
|
|
|
| 2867 |
outputs=[pending_invites_table],
|
| 2868 |
)
|
| 2869 |
|
| 2870 |
+
with gr.Group(visible=False, elem_classes=["bn-admin-panel", "bn-admin-delete-panel"]) as admin_delete_controls:
|
| 2871 |
+
gr.HTML(
|
| 2872 |
+
section_header_html(
|
| 2873 |
+
"Project",
|
| 2874 |
+
"Delete project",
|
| 2875 |
+
"Remove a project from this validator workspace without deleting its Hugging Face dataset.",
|
| 2876 |
+
class_name="bn-panel-soft",
|
| 2877 |
+
)
|
| 2878 |
+
)
|
| 2879 |
+
with gr.Group(elem_classes=["bn-delete-project-panel"]):
|
| 2880 |
+
gr.HTML(inline_hint_html("Deleting a project removes assignments and pending invites.", "danger"))
|
| 2881 |
+
delete_project_slug = gr.Dropdown(
|
| 2882 |
+
choices=_project_slugs(),
|
| 2883 |
+
label="Project to delete",
|
| 2884 |
+
)
|
| 2885 |
+
delete_project_btn = gr.Button(
|
| 2886 |
+
"Delete Project",
|
| 2887 |
+
variant="stop",
|
| 2888 |
+
elem_classes=["bn-delete-project-action"],
|
| 2889 |
+
)
|
| 2890 |
+
delete_project_message = gr.Markdown()
|
| 2891 |
+
|
| 2892 |
delete_project_btn.click(
|
| 2893 |
fn=delete_project,
|
| 2894 |
inputs=[session_state, delete_project_slug],
|
|
|
|
| 2942 |
)
|
| 2943 |
|
| 2944 |
session_state.change(
|
| 2945 |
+
fn=lambda s: (
|
| 2946 |
+
gr.update(visible=bool(s is not None)),
|
| 2947 |
+
gr.update(visible=bool(s is not None)),
|
| 2948 |
+
gr.update(visible=bool(s is not None)),
|
| 2949 |
+
),
|
| 2950 |
inputs=[session_state],
|
| 2951 |
+
outputs=[admin_users_controls, admin_pending_controls, admin_delete_controls],
|
| 2952 |
)
|
| 2953 |
|
| 2954 |
session_state.change(
|
src/ui/theme.py
CHANGED
|
@@ -580,6 +580,18 @@ body,
|
|
| 580 |
padding: 14px;
|
| 581 |
}
|
| 582 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 583 |
.bn-admin-access-panel,
|
| 584 |
.bn-admin-pending-panel {
|
| 585 |
width: 100% !important;
|
|
@@ -630,12 +642,9 @@ button.bn-soft-action:hover {
|
|
| 630 |
background: #fff1f2;
|
| 631 |
}
|
| 632 |
|
| 633 |
-
.bn-delete-project-row {
|
| 634 |
-
align-items: flex-end !important;
|
| 635 |
-
gap: 12px !important;
|
| 636 |
-
}
|
| 637 |
-
|
| 638 |
.bn-delete-project-action button {
|
|
|
|
|
|
|
| 639 |
min-height: 54px !important;
|
| 640 |
border-radius: 8px !important;
|
| 641 |
font-weight: 790 !important;
|
|
|
|
| 580 |
padding: 14px;
|
| 581 |
}
|
| 582 |
|
| 583 |
+
.bn-admin-panel .block,
|
| 584 |
+
.bn-admin-panel .form,
|
| 585 |
+
.bn-card-body {
|
| 586 |
+
background: #ffffff !important;
|
| 587 |
+
}
|
| 588 |
+
|
| 589 |
+
.bn-card-body {
|
| 590 |
+
border: 1px solid var(--bn-border) !important;
|
| 591 |
+
border-radius: 8px !important;
|
| 592 |
+
padding: 12px !important;
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
.bn-admin-access-panel,
|
| 596 |
.bn-admin-pending-panel {
|
| 597 |
width: 100% !important;
|
|
|
|
| 642 |
background: #fff1f2;
|
| 643 |
}
|
| 644 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
.bn-delete-project-action button {
|
| 646 |
+
width: 100% !important;
|
| 647 |
+
margin-top: 2px !important;
|
| 648 |
min-height: 54px !important;
|
| 649 |
border-radius: 8px !important;
|
| 650 |
font-weight: 790 !important;
|
tests/unit/test_app_factory_audio_helpers.py
CHANGED
|
@@ -18,6 +18,7 @@ from src.ui.app_factory import (
|
|
| 18 |
_post_validation_queue_anchor,
|
| 19 |
_save_selected_validation,
|
| 20 |
_save_selected_validation_with_refresh,
|
|
|
|
| 21 |
_reapply_last_conflict_validation_with_refresh,
|
| 22 |
_batch_validate_conflicts,
|
| 23 |
create_app,
|
|
@@ -429,6 +430,19 @@ def test_find_detection_row_index() -> None:
|
|
| 429 |
assert _find_detection_row_index(rows, "missing") == 0
|
| 430 |
|
| 431 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 432 |
def test_post_validation_queue_anchor_keeps_next_row_when_saved_row_leaves_filtered_page() -> None:
|
| 433 |
rows = [["dkey_02", "audio_02"], ["dkey_03", "audio_03"]]
|
| 434 |
|
|
|
|
| 18 |
_post_validation_queue_anchor,
|
| 19 |
_save_selected_validation,
|
| 20 |
_save_selected_validation_with_refresh,
|
| 21 |
+
_selected_dataframe_row_index,
|
| 22 |
_reapply_last_conflict_validation_with_refresh,
|
| 23 |
_batch_validate_conflicts,
|
| 24 |
create_app,
|
|
|
|
| 430 |
assert _find_detection_row_index(rows, "missing") == 0
|
| 431 |
|
| 432 |
|
| 433 |
+
def test_selected_dataframe_row_index_prefers_selected_row_value() -> None:
|
| 434 |
+
class FakeSelectEvent:
|
| 435 |
+
index = (2, 0)
|
| 436 |
+
row_value = ["dkey_02", "audio_02", "Species 2"]
|
| 437 |
+
|
| 438 |
+
rows = [
|
| 439 |
+
["dkey_01", "audio_01", "Species 1"],
|
| 440 |
+
["dkey_02", "audio_02", "Species 2"],
|
| 441 |
+
]
|
| 442 |
+
|
| 443 |
+
assert _selected_dataframe_row_index(rows, FakeSelectEvent()) == 1
|
| 444 |
+
|
| 445 |
+
|
| 446 |
def test_post_validation_queue_anchor_keeps_next_row_when_saved_row_leaves_filtered_page() -> None:
|
| 447 |
rows = [["dkey_02", "audio_02"], ["dkey_03", "audio_03"]]
|
| 448 |
|