Spaces:
Sleeping
Sleeping
Sync app from GitHub Actions (feature/project-state-security-privacy-review)
Browse files- src/ui/app_factory.py +13 -1
- src/ui/login_page.py +13 -7
src/ui/app_factory.py
CHANGED
|
@@ -3437,7 +3437,7 @@ def create_app() -> gr.Blocks:
|
|
| 3437 |
),
|
| 3438 |
)
|
| 3439 |
)
|
| 3440 |
-
session_output, error_message = create_login_page(
|
| 3441 |
auth_service,
|
| 3442 |
allow_username_login=allow_username_login,
|
| 3443 |
enable_oauth_login=_is_running_in_hf_space(),
|
|
@@ -3463,6 +3463,18 @@ def create_app() -> gr.Blocks:
|
|
| 3463 |
outputs=[session_state],
|
| 3464 |
)
|
| 3465 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3466 |
def hydrate_oauth_session_after_click(
|
| 3467 |
login_intent: str,
|
| 3468 |
profile: gr.OAuthProfile | None,
|
|
|
|
| 3437 |
),
|
| 3438 |
)
|
| 3439 |
)
|
| 3440 |
+
session_output, error_message, oauth_login_button = create_login_page(
|
| 3441 |
auth_service,
|
| 3442 |
allow_username_login=allow_username_login,
|
| 3443 |
enable_oauth_login=_is_running_in_hf_space(),
|
|
|
|
| 3463 |
outputs=[session_state],
|
| 3464 |
)
|
| 3465 |
|
| 3466 |
+
def render_oauth_button_label(session):
|
| 3467 |
+
if session is None:
|
| 3468 |
+
return gr.update(value="Sign in with Hugging Face")
|
| 3469 |
+
return gr.update(value="Sign out")
|
| 3470 |
+
|
| 3471 |
+
if oauth_login_button is not None and _is_running_in_hf_space():
|
| 3472 |
+
session_state.change(
|
| 3473 |
+
fn=render_oauth_button_label,
|
| 3474 |
+
inputs=[session_state],
|
| 3475 |
+
outputs=[oauth_login_button],
|
| 3476 |
+
)
|
| 3477 |
+
|
| 3478 |
def hydrate_oauth_session_after_click(
|
| 3479 |
login_intent: str,
|
| 3480 |
profile: gr.OAuthProfile | None,
|
src/ui/login_page.py
CHANGED
|
@@ -78,14 +78,14 @@ def create_login_page(
|
|
| 78 |
enable_oauth_login: bool = False,
|
| 79 |
auth_mode_label: str = "",
|
| 80 |
admin_storage_mode: bool = False,
|
| 81 |
-
) -> Tuple[gr.Textbox, gr.Markdown]:
|
| 82 |
"""Create an OAuth production login with an optional local username fallback.
|
| 83 |
|
| 84 |
Args:
|
| 85 |
auth_service: AuthService instance for login validation
|
| 86 |
|
| 87 |
Returns:
|
| 88 |
-
Tuple of (session_output, error_message)
|
| 89 |
"""
|
| 90 |
with gr.Row():
|
| 91 |
with gr.Column(scale=1):
|
|
@@ -132,15 +132,21 @@ def create_login_page(
|
|
| 132 |
|
| 133 |
if enable_oauth_login and login_button is not None:
|
| 134 |
login_button.click(
|
| 135 |
-
fn=lambda: None,
|
| 136 |
-
inputs=
|
| 137 |
outputs=None,
|
| 138 |
js="""
|
| 139 |
-
() => {
|
|
|
|
| 140 |
sessionStorage.setItem("birdnet_hf_login_intent", "1");
|
| 141 |
window.parent?.postMessage({ type: "SET_SCROLLING", enabled: true }, "*");
|
| 142 |
setTimeout(() => {
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
}, 100);
|
| 145 |
return [];
|
| 146 |
}
|
|
@@ -157,4 +163,4 @@ def create_login_page(
|
|
| 157 |
outputs=[session_output, error_message],
|
| 158 |
)
|
| 159 |
|
| 160 |
-
return session_output, error_message
|
|
|
|
| 78 |
enable_oauth_login: bool = False,
|
| 79 |
auth_mode_label: str = "",
|
| 80 |
admin_storage_mode: bool = False,
|
| 81 |
+
) -> Tuple[gr.Textbox, gr.Markdown, gr.Button | None]:
|
| 82 |
"""Create an OAuth production login with an optional local username fallback.
|
| 83 |
|
| 84 |
Args:
|
| 85 |
auth_service: AuthService instance for login validation
|
| 86 |
|
| 87 |
Returns:
|
| 88 |
+
Tuple of (session_output, error_message, login_button)
|
| 89 |
"""
|
| 90 |
with gr.Row():
|
| 91 |
with gr.Column(scale=1):
|
|
|
|
| 132 |
|
| 133 |
if enable_oauth_login and login_button is not None:
|
| 134 |
login_button.click(
|
| 135 |
+
fn=lambda _button_value: None,
|
| 136 |
+
inputs=[login_button],
|
| 137 |
outputs=None,
|
| 138 |
js="""
|
| 139 |
+
(buttonValue) => {
|
| 140 |
+
const label = String(buttonValue || "").toLowerCase();
|
| 141 |
sessionStorage.setItem("birdnet_hf_login_intent", "1");
|
| 142 |
window.parent?.postMessage({ type: "SET_SCROLLING", enabled: true }, "*");
|
| 143 |
setTimeout(() => {
|
| 144 |
+
if (label.includes("sign out")) {
|
| 145 |
+
sessionStorage.removeItem("birdnet_hf_login_intent");
|
| 146 |
+
window.location.assign("/logout" + window.location.search);
|
| 147 |
+
} else {
|
| 148 |
+
window.location.assign("/login/huggingface" + window.location.search);
|
| 149 |
+
}
|
| 150 |
}, 100);
|
| 151 |
return [];
|
| 152 |
}
|
|
|
|
| 163 |
outputs=[session_output, error_message],
|
| 164 |
)
|
| 165 |
|
| 166 |
+
return session_output, error_message, login_button
|