Claude commited on
Commit
024fac6
·
unverified ·
1 Parent(s): 06a852b

feat: Add HuggingFace OAuth login

Browse files
Files changed (4) hide show
  1. README.md +2 -0
  2. app.py +27 -6
  3. pyproject.toml +1 -0
  4. uv.lock +5 -1
README.md CHANGED
@@ -8,6 +8,8 @@ sdk_version: "6.2.0"
8
  app_file: app.py
9
  pinned: false
10
  private: false
 
 
11
  ---
12
 
13
  # Video Analyzer
 
8
  app_file: app.py
9
  pinned: false
10
  private: false
11
+ hf_oauth: true
12
+ hf_oauth_expiration_minutes: 480
13
  ---
14
 
15
  # Video Analyzer
app.py CHANGED
@@ -1,11 +1,32 @@
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- demo = gr.Interface(
4
- fn=lambda x: x,
5
- inputs=gr.Textbox(label="Input"),
6
- outputs=gr.Textbox(label="Output"),
7
- title="Video Analyzer",
8
- )
 
 
9
 
10
  if __name__ == "__main__":
11
  demo.launch()
 
1
+ from __future__ import annotations
2
+
3
  import gradio as gr
4
+ from huggingface_hub import whoami
5
+
6
+
7
+ def hello(profile: gr.OAuthProfile | None) -> str:
8
+ if profile is None:
9
+ return "Please log in to continue."
10
+ return f"Hello {profile.name}!"
11
+
12
+
13
+ def list_organizations(oauth_token: gr.OAuthToken | None) -> str:
14
+ if oauth_token is None:
15
+ return ""
16
+ org_names = [org["name"] for org in whoami(oauth_token.token)["orgs"]]
17
+ if org_names:
18
+ return f"You belong to: {', '.join(org_names)}"
19
+ return "You don't belong to any organizations."
20
+
21
 
22
+ with gr.Blocks() as demo:
23
+ gr.Markdown("# Video Analyzer")
24
+ gr.LoginButton()
25
+ gr.LogoutButton()
26
+ m1 = gr.Markdown()
27
+ m2 = gr.Markdown()
28
+ demo.load(hello, inputs=None, outputs=m1)
29
+ demo.load(list_organizations, inputs=None, outputs=m2)
30
 
31
  if __name__ == "__main__":
32
  demo.launch()
pyproject.toml CHANGED
@@ -6,4 +6,5 @@ readme = "README.md"
6
  requires-python = ">=3.11"
7
  dependencies = [
8
  "gradio>=6.0.0",
 
9
  ]
 
6
  requires-python = ">=3.11"
7
  dependencies = [
8
  "gradio>=6.0.0",
9
+ "huggingface_hub>=0.20.0",
10
  ]
uv.lock CHANGED
@@ -1165,7 +1165,11 @@ version = "0.1.0"
1165
  source = { virtual = "." }
1166
  dependencies = [
1167
  { name = "gradio" },
 
1168
  ]
1169
 
1170
  [package.metadata]
1171
- requires-dist = [{ name = "gradio", specifier = ">=6.0.0" }]
 
 
 
 
1165
  source = { virtual = "." }
1166
  dependencies = [
1167
  { name = "gradio" },
1168
+ { name = "huggingface-hub" },
1169
  ]
1170
 
1171
  [package.metadata]
1172
+ requires-dist = [
1173
+ { name = "gradio", specifier = ">=6.0.0" },
1174
+ { name = "huggingface-hub", specifier = ">=0.20.0" },
1175
+ ]