NaimaAqeel commited on
Commit
4d0c42b
·
verified ·
1 Parent(s): 0632240

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -58,15 +58,31 @@ retriever = AutoModelForSeq2SeqLM.from_pretrained(retriever_model_name)
58
  retriever_tokenizer = AutoTokenizer.from_pretrained(retriever_model_name)
59
 
60
 
61
- # Load or create FAISS index (same as before)
62
  index_path = "faiss_index.pkl"
63
  document_texts_path = "document_texts.pkl"
64
  document_texts = []
65
- # ... (rest of the FAISS index loading logic)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
 
68
  def preprocess_text(text):
69
- # ... (text preprocessing logic, e.g., sentence segmentation and optional stop word removal)
 
70
 
71
 
72
  def upload_files(files):
 
58
  retriever_tokenizer = AutoTokenizer.from_pretrained(retriever_model_name)
59
 
60
 
61
+ # Load or create FAISS index
62
  index_path = "faiss_index.pkl"
63
  document_texts_path = "document_texts.pkl"
64
  document_texts = []
65
+ if os.path.exists(index_path) and os.path.exists(document_texts_path):
66
+ try:
67
+ with open(index_path, "rb") as f:
68
+ index = pickle.load(f)
69
+ print("Loaded FAISS index from faiss_index.pkl")
70
+ with open(document_texts_path, "rb") as f:
71
+ document_texts = pickle.load(f)
72
+ print("Loaded document texts from document_texts.pkl")
73
+ except Exception as e:
74
+ print(f"Error loading FAISS index or document texts: {e}")
75
+ else:
76
+ # Create a new FAISS index if it doesn't exist
77
+ index = faiss.IndexFlatL2(embedding_model.get_sentence_embedding_dimension())
78
+ with open(index_path, "wb") as f:
79
+ pickle.dump(index, f)
80
+ print("Created new FAISS index and saved to faiss_index.pkl")
81
 
82
 
83
  def preprocess_text(text):
84
+ sentences = sent_tokenize(text)
85
+ return sentences
86
 
87
 
88
  def upload_files(files):