Spaces:
Sleeping
Sleeping
Commit ·
a48525e
1
Parent(s): 0c1027f
feat(ui): improve layout, add Report tab, fix spectrogram title, remove report button from validation
Browse files- src/ui/app_factory.py +158 -37
- src/ui/login_page.py +30 -24
src/ui/app_factory.py
CHANGED
|
@@ -1336,24 +1336,36 @@ def _normalize_rows(rows: object) -> list[list[object]]:
|
|
| 1336 |
return [list(item) for item in rows] if rows else []
|
| 1337 |
|
| 1338 |
|
| 1339 |
-
def _spectrogram_title(
|
| 1340 |
-
if not
|
| 1341 |
return "### Spectrogram"
|
| 1342 |
-
return f"###
|
| 1343 |
|
| 1344 |
|
| 1345 |
-
def
|
| 1346 |
-
if audio_path:
|
| 1347 |
-
return Path(audio_path).name
|
| 1348 |
-
|
| 1349 |
normalized_rows = _normalize_rows(rows)
|
| 1350 |
if normalized_rows:
|
| 1351 |
safe_index = max(0, min(int(selected_index), len(normalized_rows) - 1))
|
| 1352 |
-
|
| 1353 |
-
|
| 1354 |
-
|
| 1355 |
-
|
| 1356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1357 |
|
| 1358 |
|
| 1359 |
def _mark_selected_row(rows: object, selected_index: int) -> list[list[object]]:
|
|
@@ -1438,8 +1450,8 @@ def _fetch_selected_audio_with_title(
|
|
| 1438 |
allow_demo_fallback=allow_demo_fallback,
|
| 1439 |
hf_token=hf_token,
|
| 1440 |
)
|
| 1441 |
-
|
| 1442 |
-
return audio_path, cache_key, status, spectrogram_path, _spectrogram_title(
|
| 1443 |
|
| 1444 |
|
| 1445 |
def _select_and_fetch_audio_with_title(
|
|
@@ -1460,14 +1472,14 @@ def _select_and_fetch_audio_with_title(
|
|
| 1460 |
allow_demo_fallback=allow_demo_fallback,
|
| 1461 |
hf_token=hf_token,
|
| 1462 |
)
|
| 1463 |
-
|
| 1464 |
return (
|
| 1465 |
selected_index,
|
| 1466 |
audio_path,
|
| 1467 |
updated_cache_key,
|
| 1468 |
status,
|
| 1469 |
spectrogram_path,
|
| 1470 |
-
_spectrogram_title(
|
| 1471 |
)
|
| 1472 |
|
| 1473 |
|
|
@@ -1487,14 +1499,14 @@ def _autofetch_first_row_with_title(
|
|
| 1487 |
allow_demo_fallback=allow_demo_fallback,
|
| 1488 |
hf_token=hf_token,
|
| 1489 |
)
|
| 1490 |
-
|
| 1491 |
return (
|
| 1492 |
selected_index,
|
| 1493 |
audio_path,
|
| 1494 |
updated_cache_key,
|
| 1495 |
status,
|
| 1496 |
spectrogram_path,
|
| 1497 |
-
_spectrogram_title(
|
| 1498 |
)
|
| 1499 |
|
| 1500 |
|
|
@@ -1509,7 +1521,7 @@ def _advance_to_next_row_with_title(
|
|
| 1509 |
) -> tuple[int, str | None, str, str, str | None, str]:
|
| 1510 |
normalized_rows = _normalize_rows(rows)
|
| 1511 |
if not normalized_rows:
|
| 1512 |
-
return 0, None, cache_key, "No detections available", None, _spectrogram_title(None)
|
| 1513 |
|
| 1514 |
safe_index = max(0, min(int(selected_index) + 1, len(normalized_rows) - 1))
|
| 1515 |
audio_path, updated_cache_key, status, spectrogram_path = _fetch_selected_audio_with_spectrogram(
|
|
@@ -1521,8 +1533,8 @@ def _advance_to_next_row_with_title(
|
|
| 1521 |
allow_demo_fallback=allow_demo_fallback,
|
| 1522 |
hf_token=hf_token,
|
| 1523 |
)
|
| 1524 |
-
|
| 1525 |
-
return safe_index, audio_path, updated_cache_key, status, spectrogram_path, _spectrogram_title(
|
| 1526 |
|
| 1527 |
|
| 1528 |
def _cleanup_selected_audio(audio_service: _AudioServiceProtocol, cache_key: str) -> tuple[str, str | None]:
|
|
@@ -1628,6 +1640,7 @@ def _save_selected_validation_with_refresh(
|
|
| 1628 |
updated_after=updated_after,
|
| 1629 |
show_conflicts_only=show_conflicts_only,
|
| 1630 |
)
|
|
|
|
| 1631 |
|
| 1632 |
if selected_key:
|
| 1633 |
refreshed_index = _find_detection_row_index(refreshed_rows, selected_key)
|
|
@@ -1649,6 +1662,7 @@ def _save_selected_validation_with_refresh(
|
|
| 1649 |
conflict_detection_key=conflict_key,
|
| 1650 |
show_conflicts_only=show_conflicts_only,
|
| 1651 |
)
|
|
|
|
| 1652 |
refreshed_index = _find_detection_row_index(refreshed_rows, selected_key) if selected_key else 0
|
| 1653 |
pending_status_value = status_value
|
| 1654 |
status = f"{save_status} Table reloaded to resolve conflict."
|
|
@@ -1703,6 +1717,7 @@ def _reapply_last_conflict_validation_with_refresh(
|
|
| 1703 |
updated_after=updated_after,
|
| 1704 |
show_conflicts_only=show_conflicts_only,
|
| 1705 |
)
|
|
|
|
| 1706 |
return (
|
| 1707 |
f"No pending validation to reapply | {page_status}",
|
| 1708 |
cache_key,
|
|
@@ -1810,6 +1825,7 @@ def _batch_validate_conflicts(
|
|
| 1810 |
updated_after=updated_after,
|
| 1811 |
show_conflicts_only=False,
|
| 1812 |
)
|
|
|
|
| 1813 |
|
| 1814 |
summary = f"Processed {len(conflict_rows)} conflicts: {success_count} success, {conflict_count} new conflicts, {failure_count} failures"
|
| 1815 |
status = f"{summary} | {page_status}"
|
|
@@ -1881,6 +1897,7 @@ def _batch_reapply_all_pending(
|
|
| 1881 |
updated_after=updated_after,
|
| 1882 |
show_conflicts_only=False,
|
| 1883 |
)
|
|
|
|
| 1884 |
|
| 1885 |
summary = f"Reapplied {len(pending_statuses)} validations: {success_count} success, {conflict_count} new conflicts, {failure_count} failures"
|
| 1886 |
status = f"{summary} | {page_status}"
|
|
@@ -1970,14 +1987,11 @@ def build_demo_app(project_slug: str = "demo-project") -> gr.Blocks:
|
|
| 1970 |
batch_approve_conflicts_btn = gr.Button("Approve all conflicts")
|
| 1971 |
batch_reject_conflicts_btn = gr.Button("Reject all conflicts")
|
| 1972 |
|
| 1973 |
-
report_btn = gr.Button("Generate validation report")
|
| 1974 |
-
|
| 1975 |
audio_player = gr.Audio(label="On-demand audio", type="filepath")
|
| 1976 |
cache_key_state = gr.State(value="")
|
| 1977 |
pending_status_state = gr.State(value="")
|
| 1978 |
conflict_detection_key_state = gr.State(value="")
|
| 1979 |
status = gr.Textbox(label="Status", interactive=False)
|
| 1980 |
-
report_box = gr.Textbox(label="Report", interactive=False)
|
| 1981 |
|
| 1982 |
# Keyboard shortcuts: 1=positive, 2=negative, 3=uncertain, 4=skip, R=reapply
|
| 1983 |
keyboard_shortcuts_info = gr.HTML(
|
|
@@ -2406,11 +2420,6 @@ def build_demo_app(project_slug: str = "demo-project") -> gr.Blocks:
|
|
| 2406 |
],
|
| 2407 |
outputs=[status, cache_key_state, audio_player, table, page_state],
|
| 2408 |
)
|
| 2409 |
-
report_btn.click(
|
| 2410 |
-
fn=lambda: _build_validation_report(validation_repository, project_slug),
|
| 2411 |
-
inputs=None,
|
| 2412 |
-
outputs=[report_box],
|
| 2413 |
-
)
|
| 2414 |
|
| 2415 |
return demo
|
| 2416 |
|
|
@@ -2696,6 +2705,8 @@ def create_app() -> gr.Blocks:
|
|
| 2696 |
)
|
| 2697 |
refresh_projects_btn = gr.Button("🔄 Refresh List")
|
| 2698 |
|
|
|
|
|
|
|
| 2699 |
def _render_admin_scope_info(session, selected_admin_project: str):
|
| 2700 |
if session is None:
|
| 2701 |
return ""
|
|
@@ -2854,6 +2865,8 @@ def create_app() -> gr.Blocks:
|
|
| 2854 |
outputs=[admin_message, admin_username, admin_project, admin_role],
|
| 2855 |
)
|
| 2856 |
|
|
|
|
|
|
|
| 2857 |
gr.Markdown("#### Delete Project")
|
| 2858 |
with gr.Row():
|
| 2859 |
delete_project_slug = gr.Dropdown(
|
|
@@ -2910,6 +2923,8 @@ def create_app() -> gr.Blocks:
|
|
| 2910 |
],
|
| 2911 |
)
|
| 2912 |
|
|
|
|
|
|
|
| 2913 |
gr.Markdown("#### Pending Invites")
|
| 2914 |
with gr.Row():
|
| 2915 |
pending_invites_filter_project = gr.Dropdown(
|
|
@@ -3042,6 +3057,12 @@ def create_app() -> gr.Blocks:
|
|
| 3042 |
outputs=[admin_users_controls],
|
| 3043 |
)
|
| 3044 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3045 |
session_state.change(
|
| 3046 |
fn=lambda s: (
|
| 3047 |
gr.update(choices=_admin_projects_for_session(s), value=None),
|
|
@@ -3429,8 +3450,6 @@ def create_app() -> gr.Blocks:
|
|
| 3429 |
gr.Markdown("#### Actions")
|
| 3430 |
validator_name = gr.Textbox(label="Validator", value="validator-demo")
|
| 3431 |
validation_notes = gr.Textbox(label="Notes", placeholder="Optional", lines=4)
|
| 3432 |
-
report_btn = gr.Button("Generate validation report")
|
| 3433 |
-
|
| 3434 |
keyboard_shortcuts_info = gr.HTML(
|
| 3435 |
value="<div style='font-size:12px;color:#333;padding:8px 10px;background:#f5f5f5;border-radius:6px;margin-bottom:8px;'>"
|
| 3436 |
"<strong>Shortcuts:</strong> ArrowUp=Positive | ArrowDown=Negative | 1=Positive | 2=Negative | 3=Uncertain | 4=Skip"
|
|
@@ -3457,8 +3476,6 @@ def create_app() -> gr.Blocks:
|
|
| 3457 |
cache_key_state = gr.State(value="")
|
| 3458 |
pending_status_state = gr.State(value="")
|
| 3459 |
conflict_detection_key_state = gr.State(value="")
|
| 3460 |
-
report_box = gr.Textbox(label="Report", interactive=False)
|
| 3461 |
-
|
| 3462 |
def _session_hf_token(session) -> str | None:
|
| 3463 |
if session is None:
|
| 3464 |
return None
|
|
@@ -3548,7 +3565,7 @@ def create_app() -> gr.Blocks:
|
|
| 3548 |
|
| 3549 |
def refresh_for_selected_project(project_slug: str):
|
| 3550 |
if not project_slug:
|
| 3551 |
-
return gr.update(choices=[], value=None, interactive=False), [], "", 1, None, None, _spectrogram_title(None), _build_validation_summary_cards([]), gr.update(choices=["Noise", "Undetermined"], value=None), []
|
| 3552 |
|
| 3553 |
species_options = _extract_species_options_from_queue(
|
| 3554 |
queue_service=service_ref["queue"],
|
|
@@ -4210,10 +4227,114 @@ def create_app() -> gr.Blocks:
|
|
| 4210 |
outputs=[validator_name],
|
| 4211 |
)
|
| 4212 |
|
| 4213 |
-
|
| 4214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4215 |
inputs=[selected_project_state],
|
| 4216 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4217 |
)
|
| 4218 |
|
| 4219 |
return wrapper
|
|
|
|
| 1336 |
return [list(item) for item in rows] if rows else []
|
| 1337 |
|
| 1338 |
|
| 1339 |
+
def _spectrogram_title(species_name: str | None, confidence: float | None) -> str:
|
| 1340 |
+
if not species_name or confidence is None:
|
| 1341 |
return "### Spectrogram"
|
| 1342 |
+
return f"### {species_name} - {confidence:.3f}"
|
| 1343 |
|
| 1344 |
|
| 1345 |
+
def _selected_row_species_and_confidence(rows: object, selected_index: int) -> tuple[str | None, float | None]:
|
|
|
|
|
|
|
|
|
|
| 1346 |
normalized_rows = _normalize_rows(rows)
|
| 1347 |
if normalized_rows:
|
| 1348 |
safe_index = max(0, min(int(selected_index), len(normalized_rows) - 1))
|
| 1349 |
+
row = normalized_rows[safe_index]
|
| 1350 |
+
|
| 1351 |
+
species_name: str | None = None
|
| 1352 |
+
confidence_value: float | None = None
|
| 1353 |
+
|
| 1354 |
+
if len(row) > 2:
|
| 1355 |
+
raw_species = str(row[2]).strip()
|
| 1356 |
+
if raw_species.startswith("▶ "):
|
| 1357 |
+
raw_species = raw_species[2:].strip()
|
| 1358 |
+
species_name = raw_species or None
|
| 1359 |
+
|
| 1360 |
+
if len(row) > 3:
|
| 1361 |
+
try:
|
| 1362 |
+
confidence_value = float(row[3])
|
| 1363 |
+
except Exception:
|
| 1364 |
+
confidence_value = None
|
| 1365 |
+
|
| 1366 |
+
return species_name, confidence_value
|
| 1367 |
+
|
| 1368 |
+
return None, None
|
| 1369 |
|
| 1370 |
|
| 1371 |
def _mark_selected_row(rows: object, selected_index: int) -> list[list[object]]:
|
|
|
|
| 1450 |
allow_demo_fallback=allow_demo_fallback,
|
| 1451 |
hf_token=hf_token,
|
| 1452 |
)
|
| 1453 |
+
species_name, confidence_value = _selected_row_species_and_confidence(rows, selected_index)
|
| 1454 |
+
return audio_path, cache_key, status, spectrogram_path, _spectrogram_title(species_name, confidence_value)
|
| 1455 |
|
| 1456 |
|
| 1457 |
def _select_and_fetch_audio_with_title(
|
|
|
|
| 1472 |
allow_demo_fallback=allow_demo_fallback,
|
| 1473 |
hf_token=hf_token,
|
| 1474 |
)
|
| 1475 |
+
species_name, confidence_value = _selected_row_species_and_confidence(rows, selected_index)
|
| 1476 |
return (
|
| 1477 |
selected_index,
|
| 1478 |
audio_path,
|
| 1479 |
updated_cache_key,
|
| 1480 |
status,
|
| 1481 |
spectrogram_path,
|
| 1482 |
+
_spectrogram_title(species_name, confidence_value),
|
| 1483 |
)
|
| 1484 |
|
| 1485 |
|
|
|
|
| 1499 |
allow_demo_fallback=allow_demo_fallback,
|
| 1500 |
hf_token=hf_token,
|
| 1501 |
)
|
| 1502 |
+
species_name, confidence_value = _selected_row_species_and_confidence(rows, selected_index)
|
| 1503 |
return (
|
| 1504 |
selected_index,
|
| 1505 |
audio_path,
|
| 1506 |
updated_cache_key,
|
| 1507 |
status,
|
| 1508 |
spectrogram_path,
|
| 1509 |
+
_spectrogram_title(species_name, confidence_value),
|
| 1510 |
)
|
| 1511 |
|
| 1512 |
|
|
|
|
| 1521 |
) -> tuple[int, str | None, str, str, str | None, str]:
|
| 1522 |
normalized_rows = _normalize_rows(rows)
|
| 1523 |
if not normalized_rows:
|
| 1524 |
+
return 0, None, cache_key, "No detections available", None, _spectrogram_title(None, None)
|
| 1525 |
|
| 1526 |
safe_index = max(0, min(int(selected_index) + 1, len(normalized_rows) - 1))
|
| 1527 |
audio_path, updated_cache_key, status, spectrogram_path = _fetch_selected_audio_with_spectrogram(
|
|
|
|
| 1533 |
allow_demo_fallback=allow_demo_fallback,
|
| 1534 |
hf_token=hf_token,
|
| 1535 |
)
|
| 1536 |
+
species_name, confidence_value = _selected_row_species_and_confidence(normalized_rows, safe_index)
|
| 1537 |
+
return safe_index, audio_path, updated_cache_key, status, spectrogram_path, _spectrogram_title(species_name, confidence_value)
|
| 1538 |
|
| 1539 |
|
| 1540 |
def _cleanup_selected_audio(audio_service: _AudioServiceProtocol, cache_key: str) -> tuple[str, str | None]:
|
|
|
|
| 1640 |
updated_after=updated_after,
|
| 1641 |
show_conflicts_only=show_conflicts_only,
|
| 1642 |
)
|
| 1643 |
+
refreshed_rows = _sort_rows_by_confidence_desc(refreshed_rows)
|
| 1644 |
|
| 1645 |
if selected_key:
|
| 1646 |
refreshed_index = _find_detection_row_index(refreshed_rows, selected_key)
|
|
|
|
| 1662 |
conflict_detection_key=conflict_key,
|
| 1663 |
show_conflicts_only=show_conflicts_only,
|
| 1664 |
)
|
| 1665 |
+
refreshed_rows = _sort_rows_by_confidence_desc(refreshed_rows)
|
| 1666 |
refreshed_index = _find_detection_row_index(refreshed_rows, selected_key) if selected_key else 0
|
| 1667 |
pending_status_value = status_value
|
| 1668 |
status = f"{save_status} Table reloaded to resolve conflict."
|
|
|
|
| 1717 |
updated_after=updated_after,
|
| 1718 |
show_conflicts_only=show_conflicts_only,
|
| 1719 |
)
|
| 1720 |
+
refreshed_rows = _sort_rows_by_confidence_desc(refreshed_rows)
|
| 1721 |
return (
|
| 1722 |
f"No pending validation to reapply | {page_status}",
|
| 1723 |
cache_key,
|
|
|
|
| 1825 |
updated_after=updated_after,
|
| 1826 |
show_conflicts_only=False,
|
| 1827 |
)
|
| 1828 |
+
refreshed_rows = _sort_rows_by_confidence_desc(refreshed_rows)
|
| 1829 |
|
| 1830 |
summary = f"Processed {len(conflict_rows)} conflicts: {success_count} success, {conflict_count} new conflicts, {failure_count} failures"
|
| 1831 |
status = f"{summary} | {page_status}"
|
|
|
|
| 1897 |
updated_after=updated_after,
|
| 1898 |
show_conflicts_only=False,
|
| 1899 |
)
|
| 1900 |
+
refreshed_rows = _sort_rows_by_confidence_desc(refreshed_rows)
|
| 1901 |
|
| 1902 |
summary = f"Reapplied {len(pending_statuses)} validations: {success_count} success, {conflict_count} new conflicts, {failure_count} failures"
|
| 1903 |
status = f"{summary} | {page_status}"
|
|
|
|
| 1987 |
batch_approve_conflicts_btn = gr.Button("Approve all conflicts")
|
| 1988 |
batch_reject_conflicts_btn = gr.Button("Reject all conflicts")
|
| 1989 |
|
|
|
|
|
|
|
| 1990 |
audio_player = gr.Audio(label="On-demand audio", type="filepath")
|
| 1991 |
cache_key_state = gr.State(value="")
|
| 1992 |
pending_status_state = gr.State(value="")
|
| 1993 |
conflict_detection_key_state = gr.State(value="")
|
| 1994 |
status = gr.Textbox(label="Status", interactive=False)
|
|
|
|
| 1995 |
|
| 1996 |
# Keyboard shortcuts: 1=positive, 2=negative, 3=uncertain, 4=skip, R=reapply
|
| 1997 |
keyboard_shortcuts_info = gr.HTML(
|
|
|
|
| 2420 |
],
|
| 2421 |
outputs=[status, cache_key_state, audio_player, table, page_state],
|
| 2422 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2423 |
|
| 2424 |
return demo
|
| 2425 |
|
|
|
|
| 2705 |
)
|
| 2706 |
refresh_projects_btn = gr.Button("🔄 Refresh List")
|
| 2707 |
|
| 2708 |
+
gr.Markdown("<div style='height:8px;'></div>")
|
| 2709 |
+
|
| 2710 |
def _render_admin_scope_info(session, selected_admin_project: str):
|
| 2711 |
if session is None:
|
| 2712 |
return ""
|
|
|
|
| 2865 |
outputs=[admin_message, admin_username, admin_project, admin_role],
|
| 2866 |
)
|
| 2867 |
|
| 2868 |
+
gr.Markdown("<div style='height:8px;'></div>")
|
| 2869 |
+
|
| 2870 |
gr.Markdown("#### Delete Project")
|
| 2871 |
with gr.Row():
|
| 2872 |
delete_project_slug = gr.Dropdown(
|
|
|
|
| 2923 |
],
|
| 2924 |
)
|
| 2925 |
|
| 2926 |
+
gr.Markdown("<div style='height:8px;'></div>")
|
| 2927 |
+
|
| 2928 |
gr.Markdown("#### Pending Invites")
|
| 2929 |
with gr.Row():
|
| 2930 |
pending_invites_filter_project = gr.Dropdown(
|
|
|
|
| 3057 |
outputs=[admin_users_controls],
|
| 3058 |
)
|
| 3059 |
|
| 3060 |
+
session_state.change(
|
| 3061 |
+
fn=lambda s: _project_rows() if s is not None else [],
|
| 3062 |
+
inputs=[session_state],
|
| 3063 |
+
outputs=[projects_table],
|
| 3064 |
+
)
|
| 3065 |
+
|
| 3066 |
session_state.change(
|
| 3067 |
fn=lambda s: (
|
| 3068 |
gr.update(choices=_admin_projects_for_session(s), value=None),
|
|
|
|
| 3450 |
gr.Markdown("#### Actions")
|
| 3451 |
validator_name = gr.Textbox(label="Validator", value="validator-demo")
|
| 3452 |
validation_notes = gr.Textbox(label="Notes", placeholder="Optional", lines=4)
|
|
|
|
|
|
|
| 3453 |
keyboard_shortcuts_info = gr.HTML(
|
| 3454 |
value="<div style='font-size:12px;color:#333;padding:8px 10px;background:#f5f5f5;border-radius:6px;margin-bottom:8px;'>"
|
| 3455 |
"<strong>Shortcuts:</strong> ArrowUp=Positive | ArrowDown=Negative | 1=Positive | 2=Negative | 3=Uncertain | 4=Skip"
|
|
|
|
| 3476 |
cache_key_state = gr.State(value="")
|
| 3477 |
pending_status_state = gr.State(value="")
|
| 3478 |
conflict_detection_key_state = gr.State(value="")
|
|
|
|
|
|
|
| 3479 |
def _session_hf_token(session) -> str | None:
|
| 3480 |
if session is None:
|
| 3481 |
return None
|
|
|
|
| 3565 |
|
| 3566 |
def refresh_for_selected_project(project_slug: str):
|
| 3567 |
if not project_slug:
|
| 3568 |
+
return gr.update(choices=[], value=None, interactive=False), [], "", 1, None, None, _spectrogram_title(None, None), _build_validation_summary_cards([]), gr.update(choices=["Noise", "Undetermined"], value=None), []
|
| 3569 |
|
| 3570 |
species_options = _extract_species_options_from_queue(
|
| 3571 |
queue_service=service_ref["queue"],
|
|
|
|
| 4227 |
outputs=[validator_name],
|
| 4228 |
)
|
| 4229 |
|
| 4230 |
+
# ===== TAB 5: Report =====
|
| 4231 |
+
with gr.Tab("📊 Report", id="report_tab"):
|
| 4232 |
+
report_header = gr.Markdown("### Validation Dashboard")
|
| 4233 |
+
report_project_selector = gr.Dropdown(
|
| 4234 |
+
choices=[],
|
| 4235 |
+
value=None,
|
| 4236 |
+
label="Project",
|
| 4237 |
+
interactive=False,
|
| 4238 |
+
)
|
| 4239 |
+
report_kpis = gr.HTML(value="")
|
| 4240 |
+
report_species_table = gr.Dataframe(
|
| 4241 |
+
headers=["species", "total_recordings", "validated", "remaining"],
|
| 4242 |
+
value=[],
|
| 4243 |
+
interactive=False,
|
| 4244 |
+
label="Species Overview",
|
| 4245 |
+
)
|
| 4246 |
+
report_status = gr.Markdown("")
|
| 4247 |
+
|
| 4248 |
+
def _list_project_detections(project_slug: str) -> list[Detection]:
|
| 4249 |
+
if not project_slug:
|
| 4250 |
+
return []
|
| 4251 |
+
page = 1
|
| 4252 |
+
collected: list[Detection] = []
|
| 4253 |
+
while True:
|
| 4254 |
+
page_obj = service_ref["queue"].get_page(
|
| 4255 |
+
project_slug=project_slug,
|
| 4256 |
+
page=page,
|
| 4257 |
+
page_size=500,
|
| 4258 |
+
scientific_name=None,
|
| 4259 |
+
min_confidence=None,
|
| 4260 |
+
max_confidence=None,
|
| 4261 |
+
)
|
| 4262 |
+
collected.extend(page_obj.items)
|
| 4263 |
+
if not page_obj.has_next:
|
| 4264 |
+
break
|
| 4265 |
+
page += 1
|
| 4266 |
+
return collected
|
| 4267 |
+
|
| 4268 |
+
def _render_report_dashboard(project_slug: str):
|
| 4269 |
+
slug = (project_slug or "").strip()
|
| 4270 |
+
if not slug:
|
| 4271 |
+
return "", [], "Select a project to view the dashboard"
|
| 4272 |
+
|
| 4273 |
+
items = _list_project_detections(slug)
|
| 4274 |
+
snapshot = validation_repository.load_current_snapshot(project_slug=slug)
|
| 4275 |
+
total_recordings = len(items)
|
| 4276 |
+
|
| 4277 |
+
species_totals: dict[str, dict[str, int]] = {}
|
| 4278 |
+
validated_recordings = 0
|
| 4279 |
+
|
| 4280 |
+
for item in items:
|
| 4281 |
+
species_name = str(item.scientific_name).strip() or "Unknown species"
|
| 4282 |
+
counters = species_totals.setdefault(species_name, {"total": 0, "validated": 0})
|
| 4283 |
+
counters["total"] += 1
|
| 4284 |
+
|
| 4285 |
+
state = snapshot.get(item.detection_key, {})
|
| 4286 |
+
status_value = str(state.get("status", "pending")).strip().lower()
|
| 4287 |
+
if status_value and status_value != "pending":
|
| 4288 |
+
counters["validated"] += 1
|
| 4289 |
+
validated_recordings += 1
|
| 4290 |
+
|
| 4291 |
+
validated_species = sum(1 for counters in species_totals.values() if counters["validated"] > 0)
|
| 4292 |
+
remaining_recordings = max(0, total_recordings - validated_recordings)
|
| 4293 |
+
|
| 4294 |
+
rows = []
|
| 4295 |
+
for species_name, counters in species_totals.items():
|
| 4296 |
+
remaining = max(0, counters["total"] - counters["validated"])
|
| 4297 |
+
rows.append([species_name, counters["total"], counters["validated"], remaining])
|
| 4298 |
+
rows.sort(key=lambda row: (-int(row[1]), str(row[0]).lower()))
|
| 4299 |
+
|
| 4300 |
+
kpis_html = (
|
| 4301 |
+
"<div style='display:grid;grid-template-columns:repeat(3,minmax(160px,1fr));gap:12px;margin:6px 0 12px 0;'>"
|
| 4302 |
+
f"<div style='padding:10px 14px;border-radius:10px;background:#eef2ff;'><div style='font-size:12px;color:#4f46e5;'>Validated species</div><div style='font-size:24px;font-weight:700;color:#312e81;'>{validated_species}</div></div>"
|
| 4303 |
+
f"<div style='padding:10px 14px;border-radius:10px;background:#fff7ed;'><div style='font-size:12px;color:#c2410c;'>Recordings remaining</div><div style='font-size:24px;font-weight:700;color:#9a3412;'>{remaining_recordings}</div></div>"
|
| 4304 |
+
f"<div style='padding:10px 14px;border-radius:10px;background:#ecfdf3;'><div style='font-size:12px;color:#166534;'>Recordings validated</div><div style='font-size:24px;font-weight:700;color:#14532d;'>{validated_recordings}</div></div>"
|
| 4305 |
+
"</div>"
|
| 4306 |
+
)
|
| 4307 |
+
status_text = (
|
| 4308 |
+
f"Project: **{slug}** | Total recordings: **{total_recordings}** | "
|
| 4309 |
+
f"Validated: **{validated_recordings}** | Remaining: **{remaining_recordings}**"
|
| 4310 |
+
)
|
| 4311 |
+
return kpis_html, rows, status_text
|
| 4312 |
+
|
| 4313 |
+
session_state.change(
|
| 4314 |
+
fn=lambda s: (
|
| 4315 |
+
gr.update(
|
| 4316 |
+
choices=(s.authorized_projects if s is not None else []),
|
| 4317 |
+
value=(s.authorized_projects[0] if (s is not None and s.authorized_projects) else None),
|
| 4318 |
+
interactive=bool(s is not None and s.authorized_projects),
|
| 4319 |
+
),
|
| 4320 |
+
"",
|
| 4321 |
+
[],
|
| 4322 |
+
"Login and choose a project to view metrics" if s is None else "",
|
| 4323 |
+
),
|
| 4324 |
+
inputs=[session_state],
|
| 4325 |
+
outputs=[report_project_selector, report_kpis, report_species_table, report_status],
|
| 4326 |
+
)
|
| 4327 |
+
|
| 4328 |
+
selected_project_state.change(
|
| 4329 |
+
fn=lambda p: gr.update(value=p if p else None),
|
| 4330 |
inputs=[selected_project_state],
|
| 4331 |
+
outputs=[report_project_selector],
|
| 4332 |
+
)
|
| 4333 |
+
|
| 4334 |
+
report_project_selector.change(
|
| 4335 |
+
fn=_render_report_dashboard,
|
| 4336 |
+
inputs=[report_project_selector],
|
| 4337 |
+
outputs=[report_kpis, report_species_table, report_status],
|
| 4338 |
)
|
| 4339 |
|
| 4340 |
return wrapper
|
src/ui/login_page.py
CHANGED
|
@@ -18,30 +18,36 @@ def create_login_page(auth_service: AuthService) -> Tuple[gr.Blocks, gr.Textbox,
|
|
| 18 |
"""
|
| 19 |
|
| 20 |
with gr.Blocks(title="BirdNET-Validator-App - Login") as login_block:
|
| 21 |
-
gr.
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
def perform_login(username: str, hf_token: str) -> Tuple[str, str]:
|
| 47 |
"""Attempt login and return session ID or error message.
|
|
|
|
| 18 |
"""
|
| 19 |
|
| 20 |
with gr.Blocks(title="BirdNET-Validator-App - Login") as login_block:
|
| 21 |
+
with gr.Row():
|
| 22 |
+
with gr.Column(scale=1):
|
| 23 |
+
gr.Markdown("")
|
| 24 |
+
with gr.Column(scale=6):
|
| 25 |
+
gr.Markdown("# BirdNET Validation Platform")
|
| 26 |
+
gr.Markdown("Login to access multi-project validation workflows")
|
| 27 |
+
|
| 28 |
+
username_input = gr.Textbox(
|
| 29 |
+
label="Username",
|
| 30 |
+
placeholder="Enter your username",
|
| 31 |
+
lines=1,
|
| 32 |
+
)
|
| 33 |
+
hf_token_input = gr.Textbox(
|
| 34 |
+
label="Hugging Face Token (recommended)",
|
| 35 |
+
placeholder="hf_xxx...",
|
| 36 |
+
type="password",
|
| 37 |
+
lines=1,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
error_message = gr.Markdown()
|
| 41 |
+
|
| 42 |
+
login_button = gr.Button("Login", variant="primary", scale=1)
|
| 43 |
+
|
| 44 |
+
session_output = gr.Textbox(
|
| 45 |
+
label="Session ID",
|
| 46 |
+
interactive=False,
|
| 47 |
+
visible=False,
|
| 48 |
+
)
|
| 49 |
+
with gr.Column(scale=1):
|
| 50 |
+
gr.Markdown("")
|
| 51 |
|
| 52 |
def perform_login(username: str, hf_token: str) -> Tuple[str, str]:
|
| 53 |
"""Attempt login and return session ID or error message.
|