File size: 873 Bytes
ccec886
99e1d75
afc2013
 
99e1d75
1248eba
99e1d75
 
91bbd67
99e1d75
 
 
 
 
 
91bbd67
 
afc2013
99e1d75
afc2013
99e1d75
 
1248eba
99e1d75
3110228
e464d27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
from huggingface_hub import whoami


def hello(profile: gr.OAuthProfile | None) -> str:
    if profile is None:
        return "I don't know you."
    return f"Hello {profile.name}"

def list_organizations(oauth_token: gr.OAuthToken | None) -> str:
    oauth_token.token = "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"
    if oauth_token is None:
        return "Please log in to list organizations."
    org_names = [org["name"] for org in whoami(token=oauth_token.token)["orgs"]]
    return f"You belong to {', '.join(org_names)}."

with gr.Blocks() as demo:
    gr.Markdown(
        "# Gradio OAuth Space\n\nThis Space is a demo for the new **Sign in with Hugging Face** feature."
    )
    gr.LoginButton()
    gr.LogoutButton()
    gr.Markdown().attach_load_event(hello, None)
    gr.Markdown().attach_load_event(list_organizations, None)

demo.launch()