DrishtiSharma
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -381,7 +381,6 @@ def get_retriever() -> None:
|
|
381 |
Upload document(s), create a vector store, prepare a retriever tool,
|
382 |
save the tool to the variable st.session_state.retriever_tool
|
383 |
"""
|
384 |
-
|
385 |
st.write("")
|
386 |
st.write("**Query Document(s)**")
|
387 |
uploaded_files = st.file_uploader(
|
@@ -392,33 +391,44 @@ def get_retriever() -> None:
|
|
392 |
key="document_upload_" + str(st.session_state.uploader_key),
|
393 |
)
|
394 |
|
395 |
-
if
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
if vector_store is not None:
|
400 |
-
uploaded_file_names = [file.name for file in uploaded_files]
|
401 |
-
file_names = ", ".join(uploaded_file_names)
|
402 |
-
st.session_state.vector_store_message = (
|
403 |
-
f"Vector store for :blue[[{file_names}]] is ready!"
|
404 |
-
)
|
405 |
-
retriever = vector_store.as_retriever()
|
406 |
-
st.session_state.retriever_tool = create_retriever_tool(
|
407 |
-
retriever,
|
408 |
-
name="retriever",
|
409 |
-
description=(
|
410 |
-
"Search for information about the uploaded documents. "
|
411 |
-
"For any questions about the documents, you must use "
|
412 |
-
"this tool!"
|
413 |
-
),
|
414 |
-
)
|
415 |
|
416 |
-
|
417 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
418 |
else:
|
419 |
-
st.error("
|
|
|
|
|
420 |
|
421 |
-
st.session_state.uploader_key += 1
|
422 |
|
423 |
|
424 |
def display_text_with_equations(text: str):
|
|
|
381 |
Upload document(s), create a vector store, prepare a retriever tool,
|
382 |
save the tool to the variable st.session_state.retriever_tool
|
383 |
"""
|
|
|
384 |
st.write("")
|
385 |
st.write("**Query Document(s)**")
|
386 |
uploaded_files = st.file_uploader(
|
|
|
391 |
key="document_upload_" + str(st.session_state.uploader_key),
|
392 |
)
|
393 |
|
394 |
+
# Only proceed if files are uploaded
|
395 |
+
if uploaded_files:
|
396 |
+
if st.button(label="Create the vector store"):
|
397 |
+
st.info("Creating the vector store and initializing the retriever tool...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
398 |
|
399 |
+
# Create the vector store.
|
400 |
+
vector_store = get_vector_store(uploaded_files)
|
401 |
+
|
402 |
+
if vector_store is not None:
|
403 |
+
uploaded_file_names = [file.name for file in uploaded_files]
|
404 |
+
file_names = ", ".join(uploaded_file_names)
|
405 |
+
st.session_state.vector_store_message = (
|
406 |
+
f"Vector store for :blue[[{file_names}]] is ready!"
|
407 |
+
)
|
408 |
+
retriever = vector_store.as_retriever()
|
409 |
+
st.session_state.retriever_tool = create_retriever_tool(
|
410 |
+
retriever,
|
411 |
+
name="retriever",
|
412 |
+
description=(
|
413 |
+
"Search for information about the uploaded documents. "
|
414 |
+
"For any questions about the documents, you must use "
|
415 |
+
"this tool!"
|
416 |
+
),
|
417 |
+
)
|
418 |
+
# Ensure the retrieval tool is included in tool selection
|
419 |
+
st.session_state.tool_names[0].append("Retrieval")
|
420 |
+
|
421 |
+
if st.session_state.retriever_tool:
|
422 |
+
st.success("Retriever tool has been successfully initialized and is ready to use.")
|
423 |
+
else:
|
424 |
+
st.error("Failed to initialize the retriever tool. Please try uploading again.")
|
425 |
+
|
426 |
+
st.session_state.uploader_key += 1
|
427 |
else:
|
428 |
+
st.error("Could not create vector store. Please check the uploaded files.")
|
429 |
+
else:
|
430 |
+
st.info("Please upload documents to create the vector store.")
|
431 |
|
|
|
432 |
|
433 |
|
434 |
def display_text_with_equations(text: str):
|