Spaces:
Runtime error
Runtime error
File size: 1,006 Bytes
ccec886 43a5d8c afc2013 99e1d75 1248eba 99e1d75 91bbd67 ea0fbdd 43a5d8c 99e1d75 43a5d8c 91bbd67 ea0fbdd 91bbd67 afc2013 ea0fbdd afc2013 99e1d75 f37ec25 43a5d8c 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 28 29 30 31 32 33 |
import gradio as gr
from huggingface_hub import list_models
def hello(profile: gr.OAuthProfile | None) -> str:
if profile is None:
return "I don't know you."
return f"Hello {profile.name}"
def list_private_models(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
if oauth_token is None:
return "Please log in to list private models."
models = [
f"{model.id} ({'private' if model.private else 'public'})"
for model in list_models(author=profile.username, token=oauth_token.token)
]
return "Models:\n\n" + "\n - ".join(models) + "."
with gr.Blocks() as demo:
gr.Markdown(
"# Gradio OAuth Space\n\nThis Space is a demo for the **Sign in with Hugging Face** feature. "
"Duplicate this Space to get started."
)
gr.LoginButton()
m1 = gr.Markdown()
m2 = gr.Markdown()
demo.load(hello, inputs=None, outputs=m1)
demo.load(list_private_models, inputs=None, outputs=m2)
demo.launch()
|