jrrribeiro commited on
Commit
ddb2084
·
verified ·
1 Parent(s): 2a425c9

Sync app from GitHub Actions (feature/project-state-security-privacy-review)

Browse files
Files changed (3) hide show
  1. src/ui/app_factory.py +140 -1
  2. src/ui/login_page.py +4 -16
  3. src/ui/theme.py +29 -0
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
@@ -6259,4 +6259,143 @@ def create_app() -> gr.Blocks:
6259
  outputs=[settings_health, settings_status],
6260
  )
6261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6262
  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, perform_oauth_login
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
 
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
src/ui/login_page.py CHANGED
@@ -99,7 +99,6 @@ def create_login_page(
99
  visible=False,
100
  )
101
 
102
- oauth_continue_button = None
103
  username_input = None
104
  login_button = None
105
  if enable_oauth_login:
@@ -110,10 +109,11 @@ def create_login_page(
110
  else "Secure login with your Hugging Face account to access your validation workspace."
111
  )
112
  )
113
- oauth_continue_button = gr.LoginButton(
114
  "Sign in with Hugging Face",
115
- logout_value="Signed in as {}",
116
- variant="primary",
 
117
  )
118
  elif allow_username_login:
119
  gr.Markdown("Local development login")
@@ -127,18 +127,6 @@ def create_login_page(
127
  with gr.Column(scale=1):
128
  gr.Markdown("")
129
 
130
- def handle_oauth_login(
131
- profile: gr.OAuthProfile | None,
132
- oauth_token: gr.OAuthToken | None,
133
- ) -> Tuple[str, str]:
134
- return perform_oauth_login(auth_service, profile, oauth_token)
135
-
136
- if oauth_continue_button is not None:
137
- oauth_continue_button.click(
138
- fn=handle_oauth_login,
139
- inputs=None,
140
- outputs=[session_output, error_message],
141
- )
142
  if login_button is not None and username_input is not None:
143
  login_button.click(
144
  fn=lambda username: perform_login(
 
99
  visible=False,
100
  )
101
 
 
102
  username_input = None
103
  login_button = None
104
  if enable_oauth_login:
 
109
  else "Secure login with your Hugging Face account to access your validation workspace."
110
  )
111
  )
112
+ gr.LoginButton(
113
  "Sign in with Hugging Face",
114
+ logout_value="Sign out ({})",
115
+ icon=None,
116
+ elem_classes=["bn-oauth-login-button"],
117
  )
118
  elif allow_username_login:
119
  gr.Markdown("Local development login")
 
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(
src/ui/theme.py CHANGED
@@ -130,6 +130,35 @@ main.app,
130
  font-weight: 650 !important;
131
  }
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  .bn-panel {
134
  background: var(--bn-panel);
135
  border: 1px solid var(--bn-border);
 
130
  font-weight: 650 !important;
131
  }
132
 
133
+ .bn-oauth-login-button button,
134
+ button.bn-oauth-login-button {
135
+ min-height: 48px !important;
136
+ border: 1px solid #f97316 !important;
137
+ border-radius: 8px !important;
138
+ background: #f97316 !important;
139
+ color: #ffffff !important;
140
+ font-weight: 780 !important;
141
+ display: flex !important;
142
+ align-items: center !important;
143
+ justify-content: center !important;
144
+ gap: 8px !important;
145
+ white-space: nowrap !important;
146
+ overflow: hidden !important;
147
+ text-overflow: ellipsis !important;
148
+ }
149
+
150
+ .bn-oauth-login-button button:hover,
151
+ button.bn-oauth-login-button:hover {
152
+ border-color: #ea580c !important;
153
+ background: #ea580c !important;
154
+ color: #ffffff !important;
155
+ }
156
+
157
+ .bn-oauth-login-button button *,
158
+ 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);