Spaces:
Sleeping
Sleeping
Update bumain2.py
Browse files- bumain2.py +12 -5
bumain2.py
CHANGED
|
@@ -55,16 +55,23 @@ class CounselingKnowledgeBase:
|
|
| 55 |
self.force_reload = force_reload
|
| 56 |
self.full_documents = [] # Store full document text
|
| 57 |
|
| 58 |
-
|
| 59 |
try:
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
)
|
|
|
|
| 63 |
self.load_documents()
|
| 64 |
except Exception as e:
|
| 65 |
-
print(f"Error initializing embeddings model: {e}")
|
| 66 |
-
print("
|
| 67 |
self.embeddings = None
|
|
|
|
|
|
|
| 68 |
|
| 69 |
def load_documents(self):
|
| 70 |
"""Load and process PDF documents into a vector store."""
|
|
|
|
| 55 |
self.force_reload = force_reload
|
| 56 |
self.full_documents = [] # Store full document text
|
| 57 |
|
| 58 |
+
# Error handling for embedding model initialization
|
| 59 |
try:
|
| 60 |
+
# Use a local embeddings model that works well on HF Spaces
|
| 61 |
+
print("Initializing HuggingFace embeddings model...")
|
| 62 |
+
self.embeddings = HuggingFaceEmbeddings(
|
| 63 |
+
model_name="sentence-transformers/all-MiniLM-L6-v2", # Lightweight and fast
|
| 64 |
+
model_kwargs={'device': 'cpu'}, # Force CPU usage for HF Spaces
|
| 65 |
+
encode_kwargs={'normalize_embeddings': True}
|
| 66 |
)
|
| 67 |
+
print("✅ HuggingFace embeddings model initialized successfully")
|
| 68 |
self.load_documents()
|
| 69 |
except Exception as e:
|
| 70 |
+
print(f"❌ Error initializing embeddings model: {e}")
|
| 71 |
+
print("Failed to initialize HuggingFace embeddings")
|
| 72 |
self.embeddings = None
|
| 73 |
+
# Don't exit, but warn that knowledge base won't work
|
| 74 |
+
print("⚠️ Knowledge base will not be available")
|
| 75 |
|
| 76 |
def load_documents(self):
|
| 77 |
"""Load and process PDF documents into a vector store."""
|