File size: 1,013 Bytes
1248eba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from __future__ import annotations

import gradio as gr
import gradio.utils


if gradio.utils.get_space() is not None:
    URL, PORT = "https://wauplin-gradio-oauth-test.hf.space", 7860
else:
    URL, PORT = "http://localhost:5173", 5173

TEMPLATE = """
### Name:     {name}
### Username: {preferred_username}
### Profile:  {profile}
### Website:  {website}

![Profile Picture]({picture})

You can manage your connected applications in your [settings](https://huggingface.co/settings/connected-applications).
"""


def show_profile(profile: gr.OAuthProfile) -> str:
    # request.session in case of websockets (see `def get_request_params`)
    # request.request.session in case of direct call
    return TEMPLATE.format(**profile)


with gr.Blocks() as demo:
    with gr.Row():
        gr.LoginButton()
        gr.LogoutButton()

    profile_btn = gr.Button("Show profile")
    output = gr.Markdown()
    profile_btn.click(fn=show_profile, outputs=output)

print(URL)

demo.queue()
demo.launch(server_port=PORT)