File size: 1,772 Bytes
40e000b 2b4b309 6fc91c7 2b4b309 75f9ac3 2b4b309 6fc91c7 c0c68e7 6fc91c7 40e000b 75f9ac3 40e000b |
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
from typing import Union
import gradio as gr
from gradio.oauth import (
OAUTH_CLIENT_ID,
OAUTH_CLIENT_SECRET,
OAUTH_SCOPES,
OPENID_PROVIDER_URL,
get_space,
)
from huggingface_hub import whoami
if (
all(
[
OAUTH_CLIENT_ID,
OAUTH_CLIENT_SECRET,
OAUTH_SCOPES,
OPENID_PROVIDER_URL,
]
)
or get_space() is None
):
from gradio.oauth import OAuthToken
else:
OAuthToken = str
def get_login_button():
if (
all(
[
OAUTH_CLIENT_ID,
OAUTH_CLIENT_SECRET,
OAUTH_SCOPES,
OPENID_PROVIDER_URL,
]
)
or get_space() is None
):
return gr.LoginButton(
value="Sign in with Hugging Face to generate a full dataset and push it to the Hub!",
size="lg",
)
def get_duplicate_button():
if get_space() is not None:
return gr.DuplicateButton(size="lg")
def list_orgs(token: OAuthToken = None):
if token is not None:
data = whoami(token)
organisations = [
entry["entity"]["name"]
for entry in data["auth"]["accessToken"]["fineGrained"]["scoped"]
if "repo.write" in entry["permissions"]
]
organisations.append(data["name"])
return list(set(organisations))
else:
return []
def get_org_dropdown(token: OAuthToken = None):
orgs = list_orgs(token)
return gr.Dropdown(
label="Organization", choices=orgs, value=orgs[0] if orgs else None
)
def swap_visibilty(profile: Union[gr.OAuthProfile, None]):
if profile is None:
return gr.Column(visible=False)
else:
return gr.Column(visible=True)
|