Update app.py
Browse files
app.py
CHANGED
|
@@ -127,7 +127,7 @@ def load_vector_index(role: str):
|
|
| 127 |
)
|
| 128 |
Settings.embed_model = embed_model
|
| 129 |
|
| 130 |
-
# ✅
|
| 131 |
if os.getenv("VERCEL") or os.access(".", os.W_OK) is False:
|
| 132 |
persist_dir = os.path.join("/tmp", "chroma_db", role)
|
| 133 |
else:
|
|
@@ -138,8 +138,11 @@ def load_vector_index(role: str):
|
|
| 138 |
# Initialize Chroma client
|
| 139 |
chroma_client = chromadb.PersistentClient(path=persist_dir)
|
| 140 |
|
| 141 |
-
# Get
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
# Create vector store
|
| 145 |
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
|
|
@@ -159,6 +162,7 @@ def load_vector_index(role: str):
|
|
| 159 |
except Exception as e:
|
| 160 |
st.error(f"Error loading vector index: {str(e)}")
|
| 161 |
st.stop()
|
|
|
|
| 162 |
def chat_interface():
|
| 163 |
"""Main chat interface"""
|
| 164 |
# Add styled heading
|
|
|
|
| 127 |
)
|
| 128 |
Settings.embed_model = embed_model
|
| 129 |
|
| 130 |
+
# ✅ Use /tmp for Vercel/read-only filesystems
|
| 131 |
if os.getenv("VERCEL") or os.access(".", os.W_OK) is False:
|
| 132 |
persist_dir = os.path.join("/tmp", "chroma_db", role)
|
| 133 |
else:
|
|
|
|
| 138 |
# Initialize Chroma client
|
| 139 |
chroma_client = chromadb.PersistentClient(path=persist_dir)
|
| 140 |
|
| 141 |
+
# ✅ Get or create collection
|
| 142 |
+
try:
|
| 143 |
+
chroma_collection = chroma_client.get_collection("documents")
|
| 144 |
+
except chromadb.errors.NotFoundError:
|
| 145 |
+
chroma_collection = chroma_client.create_collection("documents")
|
| 146 |
|
| 147 |
# Create vector store
|
| 148 |
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
|
|
|
|
| 162 |
except Exception as e:
|
| 163 |
st.error(f"Error loading vector index: {str(e)}")
|
| 164 |
st.stop()
|
| 165 |
+
|
| 166 |
def chat_interface():
|
| 167 |
"""Main chat interface"""
|
| 168 |
# Add styled heading
|