cakemus commited on
Commit
1489a02
·
1 Parent(s): d7b99e1

cache cleanup

Browse files
Files changed (2) hide show
  1. app.py +2 -6
  2. cleanup.py +23 -0
app.py CHANGED
@@ -4,13 +4,9 @@ from diffusers import StableVideoDiffusionPipeline
4
  from diffusers.utils import load_image, export_to_video
5
  import spaces
6
  import os
 
7
 
8
- # Check disk usage
9
- os.system("df -h")
10
-
11
- # Clear Hugging Face cache
12
- os.system("rm -rf ~/.cache/huggingface")
13
- os.system("rm -rf ~/.cache/transformers")
14
 
15
  # Check if GPU is available
16
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
4
  from diffusers.utils import load_image, export_to_video
5
  import spaces
6
  import os
7
+ import cleanup # Import the cleanup script
8
 
9
+ cleanup.free_up_space() # Call the cleanup function
 
 
 
 
 
10
 
11
  # Check if GPU is available
12
  device = "cuda" if torch.cuda.is_available() else "cpu"
cleanup.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import shutil
3
+
4
+ def free_up_space():
5
+ # Check disk usage before cleanup
6
+ print("Disk usage before cleanup:")
7
+ os.system("df -h")
8
+
9
+ # Clear Hugging Face cache
10
+ print("Clearing Hugging Face cache...")
11
+ shutil.rmtree(os.path.expanduser("~/.cache/huggingface"), ignore_errors=True)
12
+ shutil.rmtree(os.path.expanduser("~/.cache/transformers"), ignore_errors=True)
13
+
14
+ # Clear PyTorch cache
15
+ print("Clearing PyTorch cache...")
16
+ shutil.rmtree(os.path.expanduser("~/.cache/torch"), ignore_errors=True)
17
+
18
+ # Check disk usage after cleanup
19
+ print("Disk usage after cleanup:")
20
+ os.system("df -h")
21
+
22
+ if __name__ == "__main__":
23
+ free_up_space()