Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: Fix clean up script, also clean spaces #348

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions scripts/clean_skops.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""This script removes all repos under the skops user on HF Hub.
"""This script removes all old repos under the skops user on HF Hub.

The user is used for the CI and if there are leftover repos, they can be
removed.
Expand All @@ -7,28 +7,61 @@
import datetime

from huggingface_hub import HfApi
from requests.exceptions import HTTPError

MAX_AGE = 7 # in days

# This is the token for the skops user. TODO remove eventually, see issue #47
token = "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"
client = HfApi(token=token)
user = client.whoami()["name"]
answer = input(
f"Are you sure you want to delete all repos under {user} older than 7 days? (y/[n])"
f"Are you sure you want to delete all repos under {user} older than {MAX_AGE} days?"
" (y/[n]) "
)
if answer != "y":
exit(1)
models = [x for x in client.list_models(author=user)]

# MODELS

models = [x for x in client.list_models(author=user)]
print(f"Found {len(models)} models, checking their age...")

for model_info in models:
info = client.model_info(model_info.modelId)
try:
info = client.model_info(model_info.modelId)
except HTTPError:
# https://github.com/huggingface/moon-landing/issues/6034
continue

age = (
datetime.datetime.now()
- datetime.datetime.fromisoformat(info.lastModified.rsplit(".", 1)[0])
).days
if age < 7:
if age < MAX_AGE:
print(f"Skipping model: {model_info.modelId}, age: {age}")
continue
print(f"deleting {model_info.modelId}, age: {age} days")
client.delete_repo(model_info.modelId)

# SPACES

spaces = [x for x in client.list_spaces(author=user)]
print(f"Found {len(spaces)} spaces, checking their age...")

for space_info in spaces:
try:
info = client.space_info(space_info.id)
except HTTPError:
# https://github.com/huggingface/moon-landing/issues/6034
continue

age = (
datetime.datetime.now()
- datetime.datetime.fromisoformat(info.lastModified.rsplit(".", 1)[0])
).days
if age < MAX_AGE:
print(f"Skipping space: {space_info.id}, age: {age}")
continue
print(f"deleting {space_info.id}, age: {age} days")
client.delete_repo(space_info.id, repo_type="space")