Spaces:
Sleeping
Sleeping
Nikolay Banar
commited on
Commit
•
5692a3b
1
Parent(s):
452c918
update app
Browse files
app.py
CHANGED
@@ -1,7 +1,25 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import whoami
|
3 |
+
def hello(profile: gr.OAuthProfile | None) -> str:
|
4 |
+
if profile is None:
|
5 |
+
return "I don't know you."
|
6 |
+
return f"Hello {profile.name}"
|
7 |
|
8 |
+
def list_organizations(oauth_token: gr.OAuthToken | None) -> str:
|
9 |
+
if oauth_token is None:
|
10 |
+
return "Please log in to list organizations."
|
11 |
+
org_names = [org["name"] for org in whoami(token=oauth_token.token)["orgs"]]
|
12 |
+
return f"You belong to {', '.join(org_names)}."
|
13 |
|
14 |
+
with gr.Blocks() as demo:
|
15 |
+
gr.Markdown(
|
16 |
+
"# Gradio OAuth Space\n\nThis Space is a demo for the new **Sign in with Hugging Face** feature."
|
17 |
+
)
|
18 |
+
gr.LoginButton()
|
19 |
+
gr.LogoutButton()
|
20 |
+
m1 = gr.Markdown()
|
21 |
+
m2 = gr.Markdown()
|
22 |
+
demo.load(hello, inputs=None, outputs=m1)
|
23 |
+
demo.load(list_organizations, inputs=None, outputs=m2)
|
24 |
+
|
25 |
+
demo.launch()
|