NEXAS commited on
Commit
d8f7459
·
verified ·
1 Parent(s): 5eb07d7

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +3 -3
src/streamlit_app.py CHANGED
@@ -6,12 +6,12 @@ import os
6
  import numpy as np
7
  import chromadb
8
  from chromadb.utils import embedding_functions
 
9
 
10
  # Initialize session state
11
  if 'model' not in st.session_state:
12
  device = "cuda" if torch.cuda.is_available() else "cpu"
13
- cache_dir = "./clip_cache"
14
- os.makedirs(cache_dir, exist_ok=True)
15
  try:
16
  model, preprocess = clip.load("ViT-B/32", device=device, download_root=cache_dir)
17
  except Exception as e:
@@ -38,7 +38,7 @@ if 'chroma_client' not in st.session_state:
38
  st.error(f"Failed to initialize ChromaDB: {e}")
39
  st.stop()
40
 
41
- # Load demo images only once
42
  if not st.session_state.get("demo_images_loaded", False):
43
  demo_folder = "demo_images"
44
  if os.path.exists(demo_folder):
 
6
  import numpy as np
7
  import chromadb
8
  from chromadb.utils import embedding_functions
9
+ import tempfile # ✅ For safe writable cache directory
10
 
11
  # Initialize session state
12
  if 'model' not in st.session_state:
13
  device = "cuda" if torch.cuda.is_available() else "cpu"
14
+ cache_dir = tempfile.gettempdir() # ✅ Use temp dir instead of restricted local path
 
15
  try:
16
  model, preprocess = clip.load("ViT-B/32", device=device, download_root=cache_dir)
17
  except Exception as e:
 
38
  st.error(f"Failed to initialize ChromaDB: {e}")
39
  st.stop()
40
 
41
+ # Load demo images once
42
  if not st.session_state.get("demo_images_loaded", False):
43
  demo_folder = "demo_images"
44
  if os.path.exists(demo_folder):