Gopikanth123 commited on
Commit
16d15ab
·
verified ·
1 Parent(s): 52e03d0

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +19 -3
main.py CHANGED
@@ -34,10 +34,26 @@ os.makedirs(PERSIST_DIR, exist_ok=True)
34
  chat_history = []
35
  current_chat_history = []
36
 
 
 
 
 
 
37
  def data_ingestion_from_directory():
38
- documents = SimpleDirectoryReader(PDF_DIRECTORY).load_data()
39
- storage_context = StorageContext.from_defaults()
40
- index = VectorStoreIndex.from_documents(documents)
 
 
 
 
 
 
 
 
 
 
 
41
  index.storage_context.persist(persist_dir=PERSIST_DIR)
42
 
43
  def handle_query(query):
 
34
  chat_history = []
35
  current_chat_history = []
36
 
37
+ # def data_ingestion_from_directory():
38
+ # documents = SimpleDirectoryReader(PDF_DIRECTORY).load_data()
39
+ # storage_context = StorageContext.from_defaults()
40
+ # index = VectorStoreIndex.from_documents(documents)
41
+ # index.storage_context.persist(persist_dir=PERSIST_DIR)
42
  def data_ingestion_from_directory():
43
+ # Clear previous data by removing the persist directory
44
+ if os.path.exists(PERSIST_DIR):
45
+ shutil.rmtree(PERSIST_DIR) # Remove the persist directory and all its contents
46
+
47
+ # Recreate the persist directory after removal
48
+ os.makedirs(PERSIST_DIR, exist_ok=True)
49
+
50
+ # Load new documents from the directory
51
+ new_documents = SimpleDirectoryReader(PDF_DIRECTORY).load_data()
52
+
53
+ # Create a new index with the new documents
54
+ index = VectorStoreIndex.from_documents(new_documents)
55
+
56
+ # Persist the new index
57
  index.storage_context.persist(persist_dir=PERSIST_DIR)
58
 
59
  def handle_query(query):