Update app.py
Browse files
app.py
CHANGED
|
@@ -55,22 +55,22 @@ def vector_embedding():
|
|
| 55 |
else:
|
| 56 |
st.write("Vectors already initialized.")
|
| 57 |
|
| 58 |
-
prompt1 = st.text_input("Enter Your Question From Documents")
|
| 59 |
-
|
| 60 |
-
# Inside the button click for document embedding
|
| 61 |
-
if st.button("Documents Embedding"):
|
| 62 |
-
try:
|
| 63 |
-
vector_embedding()
|
| 64 |
-
except Exception as e:
|
| 65 |
-
st.error(f"Error initializing vector store: {e}")
|
| 66 |
-
|
| 67 |
-
# Inside the button click for processing user question
|
| 68 |
if prompt1:
|
| 69 |
if "vectors" not in st.session_state:
|
| 70 |
st.error("Vectors are not initialized. Please click 'Documents Embedding' first.")
|
| 71 |
else:
|
|
|
|
|
|
|
|
|
|
| 72 |
try:
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
except Exception as e:
|
| 76 |
-
st.error(f"
|
|
|
|
| 55 |
else:
|
| 56 |
st.write("Vectors already initialized.")
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
if prompt1:
|
| 59 |
if "vectors" not in st.session_state:
|
| 60 |
st.error("Vectors are not initialized. Please click 'Documents Embedding' first.")
|
| 61 |
else:
|
| 62 |
+
document_chain = create_stuff_documents_chain(llm, prompt)
|
| 63 |
+
retriever = st.session_state.vectors.as_retriever()
|
| 64 |
+
retrieval_chain = create_retrieval_chain(retriever, document_chain)
|
| 65 |
try:
|
| 66 |
+
start = time.process_time()
|
| 67 |
+
response = retrieval_chain.invoke({'input': prompt1})
|
| 68 |
+
st.write("Response time: ", time.process_time() - start)
|
| 69 |
+
st.write(response['answer'])
|
| 70 |
+
|
| 71 |
+
with st.expander("Document Similarity Search"):
|
| 72 |
+
for i, doc in enumerate(response["context"]):
|
| 73 |
+
st.write(doc.page_content)
|
| 74 |
+
st.write("--------------------------------")
|
| 75 |
except Exception as e:
|
| 76 |
+
st.error(f"Failed to retrieve the answer: {e}")
|