Spaces:
Sleeping
Sleeping
File size: 1,958 Bytes
601985d 225d3ce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #!/usr/bin/env python3
"""
Cleanup script to reduce Hugging Face Space size
"""
import os
import shutil
import glob
def cleanup_space():
"""Clean up unnecessary files to reduce space usage"""
# Remove common cache directories
cache_dirs = [
'__pycache__',
'.pytest_cache',
'.mypy_cache',
'.coverage',
'htmlcov',
'gradio_cached_examples',
'flagged',
'.cache',
'huggingface_hub'
]
for cache_dir in cache_dirs:
if os.path.exists(cache_dir):
print(f"Removing {cache_dir}")
shutil.rmtree(cache_dir, ignore_errors=True)
# Remove common cache files
cache_patterns = [
'*.pyc',
'*.pyo',
'*.log',
'*.tmp',
'*.temp',
'.DS_Store',
'Thumbs.db'
]
for pattern in cache_patterns:
for file_path in glob.glob(pattern, recursive=True):
try:
if os.path.isfile(file_path):
os.remove(file_path)
print(f"Removed {file_path}")
except Exception as e:
print(f"Could not remove {file_path}: {e}")
# Remove large model files if they exist
large_extensions = ['.pth', '.bin', '.model', '.weights', '.h5', '.hdf5', '.pkl', '.pickle']
for ext in large_extensions:
for file_path in glob.glob(f'**/*{ext}', recursive=True):
try:
if os.path.isfile(file_path):
size_mb = os.path.getsize(file_path) / (1024 * 1024)
if size_mb > 10: # Only remove files larger than 10MB
os.remove(file_path)
print(f"Removed large file {file_path} ({size_mb:.1f}MB)")
except Exception as e:
print(f"Could not remove {file_path}: {e}")
print("Cleanup completed!")
if __name__ == "__main__":
cleanup_space()
|