PerryCheng614 commited on
Commit
793fd68
1 Parent(s): 519b002

Upload 2 files

Browse files
Files changed (2) hide show
  1. login.py +23 -0
  2. requirements.txt +1 -0
login.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import whoami
3
+
4
+ def hello(profile: gr.OAuthProfile | None) -> str:
5
+ if profile is None:
6
+ return "I don't know you."
7
+ print(profile)
8
+ return f"Hello {profile.name}"
9
+
10
+ def list_organizations(oauth_token: gr.OAuthToken | None) -> str:
11
+ if oauth_token is None:
12
+ return "Please log in to list organizations."
13
+ org_names = [org["name"] for org in whoami(oauth_token.token)["orgs"]]
14
+ return f"You belong to {', '.join(org_names)}."
15
+
16
+ with gr.Blocks() as demo:
17
+ gr.LoginButton()
18
+ m1 = gr.Markdown()
19
+ m2 = gr.Markdown()
20
+ demo.load(hello, inputs=None, outputs=m1)
21
+ demo.load(list_organizations, inputs=None, outputs=m2)
22
+
23
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio[oauth]