similarity search
Browse files
app.py
CHANGED
|
@@ -28,19 +28,19 @@ if files:
|
|
| 28 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=150)
|
| 29 |
chunks = text_splitter.split_text(full_text)
|
| 30 |
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 31 |
-
|
| 32 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True,)
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 28 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=150)
|
| 29 |
chunks = text_splitter.split_text(full_text)
|
| 30 |
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 31 |
+
db = FAISS.from_texts(chunks, embeddings)
|
| 32 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True,)
|
| 33 |
+
|
| 34 |
+
def retrieve_info(query):
|
| 35 |
+
similar_response = db.similarity_search(query, k=3)
|
| 36 |
+
page_contents_array = [doc.page_contents for doc in similar_response]
|
| 37 |
+
page_contents = " ".join(page_contents_array)
|
| 38 |
+
return page_contents
|
| 39 |
+
|
| 40 |
+
st.header("Chatbot")
|
| 41 |
+
st.subheader("Ask a question")
|
| 42 |
+
question = st.text_input("Question")
|
| 43 |
+
if question:
|
| 44 |
+
st.subheader("Answer")
|
| 45 |
+
answer = retrieve_info(question)
|
| 46 |
+
st.write(answer)
|