Update app.py
Browse files
app.py
CHANGED
|
@@ -214,18 +214,18 @@ def load_pdf_and_prepare(pdf_file):
|
|
| 214 |
chunks = chunk_text(text)
|
| 215 |
index = embed_chunks(chunks)
|
| 216 |
pdf_loaded = True
|
| 217 |
-
return "
|
| 218 |
except Exception as e:
|
| 219 |
-
return f"
|
| 220 |
|
| 221 |
def delete_pdf():
|
| 222 |
global chunks, index, pdf_loaded
|
| 223 |
chunks, index, pdf_loaded = [], None, False
|
| 224 |
-
return "
|
| 225 |
|
| 226 |
def query_pdf(question, top_k=3):
|
| 227 |
if not pdf_loaded:
|
| 228 |
-
return "
|
| 229 |
question_embedding = embed_model.encode([question])
|
| 230 |
D, I = index.search(np.array(question_embedding), top_k)
|
| 231 |
context = "\n".join([chunks[i] for i in I[0]])
|
|
|
|
| 214 |
chunks = chunk_text(text)
|
| 215 |
index = embed_chunks(chunks)
|
| 216 |
pdf_loaded = True
|
| 217 |
+
return " PDF uploaded and processed successfully."
|
| 218 |
except Exception as e:
|
| 219 |
+
return f" Error: {str(e)}"
|
| 220 |
|
| 221 |
def delete_pdf():
|
| 222 |
global chunks, index, pdf_loaded
|
| 223 |
chunks, index, pdf_loaded = [], None, False
|
| 224 |
+
return " PDF cleared. Ready for new upload."
|
| 225 |
|
| 226 |
def query_pdf(question, top_k=3):
|
| 227 |
if not pdf_loaded:
|
| 228 |
+
return " Please upload and process a PDF first."
|
| 229 |
question_embedding = embed_model.encode([question])
|
| 230 |
D, I = index.search(np.array(question_embedding), top_k)
|
| 231 |
context = "\n".join([chunks[i] for i in I[0]])
|