nikhmr1235 commited on
Commit
0215574
·
verified ·
1 Parent(s): 9dcff61

fix KeyError: 7 becasue of state object being re-intialised within process_pdf()

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -59,10 +59,15 @@ def process_pdf(pdf_file, state):
59
  state
60
  )
61
 
 
 
 
 
 
62
  # Create a new session and directory for the user
63
- state = new_session()
64
- if not os.path.exists(state.vector_store_path):
65
- os.makedirs(state.vector_store_path)
66
 
67
  # Extract text from the PDF using PyMuPDF (fitz)
68
  doc = fitz.open(pdf_file.name)
 
59
  state
60
  )
61
 
62
+ # Remove the old temporary directory if it exists
63
+ if os.path.exists(state.vector_store_path):
64
+ shutil.rmtree(state.vector_store_path)
65
+ state.db = None # Reset the database state
66
+
67
  # Create a new session and directory for the user
68
+ state.session_id = str(uuid.uuid4())
69
+ state.vector_store_path = os.path.join(CHROMA_DB_PATH, state.session_id)
70
+ os.makedirs(state.vector_store_path)
71
 
72
  # Extract text from the PDF using PyMuPDF (fitz)
73
  doc = fitz.open(pdf_file.name)