Spaces:
Sleeping
Sleeping
Mahdi Naser Moghadasi
Revert FLUX.1 integration and restore original Stable Diffusion models
225d3ce Download cleanup_space.py from brightmind-ai/test: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/spaces/brightmind-ai/test/resolve/225d3ce4f1da1706728a984e2d60e9e16f9d5d42/cleanup_space.py
- Command line
-
hf download hf://spaces/brightmind-ai/test@225d3ce4f1da1706728a984e2d60e9e16f9d5d42/cleanup_space.py
-
curl -L -o cleanup_space.py https://huggingface.co/spaces/brightmind-ai/test/resolve/225d3ce4f1da1706728a984e2d60e9e16f9d5d42/cleanup_space.py
1.96 kB
| #!/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() | |