broadfield-dev commited on
Commit
8df5ef2
Β·
verified Β·
1 Parent(s): 6236d6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -34,7 +34,6 @@ def make_spaces_private(hf_token, selected_spaces, progress=gr.Progress()):
34
  if not selected_spaces:
35
  return "Please select at least one space to make private."
36
 
37
- # Disable progress tracking temporarily for Gradio 4+ compatibility with loops
38
  progress(0, desc="Starting...")
39
 
40
  try:
@@ -45,7 +44,9 @@ def make_spaces_private(hf_token, selected_spaces, progress=gr.Progress()):
45
  for i, space_id in enumerate(selected_spaces):
46
  progress((i + 1) / total_spaces, desc=f"Processing '{space_id}'...")
47
  try:
48
- api.update_repo_settings(repo_id=space_id, private=True)
 
 
49
  log_messages.append(f"βœ… Successfully made '{space_id}' private.")
50
  except Exception as e:
51
  log_messages.append(f"❌ Failed to make '{space_id}' private: {e}")
@@ -63,10 +64,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
63
  """
64
  # πŸ›‘οΈ Hugging Face Space Privacy Control
65
  Quickly make your public Hugging Face Spaces private.
66
- 1. Enter your Hugging Face access token with **write** permission.
67
  2. Click "List My Public Spaces".
68
  3. Select the spaces you want to make private (or use "Select All").
69
- 4. Click the final button to make them private.
70
  """
71
  )
72
 
@@ -80,7 +81,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
80
  list_spaces_button = gr.Button("List My Public Spaces", variant="secondary", scale=1)
81
 
82
  with gr.Group():
83
- # This (invisible) state component is the key to the fix
84
  spaces_list_state = gr.State([])
85
 
86
  select_all_checkbox = gr.Checkbox(label="Select All / Deselect All")
@@ -91,19 +92,20 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
91
  )
92
 
93
  make_private_button = gr.Button("Make Selected Spaces Private", variant="primary")
94
- status_output = gr.Textbox(label="Status", interactive=False)
95
 
96
  # --- Event Listeners ---
97
 
98
  def list_spaces_action(token):
99
  """Called when the list button is clicked. Updates the checkboxes and the state."""
100
  spaces, message, state_list = get_my_spaces(token)
101
- return gr.update(choices=spaces, value=[]), message, state_list
 
102
 
103
  list_spaces_button.click(
104
  fn=list_spaces_action,
105
  inputs=hf_token_input,
106
- outputs=[spaces_checkboxes, status_output, spaces_list_state]
107
  )
108
 
109
  def select_all_action(select_all_checked, full_list_of_spaces):
 
34
  if not selected_spaces:
35
  return "Please select at least one space to make private."
36
 
 
37
  progress(0, desc="Starting...")
38
 
39
  try:
 
44
  for i, space_id in enumerate(selected_spaces):
45
  progress((i + 1) / total_spaces, desc=f"Processing '{space_id}'...")
46
  try:
47
+ # --- THIS IS THE FIX ---
48
+ # We must explicitly tell the API that this is a 'space'.
49
+ api.update_repo_settings(repo_id=space_id, private=True, repo_type="space")
50
  log_messages.append(f"βœ… Successfully made '{space_id}' private.")
51
  except Exception as e:
52
  log_messages.append(f"❌ Failed to make '{space_id}' private: {e}")
 
64
  """
65
  # πŸ›‘οΈ Hugging Face Space Privacy Control
66
  Quickly make your public Hugging Face Spaces private.
67
+ 1. Create and paste a Hugging Face access token with **write** permission.
68
  2. Click "List My Public Spaces".
69
  3. Select the spaces you want to make private (or use "Select All").
70
+ 4. Click the final button to update their privacy settings.
71
  """
72
  )
73
 
 
81
  list_spaces_button = gr.Button("List My Public Spaces", variant="secondary", scale=1)
82
 
83
  with gr.Group():
84
+ # This (invisible) state component is the key to the select_all fix
85
  spaces_list_state = gr.State([])
86
 
87
  select_all_checkbox = gr.Checkbox(label="Select All / Deselect All")
 
92
  )
93
 
94
  make_private_button = gr.Button("Make Selected Spaces Private", variant="primary")
95
+ status_output = gr.Textbox(label="Status", interactive=False, lines=5)
96
 
97
  # --- Event Listeners ---
98
 
99
  def list_spaces_action(token):
100
  """Called when the list button is clicked. Updates the checkboxes and the state."""
101
  spaces, message, state_list = get_my_spaces(token)
102
+ # Also reset the select_all checkbox to unchecked
103
+ return gr.update(choices=spaces, value=[]), message, state_list, gr.update(value=False)
104
 
105
  list_spaces_button.click(
106
  fn=list_spaces_action,
107
  inputs=hf_token_input,
108
+ outputs=[spaces_checkboxes, status_output, spaces_list_state, select_all_checkbox]
109
  )
110
 
111
  def select_all_action(select_all_checked, full_list_of_spaces):