Tushar Malik commited on
Commit
ed8b7cc
·
verified ·
1 Parent(s): 72f8608

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -16,6 +16,7 @@ from sklearn.preprocessing import normalize
16
  from rank_bm25 import BM25Okapi
17
  from gensim.models import Word2Vec
18
  from typing import List, Optional, Tuple
 
19
 
20
  # Cell 3: Set up logging and Mistral client
21
  logger = logging.getLogger(__name__)
@@ -505,12 +506,22 @@ def chatbot_interface(user_query, response_style, selected_retrieval_methods, se
505
  vector_db_path = "vector_db.pkl"
506
  annoy_index_path = "vector_index.ann"
507
  if pdf_file is not None:
508
- pdf_path = pdf_file.name # Get the path of the uploaded file
509
- create_vector_db_and_annoy_index(pdf_path, 'vector_db.pkl', 'vector_index.ann')
 
 
 
 
510
  store_embeddings_in_vector_db(pdf_path, 'vector_db.pkl', 'vector_index.ann', chunk_size, overlap)
511
-
512
  else:
513
  return "Please upload a PDF file."
 
 
 
 
 
 
 
514
 
515
  # Load the documents and create embeddings with the provided chunk_size and overlap
516
  #store_embeddings_in_vector_db('med.pdf', 'vector_db.pkl', 'vector_index.ann', chunk_size, overlap)
 
16
  from rank_bm25 import BM25Okapi
17
  from gensim.models import Word2Vec
18
  from typing import List, Optional, Tuple
19
+ import tempfile
20
 
21
  # Cell 3: Set up logging and Mistral client
22
  logger = logging.getLogger(__name__)
 
506
  vector_db_path = "vector_db.pkl"
507
  annoy_index_path = "vector_index.ann"
508
  if pdf_file is not None:
509
+ with tempfile.NamedTemporaryFile(mode="wb", suffix=".pdf", delete=False) as tmp:
510
+ tmp.write(pdf_file) # Write the uploaded file content to the temporary file
511
+ pdf_path = tmp.name
512
+
513
+ # Create vector DB and Annoy index
514
+ create_vector_db_and_annoy_index(pdf_path, vector_db_path, annoy_index_path)
515
  store_embeddings_in_vector_db(pdf_path, 'vector_db.pkl', 'vector_index.ann', chunk_size, overlap)
 
516
  else:
517
  return "Please upload a PDF file."
518
+ # if pdf_file is not None:
519
+ # pdf_path = pdf_file.name # Get the path of the uploaded file
520
+ # create_vector_db_and_annoy_index(pdf_path, 'vector_db.pkl', 'vector_index.ann')
521
+ # store_embeddings_in_vector_db(pdf_path, 'vector_db.pkl', 'vector_index.ann', chunk_size, overlap)
522
+
523
+ # else:
524
+ # return "Please upload a PDF file."
525
 
526
  # Load the documents and create embeddings with the provided chunk_size and overlap
527
  #store_embeddings_in_vector_db('med.pdf', 'vector_db.pkl', 'vector_index.ann', chunk_size, overlap)