Spaces:
Sleeping
Sleeping
Sync app from GitHub Actions (feature/project-state-security-privacy-review)
Browse files- src/ui/app_factory.py +9 -143
- src/ui/login_page.py +18 -0
- src/ui/theme.py +50 -4
src/ui/app_factory.py
CHANGED
|
@@ -52,7 +52,7 @@ from src.services.hf_project_resource_deletion import HfProjectResourceDeleter,
|
|
| 52 |
from src.services.validation_service import ValidationService
|
| 53 |
from src.services.invite_email_notifier import EmailJSInviteEmailNotifier, InviteEmailNotifier
|
| 54 |
from src.auth.auth_service import AuthService
|
| 55 |
-
from src.ui.login_page import create_login_page
|
| 56 |
from src.ui.admin_panel import AdminPanelManager
|
| 57 |
from src.ui.components import admin_overview_html, compact_metric_grid, coverage_bars_html, inline_hint_html, invite_panel_html, paged_activity_html, project_context_html, section_header_html, selected_segment_html, settings_health_html
|
| 58 |
from src.ui.theme import APP_CSS, app_header_html
|
|
@@ -3940,8 +3940,6 @@ def create_app() -> gr.Blocks:
|
|
| 3940 |
refreshed_session,
|
| 3941 |
)
|
| 3942 |
|
| 3943 |
-
gr.HTML("<div class='bn-spacer'></div>")
|
| 3944 |
-
|
| 3945 |
def _render_admin_scope_info(session, selected_admin_project: str):
|
| 3946 |
if session is None:
|
| 3947 |
return ""
|
|
@@ -4949,7 +4947,14 @@ def create_app() -> gr.Blocks:
|
|
| 4949 |
next_btn = gr.Button("Next")
|
| 4950 |
|
| 4951 |
gr.Markdown("### Filters")
|
| 4952 |
-
min_confidence = gr.Slider(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4953 |
validation_status_filter = gr.Dropdown(
|
| 4954 |
label="Status",
|
| 4955 |
choices=["all", "pending", "positive", "negative", "uncertain", "skip"],
|
|
@@ -6259,143 +6264,4 @@ def create_app() -> gr.Blocks:
|
|
| 6259 |
outputs=[settings_health, settings_status],
|
| 6260 |
)
|
| 6261 |
|
| 6262 |
-
def _hydrate_hf_oauth_session(
|
| 6263 |
-
profile: gr.OAuthProfile | None,
|
| 6264 |
-
oauth_token: gr.OAuthToken | None,
|
| 6265 |
-
):
|
| 6266 |
-
if not _is_running_in_hf_space():
|
| 6267 |
-
return gr.update(), gr.update()
|
| 6268 |
-
if profile is None or oauth_token is None:
|
| 6269 |
-
return None, ""
|
| 6270 |
-
|
| 6271 |
-
session_id, message = perform_oauth_login(auth_service, profile, oauth_token)
|
| 6272 |
-
session = auth_service.get_session(session_id) if session_id else None
|
| 6273 |
-
return session, message
|
| 6274 |
-
|
| 6275 |
-
def _render_admin_section_visibility(session):
|
| 6276 |
-
return (
|
| 6277 |
-
gr.update(visible=bool(session is not None and not runtime_config.hf_admin_storage_mode_enabled)),
|
| 6278 |
-
gr.update(visible=bool(session is not None)),
|
| 6279 |
-
gr.update(visible=bool(session is not None)),
|
| 6280 |
-
gr.update(visible=bool(session is not None)),
|
| 6281 |
-
)
|
| 6282 |
-
|
| 6283 |
-
def _render_admin_project_choices(session):
|
| 6284 |
-
admin_projects = _admin_projects_for_session(session)
|
| 6285 |
-
first_project = admin_projects[0] if admin_projects else None
|
| 6286 |
-
return (
|
| 6287 |
-
gr.update(choices=admin_projects, value=first_project),
|
| 6288 |
-
gr.update(choices=admin_projects, value=first_project),
|
| 6289 |
-
gr.update(choices=admin_projects, value=first_project),
|
| 6290 |
-
gr.update(choices=admin_projects, value=first_project),
|
| 6291 |
-
gr.update(choices=["all", *admin_projects], value="all"),
|
| 6292 |
-
[],
|
| 6293 |
-
)
|
| 6294 |
-
|
| 6295 |
-
def _render_report_login_state(session):
|
| 6296 |
-
return (
|
| 6297 |
-
gr.update(
|
| 6298 |
-
choices=(session.authorized_projects if session is not None else []),
|
| 6299 |
-
value=(session.authorized_projects[0] if (session is not None and session.authorized_projects) else None),
|
| 6300 |
-
interactive=bool(session is not None and session.authorized_projects),
|
| 6301 |
-
),
|
| 6302 |
-
"",
|
| 6303 |
-
coverage_bars_html([]),
|
| 6304 |
-
paged_activity_html("Validator activity", ["Validator", "Validations"], []),
|
| 6305 |
-
paged_activity_html("Recent activity", ["Timestamp", "Validator", "Status", "Detection"], []),
|
| 6306 |
-
1,
|
| 6307 |
-
1,
|
| 6308 |
-
"Login and choose a project." if session is None else "Choose a project to load project metrics.",
|
| 6309 |
-
)
|
| 6310 |
-
|
| 6311 |
-
if _is_running_in_hf_space():
|
| 6312 |
-
oauth_load_event = wrapper.load(
|
| 6313 |
-
fn=_hydrate_hf_oauth_session,
|
| 6314 |
-
inputs=None,
|
| 6315 |
-
outputs=[session_state, error_message],
|
| 6316 |
-
)
|
| 6317 |
-
oauth_load_event.then(
|
| 6318 |
-
fn=create_admin_display,
|
| 6319 |
-
inputs=[session_state],
|
| 6320 |
-
outputs=[admin_info, admin_controls],
|
| 6321 |
-
).then(
|
| 6322 |
-
fn=_render_admin_overview,
|
| 6323 |
-
inputs=[session_state],
|
| 6324 |
-
outputs=[admin_overview],
|
| 6325 |
-
).then(
|
| 6326 |
-
fn=_render_admin_scope_info,
|
| 6327 |
-
inputs=[session_state, admin_project],
|
| 6328 |
-
outputs=[admin_scope_info],
|
| 6329 |
-
).then(
|
| 6330 |
-
fn=_render_admin_section_visibility,
|
| 6331 |
-
inputs=[session_state],
|
| 6332 |
-
outputs=[admin_token_controls, admin_delete_controls, admin_users_controls, admin_pending_controls],
|
| 6333 |
-
).then(
|
| 6334 |
-
fn=lambda session: _project_rows() if session is not None else [],
|
| 6335 |
-
inputs=[session_state],
|
| 6336 |
-
outputs=[projects_table],
|
| 6337 |
-
).then(
|
| 6338 |
-
fn=_render_admin_project_choices,
|
| 6339 |
-
inputs=[session_state],
|
| 6340 |
-
outputs=[
|
| 6341 |
-
admin_project,
|
| 6342 |
-
token_project_select,
|
| 6343 |
-
pending_invite_project,
|
| 6344 |
-
delete_project_slug,
|
| 6345 |
-
pending_invites_filter_project,
|
| 6346 |
-
pending_invites_table,
|
| 6347 |
-
],
|
| 6348 |
-
).then(
|
| 6349 |
-
fn=update_project_selector,
|
| 6350 |
-
inputs=[session_state],
|
| 6351 |
-
outputs=[
|
| 6352 |
-
project_selector,
|
| 6353 |
-
project_overview,
|
| 6354 |
-
project_info_display,
|
| 6355 |
-
project_context_display,
|
| 6356 |
-
selected_project_state,
|
| 6357 |
-
selected_dataset_repo_state,
|
| 6358 |
-
],
|
| 6359 |
-
).then(
|
| 6360 |
-
fn=_build_invites_ui,
|
| 6361 |
-
inputs=[session_state],
|
| 6362 |
-
outputs=[invitations_info, invitations_overview, invite_selector, invite_controls],
|
| 6363 |
-
).then(
|
| 6364 |
-
fn=lambda session: gr.update(value=(session.username if session is not None else "")),
|
| 6365 |
-
inputs=[session_state],
|
| 6366 |
-
outputs=[validator_name],
|
| 6367 |
-
).then(
|
| 6368 |
-
fn=lambda repo_id: gr.update(value=repo_id),
|
| 6369 |
-
inputs=[selected_dataset_repo_state],
|
| 6370 |
-
outputs=[dataset_repo],
|
| 6371 |
-
).then(
|
| 6372 |
-
fn=refresh_for_selected_project,
|
| 6373 |
-
inputs=[selected_project_state, session_state],
|
| 6374 |
-
outputs=[
|
| 6375 |
-
species_filter,
|
| 6376 |
-
table,
|
| 6377 |
-
status,
|
| 6378 |
-
page_state,
|
| 6379 |
-
audio_player,
|
| 6380 |
-
spectrogram_image,
|
| 6381 |
-
spectrogram_title,
|
| 6382 |
-
validation_summary_cards,
|
| 6383 |
-
corrected_species_input,
|
| 6384 |
-
project_species_state,
|
| 6385 |
-
],
|
| 6386 |
-
).then(
|
| 6387 |
-
fn=_render_report_login_state,
|
| 6388 |
-
inputs=[session_state],
|
| 6389 |
-
outputs=[
|
| 6390 |
-
report_project_selector,
|
| 6391 |
-
report_kpis,
|
| 6392 |
-
report_coverage_bars,
|
| 6393 |
-
report_validator_table,
|
| 6394 |
-
report_recent_table,
|
| 6395 |
-
report_validator_page,
|
| 6396 |
-
report_recent_page,
|
| 6397 |
-
report_status,
|
| 6398 |
-
],
|
| 6399 |
-
)
|
| 6400 |
-
|
| 6401 |
return wrapper
|
|
|
|
| 52 |
from src.services.validation_service import ValidationService
|
| 53 |
from src.services.invite_email_notifier import EmailJSInviteEmailNotifier, InviteEmailNotifier
|
| 54 |
from src.auth.auth_service import AuthService
|
| 55 |
+
from src.ui.login_page import create_login_page
|
| 56 |
from src.ui.admin_panel import AdminPanelManager
|
| 57 |
from src.ui.components import admin_overview_html, compact_metric_grid, coverage_bars_html, inline_hint_html, invite_panel_html, paged_activity_html, project_context_html, section_header_html, selected_segment_html, settings_health_html
|
| 58 |
from src.ui.theme import APP_CSS, app_header_html
|
|
|
|
| 3940 |
refreshed_session,
|
| 3941 |
)
|
| 3942 |
|
|
|
|
|
|
|
| 3943 |
def _render_admin_scope_info(session, selected_admin_project: str):
|
| 3944 |
if session is None:
|
| 3945 |
return ""
|
|
|
|
| 4947 |
next_btn = gr.Button("Next")
|
| 4948 |
|
| 4949 |
gr.Markdown("### Filters")
|
| 4950 |
+
min_confidence = gr.Slider(
|
| 4951 |
+
label="Minimum confidence",
|
| 4952 |
+
minimum=0.0,
|
| 4953 |
+
maximum=1.0,
|
| 4954 |
+
step=0.01,
|
| 4955 |
+
value=0.0,
|
| 4956 |
+
elem_classes=["bn-clean-slider"],
|
| 4957 |
+
)
|
| 4958 |
validation_status_filter = gr.Dropdown(
|
| 4959 |
label="Status",
|
| 4960 |
choices=["all", "pending", "positive", "negative", "uncertain", "skip"],
|
|
|
|
| 6264 |
outputs=[settings_health, settings_status],
|
| 6265 |
)
|
| 6266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6267 |
return wrapper
|
src/ui/login_page.py
CHANGED
|
@@ -99,6 +99,7 @@ def create_login_page(
|
|
| 99 |
visible=False,
|
| 100 |
)
|
| 101 |
|
|
|
|
| 102 |
username_input = None
|
| 103 |
login_button = None
|
| 104 |
if enable_oauth_login:
|
|
@@ -115,6 +116,11 @@ def create_login_page(
|
|
| 115 |
icon=None,
|
| 116 |
elem_classes=["bn-oauth-login-button"],
|
| 117 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
elif allow_username_login:
|
| 119 |
gr.Markdown("Local development login")
|
| 120 |
username_input = gr.Textbox(
|
|
@@ -127,6 +133,18 @@ def create_login_page(
|
|
| 127 |
with gr.Column(scale=1):
|
| 128 |
gr.Markdown("")
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
if login_button is not None and username_input is not None:
|
| 131 |
login_button.click(
|
| 132 |
fn=lambda username: perform_login(
|
|
|
|
| 99 |
visible=False,
|
| 100 |
)
|
| 101 |
|
| 102 |
+
oauth_enter_button = None
|
| 103 |
username_input = None
|
| 104 |
login_button = None
|
| 105 |
if enable_oauth_login:
|
|
|
|
| 116 |
icon=None,
|
| 117 |
elem_classes=["bn-oauth-login-button"],
|
| 118 |
)
|
| 119 |
+
oauth_enter_button = gr.Button(
|
| 120 |
+
"Enter workspace",
|
| 121 |
+
variant="primary",
|
| 122 |
+
elem_classes=["bn-login-workspace-button"],
|
| 123 |
+
)
|
| 124 |
elif allow_username_login:
|
| 125 |
gr.Markdown("Local development login")
|
| 126 |
username_input = gr.Textbox(
|
|
|
|
| 133 |
with gr.Column(scale=1):
|
| 134 |
gr.Markdown("")
|
| 135 |
|
| 136 |
+
def handle_oauth_login(
|
| 137 |
+
profile: gr.OAuthProfile | None,
|
| 138 |
+
oauth_token: gr.OAuthToken | None,
|
| 139 |
+
) -> Tuple[str, str]:
|
| 140 |
+
return perform_oauth_login(auth_service, profile, oauth_token)
|
| 141 |
+
|
| 142 |
+
if oauth_enter_button is not None:
|
| 143 |
+
oauth_enter_button.click(
|
| 144 |
+
fn=handle_oauth_login,
|
| 145 |
+
inputs=None,
|
| 146 |
+
outputs=[session_output, error_message],
|
| 147 |
+
)
|
| 148 |
if login_button is not None and username_input is not None:
|
| 149 |
login_button.click(
|
| 150 |
fn=lambda username: perform_login(
|
src/ui/theme.py
CHANGED
|
@@ -159,6 +159,22 @@ button.bn-oauth-login-button * {
|
|
| 159 |
white-space: nowrap !important;
|
| 160 |
}
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
.bn-panel {
|
| 163 |
background: var(--bn-panel);
|
| 164 |
border: 1px solid var(--bn-border);
|
|
@@ -316,6 +332,19 @@ button.bn-oauth-login-button * {
|
|
| 316 |
gap: 8px !important;
|
| 317 |
}
|
| 318 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
.bn-danger-zone {
|
| 320 |
border-color: #f3b6b2 !important;
|
| 321 |
background: #fffafa !important;
|
|
@@ -532,15 +561,18 @@ button.bn-oauth-login-button * {
|
|
| 532 |
|
| 533 |
.bn-activity-table-wrap {
|
| 534 |
margin-top: 10px;
|
| 535 |
-
overflow
|
| 536 |
border: 1px solid var(--bn-border);
|
| 537 |
border-radius: 8px;
|
|
|
|
| 538 |
}
|
| 539 |
|
| 540 |
.bn-activity-table {
|
| 541 |
width: 100%;
|
| 542 |
min-width: 520px;
|
| 543 |
-
border-collapse:
|
|
|
|
|
|
|
| 544 |
background: #ffffff;
|
| 545 |
color: var(--bn-text);
|
| 546 |
font-size: 13px;
|
|
@@ -549,7 +581,8 @@ button.bn-oauth-login-button * {
|
|
| 549 |
.bn-activity-table th,
|
| 550 |
.bn-activity-table td {
|
| 551 |
padding: 9px 11px;
|
| 552 |
-
border
|
|
|
|
| 553 |
text-align: left;
|
| 554 |
vertical-align: top;
|
| 555 |
}
|
|
@@ -560,8 +593,21 @@ button.bn-oauth-login-button * {
|
|
| 560 |
font-weight: 750;
|
| 561 |
}
|
| 562 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 563 |
.bn-activity-table tbody tr:last-child td {
|
| 564 |
-
border-bottom: 0;
|
| 565 |
}
|
| 566 |
|
| 567 |
.bn-activity-empty {
|
|
|
|
| 159 |
white-space: nowrap !important;
|
| 160 |
}
|
| 161 |
|
| 162 |
+
.bn-login-workspace-button button,
|
| 163 |
+
button.bn-login-workspace-button {
|
| 164 |
+
min-height: 48px !important;
|
| 165 |
+
border: 1px solid #93c5fd !important;
|
| 166 |
+
border-radius: 8px !important;
|
| 167 |
+
background: #dbeafe !important;
|
| 168 |
+
color: #075985 !important;
|
| 169 |
+
font-weight: 780 !important;
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
.bn-login-workspace-button button:hover,
|
| 173 |
+
button.bn-login-workspace-button:hover {
|
| 174 |
+
border-color: #60a5fa !important;
|
| 175 |
+
background: #bfdbfe !important;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
.bn-panel {
|
| 179 |
background: var(--bn-panel);
|
| 180 |
border: 1px solid var(--bn-border);
|
|
|
|
| 332 |
gap: 8px !important;
|
| 333 |
}
|
| 334 |
|
| 335 |
+
.bn-clean-slider,
|
| 336 |
+
.bn-clean-slider .block,
|
| 337 |
+
.bn-clean-slider .form,
|
| 338 |
+
.bn-clean-slider .styler,
|
| 339 |
+
.bn-clean-slider > div {
|
| 340 |
+
background: transparent !important;
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
.bn-clean-slider input,
|
| 344 |
+
.bn-clean-slider [data-testid="number-input"] {
|
| 345 |
+
background: #ffffff !important;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
.bn-danger-zone {
|
| 349 |
border-color: #f3b6b2 !important;
|
| 350 |
background: #fffafa !important;
|
|
|
|
| 561 |
|
| 562 |
.bn-activity-table-wrap {
|
| 563 |
margin-top: 10px;
|
| 564 |
+
overflow: hidden;
|
| 565 |
border: 1px solid var(--bn-border);
|
| 566 |
border-radius: 8px;
|
| 567 |
+
background: #ffffff;
|
| 568 |
}
|
| 569 |
|
| 570 |
.bn-activity-table {
|
| 571 |
width: 100%;
|
| 572 |
min-width: 520px;
|
| 573 |
+
border-collapse: separate;
|
| 574 |
+
border-spacing: 0;
|
| 575 |
+
border: 0 !important;
|
| 576 |
background: #ffffff;
|
| 577 |
color: var(--bn-text);
|
| 578 |
font-size: 13px;
|
|
|
|
| 581 |
.bn-activity-table th,
|
| 582 |
.bn-activity-table td {
|
| 583 |
padding: 9px 11px;
|
| 584 |
+
border: 0 !important;
|
| 585 |
+
border-bottom: 1px solid var(--bn-border) !important;
|
| 586 |
text-align: left;
|
| 587 |
vertical-align: top;
|
| 588 |
}
|
|
|
|
| 593 |
font-weight: 750;
|
| 594 |
}
|
| 595 |
|
| 596 |
+
.bn-activity-table th + th,
|
| 597 |
+
.bn-activity-table td + td {
|
| 598 |
+
border-left: 1px solid var(--bn-border) !important;
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
.bn-activity-table thead th:first-child {
|
| 602 |
+
border-top-left-radius: 8px;
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
.bn-activity-table thead th:last-child {
|
| 606 |
+
border-top-right-radius: 8px;
|
| 607 |
+
}
|
| 608 |
+
|
| 609 |
.bn-activity-table tbody tr:last-child td {
|
| 610 |
+
border-bottom: 0 !important;
|
| 611 |
}
|
| 612 |
|
| 613 |
.bn-activity-empty {
|