Shubham170793 commited on
Commit
28e4d2b
·
verified ·
1 Parent(s): c28ff15

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +39 -0
src/streamlit_app.py CHANGED
@@ -1,3 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import streamlit as st
3
 
 
1
+ import shutil
2
+ import os
3
+ import streamlit as st
4
+
5
+ # ---------------------------
6
+ # 🧹 One-time cache cleaner (prevents 50 GB overflow)
7
+ # ---------------------------
8
+ def clean_cache():
9
+ folders = [
10
+ "/root/.cache/huggingface",
11
+ "/root/.cache/transformers",
12
+ "/root/.cache/torch",
13
+ "/tmp/hf_cache",
14
+ ]
15
+ total_deleted = 0
16
+ for folder in folders:
17
+ if os.path.exists(folder):
18
+ # estimate size before deleting
19
+ size = sum(
20
+ os.path.getsize(os.path.join(dp, f)) for dp, _, files in os.walk(folder) for f in files
21
+ ) / (1024**3)
22
+ total_deleted += size
23
+ shutil.rmtree(folder, ignore_errors=True)
24
+ os.makedirs("/tmp/hf_cache", exist_ok=True)
25
+ print(f"🧹 Cleaned cache folders (~{total_deleted:.2f} GB removed)")
26
+
27
+ def check_disk_usage():
28
+ """Log how much disk space is used (for debugging storage issues)."""
29
+ st.sidebar.markdown("### 💾 Disk Usage (for debugging)")
30
+ try:
31
+ usage = os.popen("du -sh /root/.cache /tmp 2>/dev/null").read()
32
+ st.sidebar.text(usage if usage else "No cache directories found.")
33
+ except Exception as e:
34
+ st.sidebar.text(f"⚠️ Could not fetch disk usage: {e}")
35
+
36
+ # Run cleanup and diagnostics at startup
37
+ clean_cache()
38
+ check_disk_usage()
39
+
40
  import os
41
  import streamlit as st
42