Spaces:
Sleeping
Sleeping
Nikolay Banar
commited on
Commit
•
23d6cab
1
Parent(s):
5692a3b
update app
Browse files
app.py
CHANGED
@@ -5,6 +5,15 @@ def hello(profile: gr.OAuthProfile | None) -> str:
|
|
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."
|
@@ -15,11 +24,24 @@ 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.
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
demo.launch()
|
|
|
5 |
return "I don't know you."
|
6 |
return f"Hello {profile.name}"
|
7 |
|
8 |
+
def is_user_in_organization(oauth_token: gr.OAuthToken | None, required_org: str) -> bool:
|
9 |
+
if oauth_token is None:
|
10 |
+
return False
|
11 |
+
|
12 |
+
user_info = whoami(token=oauth_token.token)
|
13 |
+
user_orgs = [org["name"] for org in user_info["orgs"]]
|
14 |
+
|
15 |
+
return required_org in user_orgs
|
16 |
+
|
17 |
def list_organizations(oauth_token: gr.OAuthToken | None) -> str:
|
18 |
if oauth_token is None:
|
19 |
return "Please log in to list organizations."
|
|
|
24 |
gr.Markdown(
|
25 |
"# Gradio OAuth Space\n\nThis Space is a demo for the new **Sign in with Hugging Face** feature."
|
26 |
)
|
27 |
+
with gr.Row():
|
28 |
+
gr.LoginButton()
|
29 |
+
gr.LogoutButton()
|
30 |
+
|
31 |
+
with gr.Row():
|
32 |
+
m1 = gr.Markdown()
|
33 |
+
m2 = gr.Markdown()
|
34 |
+
|
35 |
+
required_org = "YourOrganizationName"
|
36 |
+
|
37 |
+
def update_interface(profile: gr.OAuthProfile | None):
|
38 |
+
if profile and is_user_in_organization(profile.token, required_org):
|
39 |
+
m1.update(f"Hello {profile.name}, welcome to the app.")
|
40 |
+
# Load other components or functions relevant to authenticated users
|
41 |
+
else:
|
42 |
+
m1.update("Access denied. You do not belong to the required organization.")
|
43 |
+
|
44 |
+
|
45 |
+
demo.load(update_interface, inputs=None, outputs=None)
|
46 |
|
47 |
demo.launch()
|