Skip to content

Commit

Permalink
Ensure LoginButton value text is displayed (#6808)
Browse files Browse the repository at this point in the history
* fix LoginButton value

* add changeset

* formatting

* add `signed_in_value` parameter

* tweak

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
  • Loading branch information
3 people committed Dec 15, 2023
1 parent c352811 commit 6b130e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-donkeys-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Ensure LoginButton `value` text is displayed
13 changes: 11 additions & 2 deletions gradio/components/login_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6b130e2

Please sign in to comment.