gradio-oauth / app.py
Wauplin's picture
Wauplin HF Staff
push refactored app
4de0319
raw
history blame
1.31 kB
import gradio as gr
from auth import attach_oauth
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(request: gr.Request) -> str:
if "user" not in request.request.session:
return "Please login first"
return TEMPLATE.format(**request.request.session["user"])
with gr.Blocks() as demo:
# Taken from https://cmgdo.com/external-link-in-gradio-button/
login_button = gr.Button("Login")
login_button.click(
None, None, None, _js="function() {location.replace('https://wauplin-gradio-oauth-test.hf.space/login/huggingface');}"
)
# Taken from https://cmgdo.com/external-link-in-gradio-button/
logout_button = gr.Button("Logout", variant="secondary")
logout_button.click(None, None, None, _js="function() {location.replace('https://wauplin-gradio-oauth-test.hf.space/logout');}")
profile_btn = gr.Button("Show profile")
output = gr.Markdown()
profile_btn.click(fn=show_profile, outputs=output)
demo.launch(prevent_thread_lock=True, server_port=5173)
attach_oauth(demo.server_app)
demo.block_thread()