Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ from huggingface_hub import HfApi
|
|
| 3 |
from huggingface_hub.utils import HfHubHTTPError
|
| 4 |
|
| 5 |
# --- Core Functions ---
|
| 6 |
-
|
| 7 |
def get_my_spaces(hf_token):
|
| 8 |
"""Fetches a list of the user's public Hugging Face Spaces."""
|
| 9 |
if not hf_token:
|
|
@@ -26,7 +26,38 @@ def get_my_spaces(hf_token):
|
|
| 26 |
except Exception as e:
|
| 27 |
return [], f"An error occurred: {e}", []
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
|
|
|
| 30 |
def make_spaces_private(hf_token, selected_spaces, progress=gr.Progress()):
|
| 31 |
"""Sets the visibility of selected Hugging Face Spaces to private."""
|
| 32 |
if not hf_token:
|
|
|
|
| 3 |
from huggingface_hub.utils import HfHubHTTPError
|
| 4 |
|
| 5 |
# --- Core Functions ---
|
| 6 |
+
this_space="broadfield-dev/HF-privatize"
|
| 7 |
def get_my_spaces(hf_token):
|
| 8 |
"""Fetches a list of the user's public Hugging Face Spaces."""
|
| 9 |
if not hf_token:
|
|
|
|
| 26 |
except Exception as e:
|
| 27 |
return [], f"An error occurred: {e}", []
|
| 28 |
|
| 29 |
+
def make_spaces_paused(hf_token, selected_spaces, progress=gr.Progress()):
|
| 30 |
+
"""Sets the visibility of selected Hugging Face Spaces to private."""
|
| 31 |
+
if not hf_token:
|
| 32 |
+
return "Please enter your Hugging Face token."
|
| 33 |
+
if not selected_spaces:
|
| 34 |
+
return "Please select at least one space to Pause."
|
| 35 |
+
|
| 36 |
+
progress(0, desc="Starting...")
|
| 37 |
+
|
| 38 |
+
try:
|
| 39 |
+
api = HfApi(token=hf_token)
|
| 40 |
+
log_messages = []
|
| 41 |
+
total_spaces = len(selected_spaces)
|
| 42 |
+
|
| 43 |
+
for i, space_id in enumerate(selected_spaces):
|
| 44 |
+
progress((i + 1) / total_spaces, desc=f"Processing '{space_id}'...")
|
| 45 |
+
try:
|
| 46 |
+
# --- THIS IS THE FIX ---
|
| 47 |
+
# We must explicitly tell the API that this is a 'space'.
|
| 48 |
+
if not space_id == this_space:
|
| 49 |
+
api.pause_space()
|
| 50 |
+
log_messages.append(f"✅ Successfully made '{space_id}' paused.")
|
| 51 |
+
except Exception as e:
|
| 52 |
+
log_messages.append(f"❌ Failed to make '{space_id}' paused: {e}")
|
| 53 |
+
|
| 54 |
+
return "\n".join(log_messages)
|
| 55 |
+
except HfHubHTTPError as e:
|
| 56 |
+
return f"Authentication error: Please check your token. Details: {e}"
|
| 57 |
+
except Exception as e:
|
| 58 |
+
return f"An error occurred: {e}"
|
| 59 |
|
| 60 |
+
|
| 61 |
def make_spaces_private(hf_token, selected_spaces, progress=gr.Progress()):
|
| 62 |
"""Sets the visibility of selected Hugging Face Spaces to private."""
|
| 63 |
if not hf_token:
|