JustAnotherCibrarian commited on
Commit
781ae19
·
verified ·
1 Parent(s): 6489caf

Revert to V2,

Browse files
Files changed (1) hide show
  1. app.py +34 -68
app.py CHANGED
@@ -32,7 +32,6 @@ def get_gated_repos(username: str, token: str) -> list[str]:
32
 
33
  def get_organisation(username: str) -> list[str]:
34
  """Returns all members in organisation.
35
-
36
  If not an organisation, returns [user].
37
  """
38
  try:
@@ -57,7 +56,6 @@ def grant_access_to_repo(token, repo_id, username):
57
 
58
  def grant_access_multiple_repos(token, repo_list, username):
59
  """Grant access to multiple repositories + users at once.
60
-
61
  Users are dereferenced by organisation.
62
  """
63
  if not token:
@@ -78,9 +76,9 @@ def grant_access_multiple_repos(token, repo_list, username):
78
 
79
  return "\n".join(results)
80
 
81
- with gr.Blocks(title="HF Repo Access Manager") as demo:
82
- gr.Markdown("# 🔐 Hugging Face Repo Access Manager")
83
- gr.Markdown("Grant access to users/organizations for your repositories")
84
 
85
  hf_user = gr.Textbox(
86
  label = "Huggingface user",
@@ -102,48 +100,26 @@ with gr.Blocks(title="HF Repo Access Manager") as demo:
102
  scale=0,
103
  min_width=40
104
  )
105
-
106
- with gr.Tab("Request access"):
107
- with gr.Row():
108
- with gr.Column():
109
- req_repo_input = gr.Dropdown(
110
- label="Repositories to request",
111
- multiselect=True,
112
- allow_custom_value=True, # Can type other people's repos.
113
- interactive=True,
114
- choices=[DUMMY_REFRESH],
115
- value=[],
116
- info="Username/repo-name"
117
- )
118
- req_user_input = gr.Textbox(
119
- label="User/Organization",
120
- placeholder="username-or-org-name"
121
- )
122
- req_btn = gr.Button("Request access", variant="primary")
123
-
124
- with gr.Column():
125
- req_output = gr.Textbox(label="Results", lines=10)
126
 
127
- with gr.Tab("Grant access"):
128
- with gr.Row():
129
- with gr.Column():
130
- gra_repo_input = gr.Dropdown(
131
- label="Repositories to grant",
132
- multiselect=True,
133
- allow_custom_value=True, # Can type other people's repos.
134
- interactive=True,
135
- choices=[DUMMY_REFRESH],
136
- value=[],
137
- info="Username/repo-name"
138
- )
139
- gra_user_input = gr.Textbox(
140
- label="User/Organization",
141
- placeholder="username-or-org-name"
142
- )
143
- gra_btn = gr.Button("Grant access", variant="primary")
144
-
145
- with gr.Column():
146
- gra_output = gr.Textbox(label="Results", lines=10)
147
 
148
  # ---Actions---
149
 
@@ -172,13 +148,12 @@ with gr.Blocks(title="HF Repo Access Manager") as demo:
172
  Lambda method doesn't seem to work for some reason,
173
  perhaps profile and oauth aren't functional with args/kwargs.
174
  """
175
- dropbear = refresh_all_data(username, token, force = True)
176
- return (dropbear, dropbear)
177
 
178
  refresh_repos_btn.click(
179
  fn=force_refresh,
180
  inputs=[hf_user, hf_token],
181
- outputs=[req_repo_input, gra_repo_input]
182
  )
183
 
184
  def check_dummy(username, token, dropdown_value = None):
@@ -200,28 +175,19 @@ with gr.Blocks(title="HF Repo Access Manager") as demo:
200
  return refresh_all_data(username, token, indwild = True)
201
  return gr.Dropdown()
202
 
203
- # Dummy + wild load only.
204
- req_repo_input.change(
205
- fn=check_dummy,
206
- inputs=[hf_user, hf_token, req_repo_input],
207
- outputs=[req_repo_input]
208
- )
209
- gra_repo_input.change(
210
  fn=check_dummy,
211
- inputs=[hf_user, hf_token, gra_repo_input],
212
- outputs=[gra_repo_input]
213
  )
214
-
215
- req_btn.click(
216
- fn=grant_access_multiple_repos,
217
- inputs=[hf_token, req_repo_input, req_user_input],
218
- outputs=req_output
219
- )
220
- gra_btn.click(
221
  fn=grant_access_multiple_repos,
222
- inputs=[hf_token, gra_repo_input, gra_user_input],
223
- outputs=gra_output
224
  )
225
 
226
  if __name__ == "__main__":
227
- demo.launch()
 
 
32
 
33
  def get_organisation(username: str) -> list[str]:
34
  """Returns all members in organisation.
 
35
  If not an organisation, returns [user].
36
  """
37
  try:
 
56
 
57
  def grant_access_multiple_repos(token, repo_list, username):
58
  """Grant access to multiple repositories + users at once.
 
59
  Users are dereferenced by organisation.
60
  """
61
  if not token:
 
76
 
77
  return "\n".join(results)
78
 
79
+ with gr.Blocks(title="HF Bouncer") as demo:
80
+ gr.Markdown("# ⛹️ Huggingface Bouncer")
81
+ gr.Markdown("Grant access to users/organizations for multiple repositories")
82
 
83
  hf_user = gr.Textbox(
84
  label = "Huggingface user",
 
100
  scale=0,
101
  min_width=40
102
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
+ with gr.Row():
105
+ with gr.Column():
106
+ multi_repo_input = gr.Dropdown(
107
+ label="Repositories to grant",
108
+ multiselect=True,
109
+ allow_custom_value=True, # Can type other people's repos.
110
+ interactive=True,
111
+ choices=[DUMMY_REFRESH],
112
+ value=[],
113
+ info="Username/repo-name"
114
+ )
115
+ multi_user_input = gr.Textbox(
116
+ label="User/Organization",
117
+ placeholder="username-or-org-name"
118
+ )
119
+ multi_btn = gr.Button("Grant Access to All", variant="primary")
120
+
121
+ with gr.Column():
122
+ multi_output = gr.Textbox(label="Results", lines=10)
 
123
 
124
  # ---Actions---
125
 
 
148
  Lambda method doesn't seem to work for some reason,
149
  perhaps profile and oauth aren't functional with args/kwargs.
150
  """
151
+ return refresh_all_data(username, token, force = True)
 
152
 
153
  refresh_repos_btn.click(
154
  fn=force_refresh,
155
  inputs=[hf_user, hf_token],
156
+ outputs=[multi_repo_input]
157
  )
158
 
159
  def check_dummy(username, token, dropdown_value = None):
 
175
  return refresh_all_data(username, token, indwild = True)
176
  return gr.Dropdown()
177
 
178
+ # Dummy load only.
179
+ multi_repo_input.change(
 
 
 
 
 
180
  fn=check_dummy,
181
+ inputs=[hf_user, hf_token, multi_repo_input],
182
+ outputs=[multi_repo_input]
183
  )
184
+
185
+ multi_btn.click(
 
 
 
 
 
186
  fn=grant_access_multiple_repos,
187
+ inputs=[hf_token, multi_repo_input, multi_user_input],
188
+ outputs=multi_output
189
  )
190
 
191
  if __name__ == "__main__":
192
+ demo.launch()
193
+