File size: 2,181 Bytes
9a319ed
 
 
 
 
184d88a
 
 
 
 
 
 
 
 
 
 
 
9a319ed
 
09ff7cc
20bc492
 
09ff7cc
 
184d88a
9a319ed
 
184d88a
 
 
 
 
 
 
 
9a319ed
184d88a
5358eca
9a319ed
184d88a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9a319ed
184d88a
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
import gradio as gr

from huggingface_hub import list_models



def hello(profile: gr.OAuthProfile | None) -> str:
    # ^ expect a gr.OAuthProfile object as input to get the user's profile
    # if the user is not logged in, profile will be None
    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:
    # ^ expect a gr.OAuthToken object as input to get the user's token
    # if the user is not logged in, oauth_token will be None
    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 "You r in........." #"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."
        "\n\nFor more details, check out:"
        "\n- https://www.gradio.app/guides/sharing-your-app#o-auth-login-via-hugging-face"
        "\n- https://huggingface.co/docs/hub/spaces-oauth"
    )
    gr.LoginButton()
    # ^ add a login button to the Space
    gr.LogoutButton()
    m1 = gr.Markdown()
    m2 = gr.Markdown()
    demo.load(hello, inputs=None, outputs=m1)
    demo.load(list_private_models, inputs=None, outputs=m2)

demo.launch()

#def list_private_models(oauth_profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
#    if oauth_token is None:
#        return "Please log in to list private models."
#    # List models from author using token
#    models = list_models(author=oauth_profile.username, token=oauth_token.token)
#    # Return list of private models
#    return f"Private models: {', '.join(model.id for model in models if model.private)}"

#with gr.Blocks() as demo:
#    gr.LoginButton()
#    gr.LogoutButton()
#    m1 = gr.Markdown()
#    demo.load(list_private_models, inputs=None, outputs=m1)

#demo.launch()