Spaces:
Build error
Build error
Update app.py
Browse files
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
|
62 |
index_path = "faiss_index.pkl"
|
63 |
document_texts_path = "document_texts.pkl"
|
64 |
document_texts = []
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
|
68 |
def preprocess_text(text):
|
69 |
-
|
|
|
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):
|