diff --git a/.changeset/seven-donkeys-itch.md b/.changeset/seven-donkeys-itch.md new file mode 100644 index 000000000000..4b6cfddb1723 --- /dev/null +++ b/.changeset/seven-donkeys-itch.md @@ -0,0 +1,5 @@ +--- +"gradio": patch +--- + +fix:Ensure LoginButton `value` text is displayed diff --git a/gradio/components/login_button.py b/gradio/components/login_button.py index 4ba01777ea3d..e976eee8307b 100644 --- a/gradio/components/login_button.py +++ b/gradio/components/login_button.py @@ -24,6 +24,7 @@ class LoginButton(Button): def __init__( self, value: str = "Sign in with Hugging Face", + signed_in_value: str = "Signed in as {}", *, every: float | None = None, variant: Literal["primary", "secondary", "stop"] = "secondary", @@ -39,6 +40,13 @@ def __init__( scale: int | None = 0, min_width: int | None = None, ): + """ + Parameters: + signed_in_value: The text to display when the user is signed in. The string should contain a placeholder for the username, e.g. "Signed in as {}". + """ + if signed_in_value is None: + signed_in_value = "Signed in as {}" + self.signed_in_value = signed_in_value super().__init__( value, every=every, @@ -75,10 +83,11 @@ def _check_login_status(self, request: Request) -> LoginButton: request.request, "session", None ) if session is None or "oauth_info" not in session: - return LoginButton("Sign in with Hugging Face", interactive=True) + return LoginButton(value=self.value, interactive=True) else: username = session["oauth_info"]["userinfo"]["preferred_username"] - return LoginButton(f"Signed in as {username}", interactive=False) + signed_in_text = self.signed_in_value.format(username) + return LoginButton(signed_in_text, interactive=False) # JS code to redirects to /login/huggingface if user is not logged in.