CoolFace
Apppublic

K00B404/MergekitCustom

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
0likes
clean_community_org.py36 linesDownload Raw Back to root
1# Script to delete empty models from the community org.2# Can be run manually or scheduled to run periodically in the Space.3# Usage: python clean_community_org.py4#5# 1. List models from https://huggingface.co/mergekit-community6# 2. Filter out models with no files.7# 3. Filter out models that are newer than 1 hour.8# 4. Delete the remaining models.9from datetime import datetime, timezone10 11from huggingface_hub import HfApi12 13 14def garbage_collect_empty_models(token: str | None = None):15    api = HfApi(token=token)16    now = datetime.now(timezone.utc)17    print("Running garbage collection on mergekit-community.")18    for model in api.list_models(author="mergekit-community", full=True):19        if model.siblings and len(model.siblings) > 1:20            # If model has files, then it's not empty21            continue22        if (now - model.last_modified).total_seconds() < 3600:23            # If model was updated in the last hour, then keep it24            # to avoid deleting models that are being uploaded25            print("Skipping", model.modelId, "(recently updated)")26            continue27        try:28            print(f"Deleting {model.modelId}")29            api.delete_repo(model.modelId, missing_ok=True)30        except Exception as e:31            print(f"Error deleting {model.modelId}: {e}")32 33 34if __name__ == "__main__":35    garbage_collect_empty_models()36