Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure LoginButton value text is displayed #6808

Merged
merged 8 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading