Spaces:
Sleeping
Sleeping
fix KeyError: 7 becasue of state object being re-intialised within process_pdf()
Browse files
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 =
|
| 64 |
-
|
| 65 |
-
|
| 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)
|