JustAnotherCibrarian commited on
Commit
f1deedf
·
verified ·
1 Parent(s): c6cf308

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -2,19 +2,18 @@ import gradio as gr
2
  from typing import Optional
3
  from huggingface_hub import HfApi
4
 
5
- def grant_access_to_repo(profile: Optional[gr.OAuthProfile], oauth_token: gr.OAuthToken, repo_id, username):
6
  """
7
  Grant access to a user/organization for a specific repo
8
  """
9
  try:
10
- gr.Info("SBM req: " + repo_id + "|" + username + "|" + oauth_token.token)
11
  api = HfApi()
12
- api.grant_access(repo_id=repo_id, user=username, token=oauth_token.token)
13
  return f"✅ Successfully granted access to {username} for {repo_id}"
14
  except Exception as e:
15
  return f"❌ Error: {str(e)}"
16
 
17
- def grant_access_multiple_repos(profile: Optional[gr.OAuthProfile], oauth_token: gr.OAuthToken, repo_list, username):
18
  """
19
  Grant access to multiple repositories at once
20
  """
@@ -25,7 +24,7 @@ def grant_access_multiple_repos(profile: Optional[gr.OAuthProfile], oauth_token:
25
 
26
  for repo_id in repos:
27
  try:
28
- api.grant_access(repo_id=repo_id, user=username, token=oauth_token.token)
29
  results.append(f"✅ {repo_id}: Success")
30
  except Exception as e:
31
  results.append(f"❌ {repo_id}: {str(e)}")
@@ -36,7 +35,13 @@ with gr.Blocks(title="HF Repo Access Manager") as demo:
36
  gr.Markdown("# 🔐 Hugging Face Repo Access Manager")
37
  gr.Markdown("Grant access to users/organizations for your repositories")
38
 
39
- gr.LoginButton(elem_id="login")
 
 
 
 
 
 
40
 
41
  with gr.Tab("Single Repository"):
42
  with gr.Row():
@@ -77,13 +82,13 @@ with gr.Blocks(title="HF Repo Access Manager") as demo:
77
  # Connect the buttons
78
  single_btn.click(
79
  fn=grant_access_to_repo,
80
- inputs=[repo_input, user_input],
81
  outputs=single_output
82
  )
83
 
84
  multi_btn.click(
85
  fn=grant_access_multiple_repos,
86
- inputs=[multi_repo_input, multi_user_input],
87
  outputs=multi_output
88
  )
89
 
 
2
  from typing import Optional
3
  from huggingface_hub import HfApi
4
 
5
+ def grant_access_to_repo(token, repo_id, username):
6
  """
7
  Grant access to a user/organization for a specific repo
8
  """
9
  try:
 
10
  api = HfApi()
11
+ api.grant_access(repo_id=repo_id, user=username, token=token)
12
  return f"✅ Successfully granted access to {username} for {repo_id}"
13
  except Exception as e:
14
  return f"❌ Error: {str(e)}"
15
 
16
+ def grant_access_multiple_repos(token, repo_list, username):
17
  """
18
  Grant access to multiple repositories at once
19
  """
 
24
 
25
  for repo_id in repos:
26
  try:
27
+ api.grant_access(repo_id=repo_id, user=username, token=token)
28
  results.append(f"✅ {repo_id}: Success")
29
  except Exception as e:
30
  results.append(f"❌ {repo_id}: {str(e)}")
 
35
  gr.Markdown("# 🔐 Hugging Face Repo Access Manager")
36
  gr.Markdown("Grant access to users/organizations for your repositories")
37
 
38
+ hf_token = gr.Textbox(
39
+ label="Huggingface token",
40
+ placeholder="hf_xxxxxxxxxxxxxxxx",
41
+ type="password",
42
+ info="Your HF token with write permissions",
43
+ max_lines=1
44
+ )
45
 
46
  with gr.Tab("Single Repository"):
47
  with gr.Row():
 
82
  # Connect the buttons
83
  single_btn.click(
84
  fn=grant_access_to_repo,
85
+ inputs=[hf_token, repo_input, user_input],
86
  outputs=single_output
87
  )
88
 
89
  multi_btn.click(
90
  fn=grant_access_multiple_repos,
91
+ inputs=[hf_token, multi_repo_input, multi_user_input],
92
  outputs=multi_output
93
  )
94