Update main.py
Browse files
main.py
CHANGED
|
@@ -17,10 +17,19 @@ def initialize_system():
|
|
| 17 |
# Load and process documents
|
| 18 |
documents = load_single_document(Config.DOCUMENT_FILE)
|
| 19 |
logger.info(f"Loaded {len(documents)} documents")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Generate embeddings
|
| 22 |
embeddings = generate_embeddings(documents)
|
| 23 |
logger.info(f"Generated embeddings of shape {embeddings.shape}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Initialize search engine
|
| 26 |
search_engine = SearchEngine(documents, embeddings)
|
|
|
|
| 17 |
# Load and process documents
|
| 18 |
documents = load_single_document(Config.DOCUMENT_FILE)
|
| 19 |
logger.info(f"Loaded {len(documents)} documents")
|
| 20 |
+
# ❗ Prevent crash if no document loaded
|
| 21 |
+
if documents.empty:
|
| 22 |
+
raise FileNotFoundError(f"❌ No document found at: {Config.DOCUMENT_FILE}. "
|
| 23 |
+
f"Make sure the .txt file is uploaded in Hugging Face.")
|
| 24 |
+
|
| 25 |
|
| 26 |
# Generate embeddings
|
| 27 |
embeddings = generate_embeddings(documents)
|
| 28 |
logger.info(f"Generated embeddings of shape {embeddings.shape}")
|
| 29 |
+
# ❗ Prevent FAISS error if embeddings are empty
|
| 30 |
+
if embeddings.shape[0] == 0:
|
| 31 |
+
raise ValueError("❌ Embeddings are empty! Document might be empty or path is wrong.")
|
| 32 |
+
|
| 33 |
|
| 34 |
# Initialize search engine
|
| 35 |
search_engine = SearchEngine(documents, embeddings)
|