Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -280,13 +280,17 @@ def get_web_search_database():
|
|
280 |
temp_dir = tempfile.mkdtemp()
|
281 |
|
282 |
try:
|
283 |
-
#
|
284 |
-
|
285 |
-
|
|
|
|
|
|
|
|
|
286 |
except Exception as e:
|
287 |
logging.error(f"Error initializing WebSearchFAISS: {str(e)}", exc_info=True)
|
288 |
# If initialization fails, create an empty database
|
289 |
-
database =
|
290 |
logging.info("Created empty WebSearchFAISS database manually")
|
291 |
|
292 |
return database, temp_dir
|
@@ -306,7 +310,7 @@ def duckduckgo_search(query):
|
|
306 |
documents = []
|
307 |
for result in results:
|
308 |
content = f"{result['title']}\n{result['body']}"
|
309 |
-
doc =
|
310 |
documents.append(doc)
|
311 |
|
312 |
logging.info(f"Number of documents created: {len(documents)}")
|
@@ -317,7 +321,7 @@ def duckduckgo_search(query):
|
|
317 |
except Exception as e:
|
318 |
logging.error(f"Error adding documents to database: {str(e)}", exc_info=True)
|
319 |
# If adding documents fails, create a new database with these documents
|
320 |
-
database =
|
321 |
logging.info("Created new WebSearchFAISS database with search results")
|
322 |
return database, temp_dir, results
|
323 |
except Exception as e:
|
|
|
280 |
temp_dir = tempfile.mkdtemp()
|
281 |
|
282 |
try:
|
283 |
+
# Create a dummy document to initialize the database
|
284 |
+
dummy_doc = Document(page_content="Dummy content", metadata={"source": "dummy"})
|
285 |
+
database = FAISS.from_documents([dummy_doc], embed)
|
286 |
+
logging.info("Successfully initialized WebSearchFAISS database with dummy document")
|
287 |
+
# Remove the dummy document
|
288 |
+
database.delete(["dummy"])
|
289 |
+
logging.info("Removed dummy document from database")
|
290 |
except Exception as e:
|
291 |
logging.error(f"Error initializing WebSearchFAISS: {str(e)}", exc_info=True)
|
292 |
# If initialization fails, create an empty database
|
293 |
+
database = FAISS(embed, None, {}, {}, None)
|
294 |
logging.info("Created empty WebSearchFAISS database manually")
|
295 |
|
296 |
return database, temp_dir
|
|
|
310 |
documents = []
|
311 |
for result in results:
|
312 |
content = f"{result['title']}\n{result['body']}"
|
313 |
+
doc = Document(page_content=content, metadata={"source": result['href']})
|
314 |
documents.append(doc)
|
315 |
|
316 |
logging.info(f"Number of documents created: {len(documents)}")
|
|
|
321 |
except Exception as e:
|
322 |
logging.error(f"Error adding documents to database: {str(e)}", exc_info=True)
|
323 |
# If adding documents fails, create a new database with these documents
|
324 |
+
database = FAISS.from_documents(documents, get_embeddings())
|
325 |
logging.info("Created new WebSearchFAISS database with search results")
|
326 |
return database, temp_dir, results
|
327 |
except Exception as e:
|