Spaces:
Sleeping
Sleeping
KushwanthK
commited on
Upload app.py
Browse files
app.py
CHANGED
@@ -136,6 +136,7 @@ import os
|
|
136 |
# import pinecone
|
137 |
|
138 |
import pickle
|
|
|
139 |
def get_faiss_semantic_index():
|
140 |
try:
|
141 |
index_path = "./HuggingFaceEmbeddings.pkl"
|
@@ -147,6 +148,7 @@ def get_faiss_semantic_index():
|
|
147 |
return faiss_index
|
148 |
except Exception as e:
|
149 |
st.error(f"Error loading embeddings: {e}")
|
|
|
150 |
|
151 |
# def promt_engineer(text):
|
152 |
PROMPT_TEMPLATE = """
|
@@ -194,7 +196,12 @@ def chat_actions():
|
|
194 |
|
195 |
# query_embedding = model.encode(st.session_state["chat_input"])
|
196 |
query = st.session_state["chat_input"]
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
198 |
for doc in docs:
|
199 |
print("\n")
|
200 |
print(str(doc.metadata["page"]+1) + ":", doc.page_content)
|
|
|
136 |
# import pinecone
|
137 |
|
138 |
import pickle
|
139 |
+
@st.cache_data
|
140 |
def get_faiss_semantic_index():
|
141 |
try:
|
142 |
index_path = "./HuggingFaceEmbeddings.pkl"
|
|
|
148 |
return faiss_index
|
149 |
except Exception as e:
|
150 |
st.error(f"Error loading embeddings: {e}")
|
151 |
+
return None
|
152 |
|
153 |
# def promt_engineer(text):
|
154 |
PROMPT_TEMPLATE = """
|
|
|
196 |
|
197 |
# query_embedding = model.encode(st.session_state["chat_input"])
|
198 |
query = st.session_state["chat_input"]
|
199 |
+
if faiss_index is not None:
|
200 |
+
docs = faiss_index.similarity_search(query, k=2)
|
201 |
+
else:
|
202 |
+
st.error("Failed to load embeddings.")
|
203 |
+
# docs = faiss_index.similarity_search(query, k=2)
|
204 |
+
|
205 |
for doc in docs:
|
206 |
print("\n")
|
207 |
print(str(doc.metadata["page"]+1) + ":", doc.page_content)
|