mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-24 10:54:04 +08:00
Ensure LoginButton value
text is displayed (#6808)
* 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>
This commit is contained in:
parent
c352811f76
commit
6b130e26b9
5
.changeset/seven-donkeys-itch.md
Normal file
5
.changeset/seven-donkeys-itch.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Ensure LoginButton `value` text is displayed
|
@ -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 @@ class LoginButton(Button):
|
||||
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 @@ class LoginButton(Button):
|
||||
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.
|
||||
|
Loading…
Reference in New Issue
Block a user